第一范文网 - 专业文章范例文档资料分享平台

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

来源:用户分享 时间:2025/5/17 7:40:00 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

}

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文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c341ql2twie1xkfw974p6_11.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top