云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 编译原理-LL(1)文法源代码(实验三)

编译原理-LL(1)文法源代码(实验三)

  • 62 次阅读
  • 3 次下载
  • 2025/5/6 7:44:00

if(100 > pt->rCursor) {

AddFirst(U, pt->rCursor); break; } else {

if(NULL == first[pt->rCursor - 100]) {

First(pt->rCursor); }

AddFirst(U, pt->rCursor); if(!HaveEmpty(pt->rCursor)) {

break; } else {

pt = pt->next; } } j++; }

if(j >= P[i].rLength) /*当产生式右部都能推出空时*/ AddFirst(U, -1); } } }

/*加入first集*/

void AddFirst(int U, int nCh) {

struct collectNode *pt, *qt; int ch; /*用于处理Vn*/ pt = NULL; qt = NULL; if(nCh < 100) {

pt = first[U - 100]; while(NULL != pt) {

if(pt->nVt == nCh) break;

else {

qt = pt;

pt = pt->next; } }

if(NULL == pt) {

pt = (struct collectNode *)malloc(sizeof(struct collectNode)); pt->nVt = nCh; pt->next = NULL;

if(NULL == first[U - 100]) {

first[U - 100] = pt; } else {

qt->next = pt; /*qt指向first集的最后一个元素*/ }

pt = pt->next; } } else {

pt = first[nCh - 100]; while(NULL != pt) {

ch = pt->nVt; if(-1 != ch) {

AddFirst(U, ch); }

pt = pt->next; } } }

bool HaveEmpty(int nVn) {

if(nVn < 100) return false;

struct collectNode *pt; pt = first[nVn - 100]; while(NULL != pt)

{

if(-1 == pt->nVt) return true; pt = pt->next; }

return false; }

void Follow(int V) { int i;

struct pRNode *pt ;

if(100 == V) /*当为初始符时*/ AddFollow(V, -1, 0 ); for(i = 0; i < PNum; i++) {

pt = P[i].rHead;

while(NULL != pt && pt->rCursor != V) pt = pt->next; if(NULL != pt) {

pt = pt->next; if(NULL == pt) {

if(NULL == follow[P[i].lCursor - 100] && P[i].lCursor != V) {

Follow(P[i].lCursor); }

AddFollow(V, P[i].lCursor, 0); } else {

while(NULL != pt && HaveEmpty(pt->rCursor)) {

AddFollow(V, pt->rCursor, 1); pt = pt->next; }

if(NULL == pt) {

if(NULL == follow[P[i].lCursor - 100] && P[i].lCursor != V) {

Follow(P[i].lCursor); }

AddFollow(V, P[i].lCursor, 0); } else {

AddFollow(V, pt->rCursor, 1); } } } } }

void AddFollow(int V, int nCh, int kind) {

struct collectNode *pt, *qt; int ch; pt = NULL; qt = NULL;

if(nCh < 100) /*为终结符时*/ {

pt = follow[V - 100]; while(NULL != pt) {

if(pt->nVt == nCh) break; else {

qt = pt;

pt = pt->next; } }

if(NULL == pt) {

pt = (struct collectNode *)malloc(sizeof(struct collectNode)); pt->nVt = nCh; pt->next = NULL;

if(NULL == follow[V - 100]) {

follow[V - 100] = pt; } else {

qt->next = pt; /*qt指向follow集的最后一个元素*/ }

搜索更多关于: 编译原理-LL(1)文法源代码(实验三) 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

if(100 > pt->rCursor) { AddFirst(U, pt->rCursor); break; } else { if(NULL == first[pt->rCursor - 100]) { First(pt->rCursor); } AddFirst(U, pt->rCursor); if(!HaveEmpty(pt->rCursor)) { break; } else { pt = pt->next; } } j++; } if(j

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com