预览加载中,请您耐心等待几秒...
1/10
2/10
3/10
4/10
5/10
6/10
7/10
8/10
9/10
10/10

亲,该文档总共11页,到这已经超出免费预览范围,如果喜欢就直接下载吧~

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

#include"parser.h"#ifndefPARSER_DEBUG#include"semantic.h"#endif#ifdefPARSER_DEBUG#defineenter(x)printf("enterin");printf(x);printf("\n")#else#defineenter(x)#endif#ifdefPARSER_DEBUG#defineback(x)printf("exitfrom");printf(x);printf("\n")#else#defineback(x)#endif#ifdefPARSER_DEBUG#definecall_match(x)printf("matchtoken\t");printf(x);printf("\n");#else#definecall_match(x)#endif#ifdefPARSER_DEBUG#defineTree_trace(x)PrintSyntaxTree(x,1);#else#defineTree_trace#endif#ifdefPARSER_DEBUGdoubleParameter=0;//参数T的存储空间#elsedoubleParameter=0,//参数T的存储空间Origin_x=0,Origin_y=0,//横、纵平移距离Scale_x=1,Scale_y=1,//横、纵比例因子Rot_angle=0;//旋转角度#endifstaticTokentoken;//记号//---------------辅助函数声明staticvoidFetchToken();staticvoidMatchToken(enumToken_TypeAToken);staticvoidSyntaxError(intcase_of);staticvoidErrMsg(unsignedLineNo,char*descrip,char*string);staticvoidPrintSyntaxTree(structExprNode*root,intindent);//---------------非终结符的递归子程序声明staticvoidProgram();staticvoidStatement();staticvoidOriginStatement();staticvoidRotStatement();staticvoidScaleStatement();staticvoidForStatement();staticstructExprNode*Expression();staticstructExprNode*Term();staticstructExprNode*Factor();staticstructExprNode*Component();staticstructExprNode*Atom();//--------------外部接口与语法树构造函数声明externvoidParser(char*SrcFilePtr);staticstructExprNode*MakeExprNode(enumToken_Typeopcode,...);//---------------------通过词法分析器接口GetToken获取-个记号staticvoidFetchToken(){token=GetToken();if(token.type==ERRTOKEN)SyntaxError(1);}//----------------------匹配记号staticvoidMatchToken(enumToken_TypeThe_Token){if(token.type!=The_Token)SyntaxError(2);FetchToken();}//----------------------语法错误处理staticvoidSyntaxError(intcase_of){switch(case_of){case1:ErrMsg(LineNo,"错误记号",token.lexeme);break;case2:ErrMsg(LineNo,"不是预期记号",token.lexeme);break;}}//---------------------打印错误信息voidErrMsg(unsignedLineNo,char*descrip,char*string){#ifdefPARSER_DEBUGprintf("LineNo%5d:%s%s!\n",LineNo,descrip,string);#elsecharmsg[256];memset(msg,0,256);sprintf(msg,"LineNo%5d:%s%s!",LineNo,descrip,s