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

2026/4/23 6:52:47

}

t = selection_stmt(); break;

t = iteration_stmt(); break;

t = return_stmt(); break;

t = compound_stmt(); break;

t = expression_stmt(); break; syntaxError(\

currentToken = getToken(); break;

case WHILE:

case RETURN:

case LBBRACKET:

case ID: case SEMI: case LPAREN: case NUM:

default:

return t; }

TreeNode * Parser :: selection_stmt(void) {

TreeNode * t = newNode(Selection_StmtK); match(IF); match(LPAREN); if(t!=NULL) { }

match(RPAREN); t->child[1] = statement();

if(currentToken.tokenType==ELSE)

t->child[0] = expression();

{ } return t; }

TreeNode * Parser :: expression_stmt(void) {

TreeNode * t = NULL;

if(currentToken.tokenType==SEMI) { } else { } return t; }

TreeNode * Parser :: iteration_stmt(void) {

TreeNode * t = newNode(Iteration_StmtK); match(WHILE); match(LPAREN); if(t!=NULL) {

t->child[0] = expression(); t = expression(); match(SEMI); match(SEMI); return t; match(ELSE); if(t!=NULL) { }

t->child[2] = statement();

}

match(RPAREN); if(t!=NULL) { } return t; }

TreeNode * Parser :: return_stmt(void) {

TreeNode * t = newNode(Return_StmtK); match(RETURN);

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

match(SEMI); return t; }

TreeNode * Parser :: expression(void) {

TreeNode * t = var();

if(t==NULL)//不是以ID开头,只能是simple_expression情况

if(t!=NULL) { }

t->child[0] = expression(); match(SEMI); return t;

t->child[1] = statement();

{ t = simple_expression(t);

}

else//以ID开头,可能是赋值语句,或simple_expression中的var和call类型的情况 { TreeNode * p = NULL;

if(currentToken.tokenType==ASSIGN)//赋值语句 { p = newNode(AssignK);

p->attr.name = lastToken.tokenString.c_str(); match(ASSIGN); p->child[0] = t;

p->child[1] = expression(); return p;

}

else //simple_expression中的var和call类型的情况 { t = simple_expression(t); } }

return t;

}

TreeNode * Parser :: simple_expression(TreeNode * k) {

TreeNode * t = additive_expression(k); k = NULL;

if(EQ==currentToken.tokenType || GT==currentToken.tokenType GEQ==currentToken.tokenType ||

LT==currentToken.tokenType

LEQ==currentToken.tokenType || NEQ==currentToken.tokenType)

{ TreeNode * q = newNode(OpK); q->attr.op = currentToken.tokenType;

q->child[0] = t;

|| ||


C-Minus词法分析和语法分析设计编译器编译原理课程设计.doc 将本文的Word文档下载到电脑
搜索更多关于: C-Minus词法分析和语法分析设计编译器编译原理课程设计 的文档
相关推荐
相关阅读
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 10

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219