C-Minus词法分析和语法分析设计编译器编译原理课程设计

break;

fout_Tree<<\break;

fout_Tree<<\break;

fout_Tree<<\break;

fout_Tree<<\break;

fout_Tree<<\break;

fout_Tree<<\break;

fout_Tree<<\break;

fout_Tree<<\

fout_Tree<attr.op]<

fout_Tree<<\break;

fout_Tree<<\break;

fout_Tree<<\

case ParamsK:

case ParamK:

case CompK:

case Selection_StmtK:

case Iteration_StmtK:

case Return_StmtK:

case AssignK:

case OpK:

case Arry_ElemK:

case CallK:

case ArgsK:

} }

}

break;

fout_Tree<<\:Unknown exp kind\break;

default:

step++;//进入子节点多输出空格 for(i = 0;i

step--;//进入兄弟节点时,由于进入子节点时n++了,所以要n--回来,从而输出一样t = t->sibling;

if(t->child[i]!=NULL)

printTree(t->child[i]);

的空格空格

TreeNode * Parser :: newNode(Nodekind kind) {

TreeNode * p = (TreeNode *)malloc(sizeof(TreeNode)); int k; if(p==NULL) { } else {

for(k = 0;k

p->sibling = NULL; p->nodekind = kind;

p->lineno = currentToken.lineNo;

p->child[k] = NULL; cout<<\内存分配出错!\

}

if(kind==OpK || kind==IntK || kind==IdK)

p->type = Integer; p->attr.name = \p->attr.val = 0; if(kind==IdK) if(kind==ConstK)

return p; }

TreeNode * Parser :: parse(void) {

TreeNode * t;

currentToken = getToken(); lastToken = currentToken; t = declaration_list();

if(currentToken.tokenType!=ENDFILE) { } return t; }

TreeNode * Parser :: declaration_list() {

TreeNode * t = declaration(); TreeNode * p = t;

//在开始语法分析出错的情况下找到int和void型,过滤掉int和void之前的所有Token,防止在开始时出错后面一错百错

while((currentToken.tokenType!=INT)&&(currentToken.tokenType!=VOID)&&(currentToken.tokenType!=ENDFILE)) {

syntaxError(\getToken();

syntaxError(\结束错误\

}

if(currentToken.tokenType==ENDFILE)

break;

//寻找语法分析的入口,即找到int和void

while((currentToken.tokenType==INT)||(currentToken.tokenType==VOID)) { }

match(ENDFILE); return t; }

TreeNode * Parser :: declaration(void) {

TreeNode * t = NULL; TreeNode * p = NULL; TreeNode * q = NULL; TreeNode * s = NULL;

if(currentToken.tokenType==INT) {

p = newNode(IntK); match(INT); TreeNode * q; q = declaration(); if(q!=NULL) { }

if(t==NULL) { } else { }

p->sibling = q; p = q; t = p = q;

联系客服:779662525#qq.com(#替换为@)