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

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

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

} 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:

||

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