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

发布时间 : 星期二 文章C-Minus词法分析和语法分析设计编译器编译原理课程设计更新完毕开始阅读4fc4cd488bd63186bcebbc8a

} else { }

t->child[0] = p; { } else { }

if(currentToken.tokenType==ID)

q = newNode(IdK);

q->attr.name = currentToken.tokenString.c_str(); t->child[1] = q; match(ID);

syntaxError(\

if((currentToken.tokenType==LMBRACKET)&&(t->child[1]!=NULL)) { } else { }

return t;

match(LMBRACKET); t->child[2] = newNode(IdK); match(RMBRACKET);

syntaxError(\

return t; }

TreeNode * Parser :: compound_stmt(void) {

TreeNode * t = newNode(CompK);

match(LBBRACKET); t->child[0] = local_declaration(); t->child[1] = statement_list(); match(RBBRACKET); return t; }

TreeNode * Parser :: local_declaration(void) {

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

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

p = newNode(Var_DeclK); if(currentToken.tokenType==INT) { }

else if(currentToken.tokenType==VOID) { }

if((p!=NULL)&&(currentToken.tokenType==ID)) {

TreeNode * q2 = newNode(IdK); q2->attr.name = currentToken.tokenString.c_str(); p->child[1] = q2; match(ID);

TreeNode * q1 = newNode(VoidK); p->child[0] = q1; match(INT);

TreeNode * q1 = newNode(IntK); p->child[0] = q1; match(INT);

}

} else { }

if(currentToken.tokenType==LMBRACKET) { }

else if(currentToken.tokenType==SEMI) { } else { }

match(SEMI); match(SEMI);

TreeNode * q3 = newNode(Var_DeclK); p->child[3] = q3; match(LMBRACKET); match(RMBRACKET); match(SEMI);

syntaxError(\

if(p!=NULL) { }

if(t==NULL) else { }

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

return t; }

TreeNode * Parser :: statement_list(void) {

TreeNode * t = statement(); TreeNode * p = t; while

(IF==currentToken.tokenType

|| ||

LBBRACKET==currentToken.tokenType

||

|| ID==currentToken.tokenType WHILE==currentToken.tokenType

RETURN

==currentToken.tokenType ||

SEMI==currentToken.tokenType

LPAREN==currentToken.tokenType || NUM==currentToken.tokenType)

{ TreeNode * q; q = statement(); if(q!=NULL) { if(t==NULL) { t = p = q;

} else { p->sibling = q; p = q; }

}

} return t; }

TreeNode * Parser :: statement(void) {

TreeNode * t = NULL; switch(currentToken.tokenType) { case IF:

||