⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parse.c

📁 在linux下实行的简单的c语言编译器
💻 C
📖 第 1 页 / 共 3 页
字号:
#include <stdlib.h>#ifndef lint#ifdef __unused__unused#endifstatic char const yyrcsid[] = "$FreeBSD: src/usr.bin/yacc/skeleton.c,v 1.37 2003/02/12 18:03:55 davidc Exp $";#endif#define YYBYACC 1#define YYMAJOR 1#define YYMINOR 9#define YYLEX yylex()#define YYEMPTY -1#define yyclearin (yychar=(YYEMPTY))#define yyerrok (yyerrflag=0)#define YYRECOVERING() (yyerrflag!=0)#if defined(__cplusplus) || __STDC__static int yygrowstack(void);#elsestatic int yygrowstack();#endif#define YYPREFIX "yy"#line 5 "Parse.y"#define YYPARSE#include "Global.h"#include "Scan.h"#include "Utils.h"void yyerror(char *msg);TreeNode *parse();static char *savedFunName;		/*save the function name*/static char *savedIdName;		/*save the id name*/static int savedLineNo;			/*save the line num*/static TreeNode *savedTree;		/*the final syntax tree*/#line 26 "Parse.y"typedef union{	TreeNode *ptree;	Type type;			/*INT VOID CHAR FLOAT*/} YYSTYPE;#line 45 "Parse.c"#define YYERRCODE 256#define ENDFILE 257#define ERROR 258#define INT 259#define CHAR 260#define FLOAT 261#define IF 262#define ELSE 263#define WHILE 264#define VOID 265#define RETURN 266#define BREAK 267#define CONTINUE 268#define ID 269#define NUM 270#define FNUM 271#define SCHAR 272#define PLUS 273#define SUB 274#define MUT 275#define DIV 276#define LT 277#define LE 278#define GT 279#define GE 280#define EQ 281#define NEQ 282#define AND 283#define OR 284#define NOT 285#define ASSIGN 286#define SEMI 287#define COMMA 288#define LP 289#define RP 290#define LSP 291#define RSP 292#define LFP 293#define RFP 294const short yylhs[] = {                                        -1,    0,    1,    1,    2,    2,    2,   26,   27,    3,   24,   24,   24,   24,   25,   25,   25,   25,    5,    5,    4,    4,    6,    6,    7,    7,    8,    8,    8,    8,    9,   10,   10,   11,   11,   12,   12,   12,   12,   12,   12,   12,   13,   13,   14,   14,   15,   16,   16,   17,   17,   18,   18,   19,   19,   19,   19,   19,   19,   19,   19,   19,   19,   19,   19,   19,   20,   20,   20,   20,   20,   20,   20,   21,   23,   23,   22,   22,};const short yylen[] = {                                         2,    1,    2,    1,    1,    1,    1,    1,    0,    3,    3,    1,    5,    3,    1,    1,    1,    1,    7,    6,    7,    6,    1,    0,    3,    1,    1,    2,    4,    5,    4,    2,    0,    2,    0,    1,    1,    1,    1,    1,    2,    2,    2,    1,    5,    7,    5,    2,    3,    3,    1,    1,    4,    3,    3,    3,    3,    3,    3,    3,    3,    3,    3,    3,    3,    1,    3,    1,    1,    1,    1,    1,    2,    4,    3,    1,    1,    0,};const short yydefred[] = {                                      0,   14,   16,   15,   17,    7,    0,    0,    3,    4,    5,    6,    0,    8,    2,   11,    0,    0,    0,    9,    0,    0,    0,    0,    0,   10,    0,   69,   70,   71,    0,    0,    0,    0,   65,   68,    0,    0,    0,    0,    0,   25,    0,    0,   72,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,   52,    0,    0,    0,    0,    0,   66,    0,   75,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,   21,   32,   19,   24,    0,   49,   73,    0,   20,   18,    0,   28,    0,   74,   31,    0,    0,   29,    0,    0,    0,    0,    0,   43,   30,   39,   33,   35,   36,   37,   38,    0,    0,    0,    0,   47,    0,   41,   40,   42,    0,    0,   48,    0,    0,    0,   46,    0,   45,};const short yydgoto[] = {                                       6,    7,    8,    9,   10,   11,   39,   40,   41,  110,   95,  100,  111,  112,  113,  114,  115,  116,   32,   47,   34,   35,   70,   71,   16,   42,   36,   18,};const short yysindex[] = {                                   -146,    0,    0,    0,    0,    0,    0, -146,    0,    0,    0,    0, -263,    0,    0,    0, -193, -228, -265,    0, -263,  -85,  -85, -242,   38,    0, -217,    0,    0,    0,  -85,  -85, -238,  170,    0,    0, -278,   12,   38, -231, -222,    0, -263,  -85,    0, -219, -237,  170,  -85,  -85,  -85,  -85,  -85,  -85,  -85,  -85,  -85,  -85,  -85,  -85,  -85,    0, -214, -286,   38, -201,  170,    0,  -85,    0, -191, -187, -241, -241, -178, -178,  -82,  -82,  -82,  -82,  205,  205,  170,  194, -276,    0,    0,    0,    0, -232,    0,    0,  -85,    0,    0,   38,    0,   32,    0,    0, -239, -263,    0, -152, -150,  -90, -139, -137,    0,    0,    0,    0,    0,    0,    0,    0, -129, -228,  -85,  -85,    0, -127,    0,    0,    0, -128, -119,    0, -115, -115,  -86,    0, -115,    0,};const short yyrindex[] = {                                      0,    0,    0,    0,    0,    0,    0,  173,    0,    0,    0,    0,    0,    0,    0,    0,    0, -177,    0,    0,    0,    0,    0,    0, -107,    0, -166,    0,    0,    0,    0,    0,  -48, -112,    0,    0,  -68,    0, -107,    0, -100,    0, -245,    0,    0,    0,   88,   30,  -94,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0, -215,  -99,    0,    0,    0,    0,  -92,   48,   68,  -28,   -8,  102,  118,  134,  150, -220,  174,  199, -272,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0, -185,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0, -166,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0, -126,    0,    0,    0,};const short yygindex[] = {                                      0,    0,  195,  108,    0,    0,  179,    0,  159,  -58,    0,    0,   37,    0,    0,    0,    0,  -27,  -12,   75,  207,    0,    0,    0,    0,    3,    2,  221,};#define YYTABLESIZE 491const short yytable[] = {                                      15,   85,   13,   12,   45,   87,    5,   86,   25,   13,   12,   93,   53,   22,   17,   53,   53,   86,   53,   46,   53,   69,   26,  103,   24,  104,   94,  105,  106,  107,    5,   27,   28,   29,   51,   52,   46,    5,   27,   28,   29,   90,   59,   26,   65,   26,   30,   38,  108,   68,   31,   48,   48,   30,   86,  109,   46,   31,   21,   63,   96,   59,   59,   22,   59,   98,   64,   59,   59,   43,   59,   67,   59,   27,   22,   27,   84,   34,  121,   34,   46,   34,   34,   34,   34,   34,   34,   34,   46,   15,   89,  125,  126,   46,   19,   20,   33,   37,  101,   91,   34,   92,   34,  117,   34,   59,   46,   46,   34,   34,   51,   51,    8,    1,    2,    3,   46,   46,   66,    4,   46,   51,   51,    5,   72,   73,   74,   75,   76,   77,   78,   79,   80,   81,   82,   83,   44,  118,   44,  119,   44,   44,   44,   44,   44,   44,   44,  103,  122,  104,  123,  105,  106,  107,    5,   27,   28,   29,  124,   44,  127,   44,  128,   44,   97,  130,  131,   44,   44,  133,   30,  129,  108,    1,   31,   13,   13,  132,   86,    5,   27,   28,   29,   23,    5,   27,   28,   29,   12,   12,   22,   49,   50,   51,   52,   30,   77,  120,   76,   31,   30,   59,   14,   99,   31,   51,   51,   51,   51,   51,   51,   51,   51,   51,   51,   51,   51,   62,   51,   51,   51,   51,   51,   88,   51,   67,   67,   67,   67,   67,   67,   67,   67,   67,   67,   67,   67,   44,   23,   67,   67,    0,   67,    0,   67,   63,   63,   63,   63,   63,   63,   63,   63,   63,   63,    0,   63,    0,    0,   63,   63,    0,   63,    0,   63,   64,   64,   64,   64,   64,   64,   64,   64,   64,   64,    0,   64,    0,    0,   64,   64,    0,   64,    0,   64,   49,   50,   51,   52,   53,   54,   55,   56,   57,   58,   59,   60,    1,    2,    3,    0,    0,    0,    4,   61,   49,   50,   51,   52,   53,   54,   55,   56,   57,   58,   59,   60,   50,   50,    0,   50,   61,   61,    0,  102,   61,   61,   61,   61,   61,   61,    0,   61,    0,    0,   61,   61,    0,   61,    0,   61,   62,   62,    0,    0,   62,   62,   62,   62,   62,   62,    0,   62,    0,    0,   62,   62,    0,   62,    0,   62,   67,   67,   67,   67,   67,   67,   67,   67,   67,   67,   67,   67,    0,    0,   67,   67,    0,   67,   55,   55,   55,   55,   55,   55,    0,   55,    0,    0,   55,   55,    0,   55,    0,   55,   56,   56,   56,   56,   56,   56,    0,   56,    0,    0,   56,   56,    0,   56,    0,   56,   57,   57,   57,   57,   57,   57,    0,   57,    0,    0,   57,   57,    0,   57,    0,   57,   58,   58,   58,   58,   58,   58,    0,   58,    0,    0,   58,   58,    0,   58,    0,   58,   49,   50,   51,   52,   53,   54,   55,   56,   57,   58,   59,   60,   60,   60,    0,   60,    0,    0,   60,   60,    0,   60,    0,   60,   49,   50,   51,   52,   53,   54,   55,   56,   57,   58,   59,   49,   50,   51,   52,   53,   54,   55,   56,   54,   54,   59,   54,    0,   54,};const short yycheck[] = {                                      12,  287,    0,    0,   31,   63,  269,  293,   20,    7,    7,  287,  284,  291,   12,  287,  288,  293,  290,   31,  292,   48,   20,  262,  289,  264,   84,  266,  267,  268,  269,  270,  271,  272,  275,  276,   48,  269,  270,  271,  272,   68,  283,  288,   42,  290,  285,  289,  287,  286,  289,  289,  289,  285,  293,  294,   68,  289,  286,  290,  292,  281,  282,  291,  284,   92,  288,  287,  288,  286,  290,  290,  292,  288,  291,  290,  290,  262,  105,  264,   92,  266,  267,  268,  269,  270,  271,  272,  100,  101,  291,  118,  119,  105,  287,  288,   21,   22,   95,  290,  285,  288,  287,  101,  289,  283,  118,  119,  293,  294,  287,  288,  289,  259,  260,  261,  128,  129,   43,  265,  132,  287,  288,  269,   49,   50,   51,   52,   53,   54,   55,   56,   57,   58,   59,   60,  262,  289,  264,  289,  266,  267,  268,  269,  270,  271,  272,  262,  287,  264,  287,  266,  267,  268,  269,  270,  271,  272,  287,  285,  287,  287,  290,  289,   89,  128,  129,  293,  294,  132,  285,  290,  287,    0,  289,  287,  288,  263,  293,  269,  270,  271,  272,  290,  269,  270,  271,  272,  287,  288,  290,  273,  274,  275,  276,  285,  290,  287,  290,  289,  285,  283,    7,   95,  289,  273,  274,  275,  276,  277,  278,  279,  280,  281,  282,  283,  284,   38,  286,  287,  288,  289,  290,   64,  292,  273,  274,  275,  276,  277,  278,  279,  280,  281,  282,  283,  284,   30,   17,  287,  288,   -1,  290,   -1,  292,  273,  274,  275,  276,  277,  278,  279,  280,  281,  282,   -1,  284,   -1,   -1,  287,  288,   -1,  290,   -1,  292,  273,  274,  275,  276,  277,  278,  279,  280,  281,  282,   -1,  284,   -1,   -1,  287,  288,   -1,  290,   -1,  292,  273,  274,  275,  276,  277,  278,  279,  280,  281,  282,  283,  284,  259,  260,  261,   -1,   -1,   -1,  265,  292,  273,  274,  275,  276,  277,  278,  279,  280,  281,  282,  283,  284,  287,  288,   -1,  290,  273,  274,   -1,  292,  277,  278,  279,  280,  281,  282,   -1,  284,   -1,   -1,  287,  288,   -1,  290,   -1,  292,  273,  274,   -1,   -1,  277,  278,  279,  280,  281,  282,   -1,  284,   -1,   -1,  287,  288,   -1,  290,   -1,  292,  273,  274,  275,  276,  277,  278,  279,  280,  281,  282,  283,  284,   -1,   -1,  287,  288,   -1,  290,  277,  278,  279,  280,  281,  282,   -1,  284,   -1,   -1,  287,  288,   -1,  290,   -1,  292,  277,  278,  279,  280,  281,  282,   -1,  284,   -1,   -1,  287,  288,   -1,  290,   -1,  292,  277,  278,  279,  280,  281,  282,   -1,  284,   -1,   -1,  287,  288,   -1,  290,   -1,  292,  277,  278,  279,  280,  281,  282,   -1,  284,   -1,   -1,  287,  288,   -1,  290,   -1,  292,  273,  274,  275,  276,  277,  278,  279,  280,  281,  282,  283,  284,  281,  282,   -1,  284,   -1,   -1,  287,  288,   -1,  290,   -1,  292,  273,  274,  275,  276,  277,  278,  279,  280,  281,  282,  283,  273,  274,  275,  276,  277,  278,  279,  280,  287,  288,  283,  290,   -1,  292,};#define YYFINAL 6#ifndef YYDEBUG#define YYDEBUG 0#endif#define YYMAXTOKEN 294#if YYDEBUGconst char * const yyname[] = {"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"ENDFILE","ERROR","INT","CHAR","FLOAT","IF","ELSE","WHILE","VOID","RETURN","BREAK","CONTINUE","ID","NUM","FNUM","SCHAR","PLUS","SUB","MUT","DIV","LT","LE","GT","GE","EQ","NEQ","AND","OR","NOT","ASSIGN","SEMI","COMMA","LP","RP","LSP","RSP","LFP","RFP",};const char * const yyrule[] = {"$accept : program","program : dec_list","dec_list : dec_list dec","dec_list : dec","dec : var_dec","dec : fun_dec","dec : fun_def","id : ID","fid :","var_dec : type_spec id_list SEMI","id_list : id_list COMMA var","id_list : var","id_list : id_list COMMA id ASSIGN simple_exp","id_list : id ASSIGN simple_exp","type_spec : INT","type_spec : FLOAT","type_spec : CHAR","type_spec : VOID","fun_def : type_spec id fid LP params RP comp_stmt","fun_def : id fid LP params RP comp_stmt","fun_dec : type_spec id fid LP params RP SEMI","fun_dec : id fid LP params RP SEMI","params : param_list","params :","param_list : param_list COMMA param","param_list : param","param : type_spec","param : type_spec id","param : type_spec id LSP RSP","param : type_spec id LSP simple_exp RSP","comp_stmt : LFP local_dec stmt_list RFP","local_dec : local_dec var_dec","local_dec :","stmt_list : stmt_list stmt","stmt_list :","stmt : exp_stmt","stmt : sele_stmt","stmt : iter_stmt","stmt : return_stmt","stmt : comp_stmt","stmt : CONTINUE SEMI","stmt : BREAK SEMI","exp_stmt : exp SEMI","exp_stmt : SEMI","sele_stmt : IF LP exp RP stmt","sele_stmt : IF LP exp RP stmt ELSE stmt","iter_stmt : WHILE LP exp RP stmt","return_stmt : RETURN SEMI","return_stmt : RETURN exp SEMI","exp : var ASSIGN exp","exp : simple_exp","var : id","var : id LSP simple_exp RSP","simple_exp : simple_exp OR simple_exp","simple_exp : simple_exp AND simple_exp","simple_exp : simple_exp LT simple_exp","simple_exp : simple_exp LE simple_exp","simple_exp : simple_exp GT simple_exp","simple_exp : simple_exp GE simple_exp","simple_exp : simple_exp EQ simple_exp","simple_exp : simple_exp NEQ simple_exp","simple_exp : simple_exp PLUS simple_exp","simple_exp : simple_exp SUB simple_exp","simple_exp : simple_exp MUT simple_exp","simple_exp : simple_exp DIV simple_exp","simple_exp : factor","factor : LP exp RP","factor : var","factor : call","factor : NUM","factor : FNUM","factor : SCHAR","factor : NOT factor","call : var LP args RP","arg_list : arg_list COMMA exp","arg_list : exp","args : arg_list","args :",};#endif#if YYDEBUG#include <stdio.h>#endif#ifdef YYSTACKSIZE#undef YYMAXDEPTH#define YYMAXDEPTH YYSTACKSIZE#else#ifdef YYMAXDEPTH#define YYSTACKSIZE YYMAXDEPTH#else#define YYSTACKSIZE 10000#define YYMAXDEPTH 10000#endif#endif#define YYINITSTACKSIZE 200int yydebug;int yynerrs;int yyerrflag;int yychar;short *yyssp;YYSTYPE *yyvsp;YYSTYPE yyval;YYSTYPE yylval;short *yyss;short *yysslim;YYSTYPE *yyvs;int yystacksize;#line 509 "Parse.y"void yyerror(char *msg){	fprintf(g_lst_file, "Syntax error at line %d: %s\n", g_lineno, msg);	fprintf(g_lst_file, "Current token: ");	printToken(yychar, tokenString);	g_error = TRUE;}static TokenType yylex(){	return getToken();}TreeNode *parse(){	yyparse();	return savedTree;}#line 414 "Parse.c"/* allocate initial stack or double stack size, up to YYMAXDEPTH */static int yygrowstack()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -