📄 rule.c
字号:
/* A Bison parser, made by GNU Bison 2.3. *//* Skeleton implementation for Bison's Yacc-like parsers in C Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *//* As a special exception, you may create a larger work that contains part or all of the Bison parser skeleton and distribute that work under terms of your choice, so long as that work isn't itself a parser generator using the skeleton or a modified version thereof as a parser skeleton. Alternatively, if you modify or redistribute the parser skeleton itself, you may (at your option) remove this special exception, which will cause the skeleton and the resulting Bison output files to be licensed under the GNU General Public License without this special exception. This special exception was added by the Free Software Foundation in version 2.2 of Bison. *//* C LALR(1) parser skeleton written by Richard Stallman, by simplifying the original so-called "semantic" parser. *//* All symbols defined below should begin with yy or YY, to avoid infringing on user name space. This should be done even for local variables, as they might otherwise be expanded by user macros. There are some unavoidable exceptions within include files to define necessary library symbols; they are noted "INFRINGES ON USER NAME SPACE" below. *//* Identify Bison output. */#define YYBISON 1/* Bison version. */#define YYBISON_VERSION "2.3"/* Skeleton name. */#define YYSKELETON_NAME "yacc.c"/* Pure parsers. */#define YYPURE 0/* Using locations. */#define YYLSP_NEEDED 0/* Tokens. */#ifndef YYTOKENTYPE# define YYTOKENTYPE /* Put the tokens into the symbol table, so that GDB and other debuggers know about them. */ enum yytokentype { kAND = 258, kARRAY = 259, kBEGIN = 260, kCASE = 261, kCONST = 262, kDIV = 263, kDO = 264, kDOWNTO = 265, kELSE = 266, kEND = 267, kFILE = 268, kFOR = 269, kFUNCTION = 270, kGOTO = 271, kIF = 272, kIN = 273, kLABEL = 274, kMOD = 275, kNIL = 276, kNOT = 277, kOF = 278, kOR = 279, kPACKED = 280, kPROCEDURE = 281, kPROGRAM = 282, kRECORD = 283, kREPEAT = 284, kSET = 285, kTHEN = 286, kTO = 287, kTYPE = 288, kUNTIL = 289, kVAR = 290, kWHILE = 291, kWITH = 292, SYS_CON = 293, cFALSE = 294, cTRUE = 295, cMAXINT = 296, cSTRING = 297, cINTEGER = 298, cREAL = 299, cCHAR = 300, cBOOLEAN = 301, SYS_TYPE = 302, tINTEGER = 303, tCHAR = 304, tREAL = 305, tBOOLEAN = 306, tTEXT = 307, SYS_FUNCT = 308, fABS = 309, fCHR = 310, fODD = 311, fORD = 312, fPRED = 313, fSQR = 314, fSQRT = 315, fSUCC = 316, SYS_PROC = 317, pREAD = 318, pREADLN = 319, pWRITE = 320, pWRITELN = 321, oPLUS = 322, oMINUS = 323, oMUL = 324, oDIV = 325, oEQUAL = 326, oASSIGN = 327, oUNEQU = 328, oLT = 329, oLE = 330, oGT = 331, oGE = 332, oCOMMA = 333, oSEMI = 334, oCOLON = 335, oQUOTE = 336, oDOT = 337, oDOTDOT = 338, oARROW = 339, oLP = 340, oRP = 341, oLB = 342, oRB = 343, oLC = 344, oRC = 345, yNAME = 346 };#endif/* Tokens. */#define kAND 258#define kARRAY 259#define kBEGIN 260#define kCASE 261#define kCONST 262#define kDIV 263#define kDO 264#define kDOWNTO 265#define kELSE 266#define kEND 267#define kFILE 268#define kFOR 269#define kFUNCTION 270#define kGOTO 271#define kIF 272#define kIN 273#define kLABEL 274#define kMOD 275#define kNIL 276#define kNOT 277#define kOF 278#define kOR 279#define kPACKED 280#define kPROCEDURE 281#define kPROGRAM 282#define kRECORD 283#define kREPEAT 284#define kSET 285#define kTHEN 286#define kTO 287#define kTYPE 288#define kUNTIL 289#define kVAR 290#define kWHILE 291#define kWITH 292#define SYS_CON 293#define cFALSE 294#define cTRUE 295#define cMAXINT 296#define cSTRING 297#define cINTEGER 298#define cREAL 299#define cCHAR 300#define cBOOLEAN 301#define SYS_TYPE 302#define tINTEGER 303#define tCHAR 304#define tREAL 305#define tBOOLEAN 306#define tTEXT 307#define SYS_FUNCT 308#define fABS 309#define fCHR 310#define fODD 311#define fORD 312#define fPRED 313#define fSQR 314#define fSQRT 315#define fSUCC 316#define SYS_PROC 317#define pREAD 318#define pREADLN 319#define pWRITE 320#define pWRITELN 321#define oPLUS 322#define oMINUS 323#define oMUL 324#define oDIV 325#define oEQUAL 326#define oASSIGN 327#define oUNEQU 328#define oLT 329#define oLE 330#define oGT 331#define oGE 332#define oCOMMA 333#define oSEMI 334#define oCOLON 335#define oQUOTE 336#define oDOT 337#define oDOTDOT 338#define oARROW 339#define oLP 340#define oRP 341#define oLB 342#define oRB 343#define oLC 344#define oRC 345#define yNAME 346/* Copy the first part of user declarations. */#line 1 "spl.y"#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#include "common.h"#include "symtab.h"#include "error.h"#include "tree.h"#ifdef _MSDOS_#include "debug.h"#include "type.h"#endif#include "x86.h"extern char *yytext;symtab *ptab;symbol *p, *q;tree *t;type *pt, *qt;int temp;symbol* pop_term_stack();symbol* top_term_stack();void push_term_stack(symbol * p);Env global_env;Env main_env;Symtab rtn = NULL;Symbol arg = NULL;#ifdef GENERATE_ASTTree pop_ast_stack();Tree top_ast_stack();void push_ast_stack(Tree t);int pop_lbl_stack();int top_lbl_stack();void push_lbl_stack(int id);int pop_case_stack();int top_case_stack();void push_case_stack(int id);List pop_case_ast_stack();List top_case_ast_stack();void push_case_ast_stack(List newlist);struct list ast_forest;struct list para_list; /* for parameter list. */List case_list = NULL;struct list dag_forest; /* for dags. */Tree args;Tree now_function;Tree t;Symbol new_label = NULL;/* Symbol case_label = NULL; */Symbol test_label = NULL;Symbol exit_label = NULL;char mini_buf[NAME_LEN]; /* buffer for generated name. */int if_label_count; /* count for label of if test. */int repeat_label_count; /* count for label of repeat. */int case_label_count; /* count for label of case. */int switch_label_count; /* count for label of switch. */int do_label_count; /* count for label of do. */int while_label_count; /* count for label of while. */int for_label_count; /* count for label of for. */#endifint parser_init();Symbol install_temporary_symbol(char *name, int deftype, int typeid);Type install_temporary_type(char *name, int deftype, int typeid);void trap_in_debug();#ifdef DEBUG#define DEBUG_POINT trap_in_debug();#endif#if 0#ifndef GENERATE_AST%type <num>proc_stmt assign_stmt%type <num>expression expression_list%type <p_symbol>factor term expr#else%type <p_tree>proc_stmt assign_stmt%type <p_tree>factor term expr%type <p_tree>expression expression_list#endif#endif/* Enabling traces. */#ifndef YYDEBUG# define YYDEBUG 0#endif/* Enabling verbose error messages. */#ifdef YYERROR_VERBOSE# undef YYERROR_VERBOSE# define YYERROR_VERBOSE 1#else# define YYERROR_VERBOSE 1#endif/* Enabling the token table. */#ifndef YYTOKEN_TABLE# define YYTOKEN_TABLE 0#endif#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLAREDtypedef union YYSTYPE#line 106 "spl.y"{ char p_char[NAME_LEN]; int num;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -