📄 parse.cpp
字号:
{
#ifdef YYDEBUG
YYSTYPE *yya[4];
yyinitdebug(yya, 4);
#endif
{
#line 375 "E:\\MyVC\\compiler\\cscript1\\parse.y"
yyval=newExpNode(OpK);
yyval->child[0]=yyattribute(1 - 3);
yyval->child[1]=yyattribute(3 - 3);
yyval->attr.op=LE;
#line 1017 "E:\\MyVC\\compiler\\cscript1\\parse.c"
}
}
break;
case 54:
{
#ifdef YYDEBUG
YYSTYPE *yya[4];
yyinitdebug(yya, 4);
#endif
{
#line 382 "E:\\MyVC\\compiler\\cscript1\\parse.y"
yyval=newExpNode(OpK);
yyval->child[0]=yyattribute(1 - 3);
yyval->child[1]=yyattribute(3 - 3);
yyval->attr.op=LT;
#line 1035 "E:\\MyVC\\compiler\\cscript1\\parse.c"
}
}
break;
case 55:
{
#ifdef YYDEBUG
YYSTYPE *yya[4];
yyinitdebug(yya, 4);
#endif
{
#line 389 "E:\\MyVC\\compiler\\cscript1\\parse.y"
yyval=newExpNode(OpK);
yyval->child[0]=yyattribute(1 - 3);
yyval->child[1]=yyattribute(3 - 3);
yyval->attr.op=EQ;
#line 1053 "E:\\MyVC\\compiler\\cscript1\\parse.c"
}
}
break;
case 56:
{
#ifdef YYDEBUG
YYSTYPE *yya[4];
yyinitdebug(yya, 4);
#endif
{
#line 396 "E:\\MyVC\\compiler\\cscript1\\parse.y"
yyval=newExpNode(OpK);
yyval->child[0]=yyattribute(1 - 3);
yyval->child[1]=yyattribute(3 - 3);
yyval->attr.op=NE;
#line 1071 "E:\\MyVC\\compiler\\cscript1\\parse.c"
}
}
break;
case 57:
{
#ifdef YYDEBUG
YYSTYPE *yya[2];
yyinitdebug(yya, 2);
#endif
{
#line 403 "E:\\MyVC\\compiler\\cscript1\\parse.y"
yyval=yyattribute(1 - 1);
#line 1086 "E:\\MyVC\\compiler\\cscript1\\parse.c"
}
}
break;
case 58:
{
#ifdef YYDEBUG
YYSTYPE *yya[4];
yyinitdebug(yya, 4);
#endif
{
#line 409 "E:\\MyVC\\compiler\\cscript1\\parse.y"
yyval=newExpNode(OpK);
yyval->child[0]=yyattribute(1 - 3);
yyval->child[1]=yyattribute(3 - 3);
yyval->attr.op=PLUS;
#line 1104 "E:\\MyVC\\compiler\\cscript1\\parse.c"
}
}
break;
case 59:
{
#ifdef YYDEBUG
YYSTYPE *yya[4];
yyinitdebug(yya, 4);
#endif
{
#line 416 "E:\\MyVC\\compiler\\cscript1\\parse.y"
yyval=newExpNode(OpK);
yyval->child[0]=yyattribute(1 - 3);
yyval->child[1]=yyattribute(3 - 3);
yyval->attr.op=MINUS;
#line 1122 "E:\\MyVC\\compiler\\cscript1\\parse.c"
}
}
break;
case 60:
{
#ifdef YYDEBUG
YYSTYPE *yya[2];
yyinitdebug(yya, 2);
#endif
{
#line 423 "E:\\MyVC\\compiler\\cscript1\\parse.y"
yyval=yyattribute(1 - 1);
#line 1137 "E:\\MyVC\\compiler\\cscript1\\parse.c"
}
}
break;
case 61:
{
#ifdef YYDEBUG
YYSTYPE *yya[4];
yyinitdebug(yya, 4);
#endif
{
#line 430 "E:\\MyVC\\compiler\\cscript1\\parse.y"
yyval = newExpNode(OpK);
yyval->child[0] = yyattribute(1 - 3);
yyval->child[1] = yyattribute(3 - 3);
yyval->attr.op = TIMES;
#line 1155 "E:\\MyVC\\compiler\\cscript1\\parse.c"
}
}
break;
case 62:
{
#ifdef YYDEBUG
YYSTYPE *yya[4];
yyinitdebug(yya, 4);
#endif
{
#line 437 "E:\\MyVC\\compiler\\cscript1\\parse.y"
yyval = newExpNode(OpK);
yyval->child[0] = yyattribute(1 - 3);
yyval->child[1] = yyattribute(3 - 3);
yyval->attr.op = OVER;
#line 1173 "E:\\MyVC\\compiler\\cscript1\\parse.c"
}
}
break;
case 63:
{
#ifdef YYDEBUG
YYSTYPE *yya[2];
yyinitdebug(yya, 2);
#endif
{
#line 444 "E:\\MyVC\\compiler\\cscript1\\parse.y"
yyval = yyattribute(1 - 1);
#line 1186 "E:\\MyVC\\compiler\\cscript1\\parse.c"
}
}
break;
case 64:
{
#ifdef YYDEBUG
YYSTYPE *yya[4];
yyinitdebug(yya, 4);
#endif
{
#line 448 "E:\\MyVC\\compiler\\cscript1\\parse.y"
yyval = yyattribute(2 - 3);
#line 1199 "E:\\MyVC\\compiler\\cscript1\\parse.c"
}
}
break;
case 65:
{
#ifdef YYDEBUG
YYSTYPE *yya[2];
yyinitdebug(yya, 2);
#endif
{
#line 450 "E:\\MyVC\\compiler\\cscript1\\parse.y"
yyval = yyattribute(1 - 1);
#line 1212 "E:\\MyVC\\compiler\\cscript1\\parse.c"
}
}
break;
case 66:
{
#ifdef YYDEBUG
YYSTYPE *yya[2];
yyinitdebug(yya, 2);
#endif
{
#line 452 "E:\\MyVC\\compiler\\cscript1\\parse.y"
yyval = yyattribute(1 - 1);
#line 1225 "E:\\MyVC\\compiler\\cscript1\\parse.c"
}
}
break;
case 67:
{
#ifdef YYDEBUG
YYSTYPE *yya[2];
yyinitdebug(yya, 2);
#endif
{
#line 454 "E:\\MyVC\\compiler\\cscript1\\parse.y"
yyval = newExpNode(ConstK);
yyval->attr.vali = atoi(tokenString);
yyval->type = Integer;
#line 1242 "E:\\MyVC\\compiler\\cscript1\\parse.c"
}
}
break;
case 68:
{
#ifdef YYDEBUG
YYSTYPE *yya[2];
yyinitdebug(yya, 2);
#endif
{
#line 460 "E:\\MyVC\\compiler\\cscript1\\parse.y"
yyval = newExpNode(ConstK);
yyval->attr.valf = (float)atof(tokenString);
yyval->type = Float;
#line 1259 "E:\\MyVC\\compiler\\cscript1\\parse.c"
}
}
break;
case 69:
{
#ifdef YYDEBUG
YYSTYPE *yya[2];
yyinitdebug(yya, 2);
#endif
{
#line 466 "E:\\MyVC\\compiler\\cscript1\\parse.y"
yyval = newExpNode(ConstK);
yyval->attr.valc = tokenString[0];
yyval->type = Char;
#line 1276 "E:\\MyVC\\compiler\\cscript1\\parse.c"
}
}
break;
case 70:
{
#ifdef YYDEBUG
YYSTYPE *yya[3];
yyinitdebug(yya, 3);
#endif
{
#line 472 "E:\\MyVC\\compiler\\cscript1\\parse.y"
yyval = newExpNode(OpK);
yyval->attr.op=NOT;
yyval->child[0] = yyattribute(2 - 2);
#line 1293 "E:\\MyVC\\compiler\\cscript1\\parse.c"
}
}
break;
case 71:
{
#ifdef YYDEBUG
YYSTYPE *yya[5];
yyinitdebug(yya, 5);
#endif
{
#line 480 "E:\\MyVC\\compiler\\cscript1\\parse.y"
yyval = newExpNode(CallK);
yyval->attr.name=yyattribute(1 - 4)->attr.name;
yyval->child[0] = yyattribute(3 - 4);
#line 1310 "E:\\MyVC\\compiler\\cscript1\\parse.c"
}
}
break;
case 72:
{
#ifdef YYDEBUG
YYSTYPE *yya[4];
yyinitdebug(yya, 4);
#endif
{
#line 486 "E:\\MyVC\\compiler\\cscript1\\parse.y"
yyval = newExpNode(CallK);
yyval->attr.name=yyattribute(1 - 3)->attr.name;
yyval->child[0]=0;
#line 1327 "E:\\MyVC\\compiler\\cscript1\\parse.c"
}
}
break;
case 73:
{
#ifdef YYDEBUG
YYSTYPE *yya[2];
yyinitdebug(yya, 2);
#endif
{
#line 494 "E:\\MyVC\\compiler\\cscript1\\parse.y"
yyval=yyattribute(1 - 1);
#line 1342 "E:\\MyVC\\compiler\\cscript1\\parse.c"
}
}
break;
case 74:
{
#ifdef YYDEBUG
YYSTYPE *yya[4];
yyinitdebug(yya, 4);
#endif
{
#line 500 "E:\\MyVC\\compiler\\cscript1\\parse.y"
yyval = yyattribute(1 - 3);
yyval->sibling = yyattribute(3 - 3);
#line 1358 "E:\\MyVC\\compiler\\cscript1\\parse.c"
}
}
break;
case 75:
{
#ifdef YYDEBUG
YYSTYPE *yya[2];
yyinitdebug(yya, 2);
#endif
{
#line 505 "E:\\MyVC\\compiler\\cscript1\\parse.y"
yyval = yyattribute(1 - 1);
#line 1373 "E:\\MyVC\\compiler\\cscript1\\parse.c"
}
}
break;
default:
yyassert(0);
break;
}
}
#line 509 "E:\\MyVC\\compiler\\cscript1\\parse.y"
/*int yyerror(char* message)
{
fprintf(listing,"Syntax error at line %d: %s \n",lineno,message);
printToken(yychar,tokenString);
Error=TRUE;
return 0;
} */
#ifdef YYPROTOTYPE
int YYCDECL yygettoken(void)
#else
int YYCDECL yygettoken()
#endif
{
return yylex();
}
/*int yygettoken(void)
{
return getToken();
}
*/
static int yylex(void)
{ return getToken(); }
TreeNode* parse(void)
{
yyparse();
return savedTree;
}
#line 1415 "E:\\MyVC\\compiler\\cscript1\\parse.c"
#ifdef YYDEBUG
YYCONST yysymbol_t YYNEARFAR YYDCDECL yysymbol[] = {
{ "$end", 0 },
{ "error", 256 },
{ "INT", 257 },
{ "CHAR", 258 },
{ "FLOAT", 259 },
{ "VOID", 260 },
{ "NUM", 261 },
{ "FLOATNUM", 262 },
{ "CONSTCHAR", 263 },
{ "ID", 264 },
{ "IF", 265 },
{ "ELSE", 266 },
{ "WHILE", 267 },
{ "BREAK", 268 },
{ "RETURN", 269 },
{ "LBRACKET", 270 },
{ "RBRACKET", 271 },
{ "LPAREN", 272 },
{ "RPAREN", 273 },
{ "LBC", 274 },
{ "RBC", 275 },
{ "SEMI", 276 },
{ "COMMA", 277 },
{ "ASSIGN", 278 },
{ "EQ", 279 },
{ "LT", 280 },
{ "LE", 281 },
{ "GT", 282 },
{ "GE", 283 },
{ "NE", 284 },
{ "AND", 285 },
{ "OR", 286 },
{ "NOT", 287 },
{ "PLUS", 288 },
{ "MINUS", 289 },
{ "TIMES", 290 },
{ "OVER", 291 },
{ NULL, 0 }
};
YYCONST char *YYCONST YYNEARFAR YYDCDECL yyrule[] = {
"$accept: program",
"program: declaration_list",
"declaration_list: declaration_list declaration",
"declaration_list: declaration",
"declaration: var_declaration",
"declaration: fun_declaration",
"var_declaration: type_specifier id SEMI",
"$$1:",
"var_declaration: type_specifier id LBRACKET NUM $$1 RBRACKET SEMI",
"type_specifier: INT",
"type_specifier: CHAR",
"type_specifier: FLOAT",
"type_specifier: VOID",
"id: ID",
"fun_declaration: type_specifier id LPAREN params RPAREN compound_stmt",
"fun_declaration: type_specifier id LPAREN VOID RPAREN compound_stmt",
"fun_declaration: type_specifier id LPAREN RPAREN compound_stmt",
"params: param_list",
"param_list: param_list COMMA param",
"param_list: param",
"param: type_specifier id",
"param: type_specifier id LBRACKET RBRACKET",
"compound_stmt: LBC local_declarations RBC",
"compound_stmt: LBC local_declarations statement_list RBC",
"compound_stmt: LBC RBC",
"compound_stmt: LBC statement_list RBC",
"local_declarations: local_declarations var_declaration",
"local_declarations: var_declaration",
"statement_list: statement_list statement",
"statement_list: statement",
"statement: expression_stmt",
"statement: compound_stmt",
"statement: if_stmt",
"statement: while_stmt",
"statement: return_stmt",
"statement: assign_stmt",
"statement: break_stmt",
"expression_stmt: expression SEMI",
"expression_stmt: SEMI",
"if_stmt: IF LPAREN expression RPAREN statement ELSE statement",
"if_stmt: IF LPAREN expression RPAREN statement",
"while_stmt: WHILE LPAREN expression RPAREN statement",
"return_stmt: RETURN SEMI",
"return_stmt: RETURN expression SEMI",
"assign_stmt: var ASSIGN expression SEMI",
"break_stmt: BREAK SEMI",
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -