diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c0444f7
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,49 @@
+# Prerequisites
+*.d
+
+# Compiled Object files
+*.slo
+*.lo
+*.o
+*.obj
+
+# Precompiled Headers
+*.gch
+*.pch
+
+# Compiled Dynamic libraries
+*.so
+*.dylib
+*.dll
+
+# Fortran module files
+*.mod
+*.smod
+
+# Compiled Static libraries
+*.lai
+*.la
+*.a
+*.lib
+
+# Executables
+*.exe
+*.out
+*.app
+
+#cyg
+*.stackdump
+
+# vs
+*.suo
+*.VC.db
+*.filters
+*.user
+*/Debug/
+*/x64/
+Debug/
+*VC.opendb
+
+# graphdot
+*.dot
+*.jpg
diff --git a/.vs/CompilerPascal/v14/.suo b/.vs/CompilerPascal/v14/.suo
new file mode 100644
index 0000000..af1690c
Binary files /dev/null and b/.vs/CompilerPascal/v14/.suo differ
diff --git a/CompilerPascal.VC.db b/CompilerPascal.VC.db
new file mode 100644
index 0000000..3deeee7
Binary files /dev/null and b/CompilerPascal.VC.db differ
diff --git a/CompilerPascal.sln b/CompilerPascal.sln
new file mode 100644
index 0000000..a266d85
--- /dev/null
+++ b/CompilerPascal.sln
@@ -0,0 +1,28 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 14
+VisualStudioVersion = 14.0.25123.0
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CompilerPascal", "CompilerPascal\CompilerPascal.vcxproj", "{30F849DD-F677-4B3D-B1F2-59B1C74F8D8D}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|x64 = Debug|x64
+ Debug|x86 = Debug|x86
+ Release|x64 = Release|x64
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {30F849DD-F677-4B3D-B1F2-59B1C74F8D8D}.Debug|x64.ActiveCfg = Debug|x64
+ {30F849DD-F677-4B3D-B1F2-59B1C74F8D8D}.Debug|x64.Build.0 = Debug|x64
+ {30F849DD-F677-4B3D-B1F2-59B1C74F8D8D}.Debug|x86.ActiveCfg = Debug|Win32
+ {30F849DD-F677-4B3D-B1F2-59B1C74F8D8D}.Debug|x86.Build.0 = Debug|Win32
+ {30F849DD-F677-4B3D-B1F2-59B1C74F8D8D}.Release|x64.ActiveCfg = Release|x64
+ {30F849DD-F677-4B3D-B1F2-59B1C74F8D8D}.Release|x64.Build.0 = Release|x64
+ {30F849DD-F677-4B3D-B1F2-59B1C74F8D8D}.Release|x86.ActiveCfg = Release|Win32
+ {30F849DD-F677-4B3D-B1F2-59B1C74F8D8D}.Release|x86.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/CompilerPascal/1pas.txt b/CompilerPascal/1pas.txt
new file mode 100644
index 0000000..c1a5132
--- /dev/null
+++ b/CompilerPascal/1pas.txt
@@ -0,0 +1,7 @@
+y VAR INT
+x VAR INT
+max FUN INT INT INT
+rec VAR RECORD
+s VAR STRING
+outer VAR INT
+c VAR CHAR
diff --git a/CompilerPascal/2pas.txt b/CompilerPascal/2pas.txt
new file mode 100644
index 0000000..0a16043
--- /dev/null
+++ b/CompilerPascal/2pas.txt
@@ -0,0 +1,3 @@
+x NAME
+y VAR INT
+x VAR INT
diff --git a/CompilerPascal/3pas.txt b/CompilerPascal/3pas.txt
new file mode 100644
index 0000000..5c19a97
--- /dev/null
+++ b/CompilerPascal/3pas.txt
@@ -0,0 +1,19 @@
+mc VAR CHAR
+x VAR INT
+linktest FUN INT CHAR
+m VAR CHAR
+t VAR INT
+y VAR INT
+x VAR INT
+y VAR INT
+x VAR INT
+max FUN INT INT INT
+swap FUN INT INT VOID
+a VAR ARRAY
+sum VAR INT
+i VAR INT
+y VAR INT
+x VAR INT
+n VAR REAL
+m VAR REAL
+c VAR CHAR
diff --git a/CompilerPascal/4pas.txt b/CompilerPascal/4pas.txt
new file mode 100644
index 0000000..81fbf5d
--- /dev/null
+++ b/CompilerPascal/4pas.txt
@@ -0,0 +1,14 @@
+y VAR INT
+x VAR INT
+max FUN INT INT INT
+ar VAR ARRAY
+rec VAR RECORD
+k VAR BOOLEAN
+outer VAR INT
+z VAR CHAR
+i VAR INT
+y VAR INT
+x VAR INT
+c CONST REAL
+b CONST INT
+a CONST INT
diff --git a/CompilerPascal/5pas.txt b/CompilerPascal/5pas.txt
new file mode 100644
index 0000000..e0bbb32
--- /dev/null
+++ b/CompilerPascal/5pas.txt
@@ -0,0 +1,4 @@
+rec VAR RECORD
+s VAR STRING
+outer VAR INT
+c VAR CHAR
diff --git a/CompilerPascal/CompilerPascal.vcxproj b/CompilerPascal/CompilerPascal.vcxproj
new file mode 100644
index 0000000..f8d0343
--- /dev/null
+++ b/CompilerPascal/CompilerPascal.vcxproj
@@ -0,0 +1,161 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ x64
+
+
+
+ {30F849DD-F677-4B3D-B1F2-59B1C74F8D8D}
+ CompilerPascal
+ 8.1
+
+
+
+ Application
+ true
+ v140
+ MultiByte
+
+
+ Application
+ false
+ v140
+ true
+ MultiByte
+
+
+ Application
+ true
+ v140
+ MultiByte
+
+
+ Application
+ false
+ v140
+ true
+ MultiByte
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Level3
+ Disabled
+ false
+
+
+
+
+ Level3
+ Disabled
+ true
+
+
+
+
+ Level3
+ MaxSpeed
+ true
+ true
+ false
+
+
+ true
+ true
+
+
+
+
+ Level3
+ MaxSpeed
+ true
+ true
+ true
+
+
+ true
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/CompilerPascal/IRTree.dot b/CompilerPascal/IRTree.dot
new file mode 100644
index 0000000..72ff353
--- /dev/null
+++ b/CompilerPascal/IRTree.dot
@@ -0,0 +1,33 @@
+digraph g {
+node[peripheries=2, style=filled;]
+node1->node2;
+node1[label="LABEL"];
+node2[label="L12"];
+node3->node4->node5;
+node4[label="TEMP"];
+node5[label="t100"];
+node3->node6->node7;
+node6[label="CONST"];
+node7[label="0"];
+node3[label="MOVE"];
+node8->node9->node10;
+node9[label="TEMP"];
+node10[label="t100"];
+node8->node11->node12;
+node11->node13->node14;
+node13[label="TEMP"];
+node14[label="t100"];
+node11->node15->node16;
+node15[label="CONST"];
+node16[label="1"];
+node11[label="BINOP"];
+node12[label="PLUS"];
+node8[label="MOVE"];
+node17->node18->node19;
+node18[label="NAME"];
+node19[label="L11"];
+node17[label="JUMP"];
+node20->node21;
+node20[label="LABEL"];
+node21[label="L11"];
+}
\ No newline at end of file
diff --git a/src/Makefile b/CompilerPascal/Makefile
similarity index 61%
rename from src/Makefile
rename to CompilerPascal/Makefile
index b8cc32a..4cf7d5c 100644
--- a/src/Makefile
+++ b/CompilerPascal/Makefile
@@ -1,4 +1,4 @@
-objects = main.o semant.o env.o types.o translate.o tree.o prabsyn.o temp.o frame.o symbol.o table.o absyn.o util.o errormsg.o y.tab.o lex.yy.o
+objects = main.o codegen.o assem.o canon.o drawtree.o printtree.o semant.o env.o types.o escape.o translate.o tree.o prabsyn.o temp.o frame.o symbol.o table.o absyn.o util.o errormsg.o y.tab.o lex.yy.o
pascalc: $(objects)
cc -o pascalc -g $(objects)
@@ -6,6 +6,21 @@ pascalc: $(objects)
main.o:
cc -g -c main.c
+codegen.o: codegen.c codegen.h
+ cc -g -c codegen.c
+
+assem.o: assem.c assem.h
+ cc -g -c assem.c
+
+canon.o: canon.c canon.h
+ cc -g -c canon.c
+
+drawtree.o: drawtree.c drawtree.h
+ cc -g -c drawtree.c
+
+printtree.o: printtree.c printtree.h
+ cc -g -c printtree.c
+
semant.o: semant.c semant.h
cc -g -c semant.c
@@ -15,6 +30,9 @@ env.o: env.c env.h
types.o: types.c types.h
cc -g -c types.c
+escape.o: escape.c escape.h
+ cc -g -c escape.c
+
translate.o: translate.c translate.h
cc -g -c translate.c
@@ -57,4 +75,7 @@ prabsyn.o: prabsyn.c prabsyn.h
cc -g -c prabsyn.c
clean:
- rm -f *.o
\ No newline at end of file
+ rm -f *.o
+
+graph:
+ dot -Tjpg IRTree.dot -o IRTree.jpg
\ No newline at end of file
diff --git a/src/Pascal.l b/CompilerPascal/Pascal.l
similarity index 90%
rename from src/Pascal.l
rename to CompilerPascal/Pascal.l
index 6861530..533d06e 100644
--- a/src/Pascal.l
+++ b/CompilerPascal/Pascal.l
@@ -1,11 +1,13 @@
%{
#include
+#include
#include "util.h"
#include "errormsg.h"
#include "symbol.h"
#include "absyn.h"
#include "y.tab.h"
+#define YY_NO_UNISTD_H
// update EM_tokPos
void updatePos(void);
int charPos;
@@ -14,8 +16,8 @@ div [dD][iI][vV]
mod [mM][oO][dD]
integer [0-9]+
real [0-9]+\.[0-9]+
-char [A-za-z\_\'\.\"]
-string \"char+\"
+char [A-za-z\_\'\.\" \t\n]
+string \"{char}+\"
program [pP][rR][oO][gG][rR][aA][mM]
const [cC][oO][nN][sS][tT]
type [tT][yY][pP][eE]
@@ -130,20 +132,29 @@ sys_type boolt|cht|intt|realt
yylval.rval = getNum;
return REAL;
}
-{char} {updatePos(); yylval.cval = yytext[0]; return CHAR; }
-{string} {updatePos(); yylval.sval = yytext; return STRING; }
+
+\'{char}\' { updatePos(); yylval.cval = yytext[1]; return CHAR; }
+{string} { updatePos(); yylval.sval = yytext+1; yytext[strlen(yytext)-1] = 0; return STRING; }
+
{sys_con} {updatePos(); return SYS_CON;}
{sys_funct} {updatePos(); return SYS_FUNCT;}
{sys_proc} {updatePos(); return SYS_PROC;}
{sys_type} {updatePos(); return SYS_TYPE;}
\n {updatePos(); EM_newline();}
\r\n {updatePos(); EM_newline();}
+\/\/[^\n]* {}
+"{"([^\*]|(\*)*[^\*/])*(\*)*"}" {for(int i = 1; i='A'&&yytext[i]<='Z')
+ yytext[i] = yytext[i]-'A'+'a';
+ }
}
int yywrap(){
charPos = 1;
diff --git a/CompilerPascal/Pascal.l.bak b/CompilerPascal/Pascal.l.bak
new file mode 100644
index 0000000..c9ae644
--- /dev/null
+++ b/CompilerPascal/Pascal.l.bak
@@ -0,0 +1,157 @@
+%{
+#include
+#include
+#include "util.h"
+#include "errormsg.h"
+#include "symbol.h"
+#include "absyn.h"
+#include "y.tab.h"
+
+#define YY_NO_UNISTD_H
+// update EM_tokPos
+void updatePos(void);
+int charPos;
+%}
+div [dD][iI][vV]
+mod [mM][oO][dD]
+integer [0-9]+
+real [0-9]+\.[0-9]+
+char [A-za-z\_\'\.\" \t\n]
+string \"{char}+\"
+program [pP][rR][oO][gG][rR][aA][mM]
+const [cC][oO][nN][sS][tT]
+type [tT][yY][pP][eE]
+var [vV][aA][rR]
+array [aA][rR][rR][aA][yY]
+of [oO][fF]
+record [rR][eE][cC][oO][rR][dD]
+end [eE][nN][dD]
+function [fF][uU][nN][cC][tT][iI][oO][nN]
+procedure [pP][rR][oO][cC][eE][dD][uU][rR][eE]
+begin [bB][eE][gG][iI][nN]
+read [rR][eE][aA][dD]
+if [iI][fF]
+then [tT][hH][eE][nN]
+else [eE][lL][sS][eE]
+repeat [rR][eE][pP][eE][aA][tT]
+until [uU][nN][tT][iI][lL]
+while [wW][hH][iI][lL][eE]
+do [dD][oO]
+for [fF][oO][rR]
+to [tT][oO]
+downto [dD][oO][wW][nN][tT][oO]
+case [cC][aA][sS][eE]
+goto [gG][oO][tT][oO]
+and [aA][nN][dD]
+or [oO][rR]
+not [nN][oO][tT]
+false [fF][aA][lL][sS][eE]
+maxint [mM][aA][xX][iI][nN][tT]
+true [tT][rR][uU][eE]
+sys_con false|maxint|true
+abs [aA][bB][sS]
+chr [cC][hH][rR]
+odd [oO][dD][dD]
+ord [oO][rR][dD]
+pred [pP][rR][eE][dD]
+sqr [sS][qQ][rR]
+sqrt [sS][qQ][rR][tT]
+succ [sS][uU[cC][cC]
+sys_funct abs|chr|odd|ord|pred|sqr|sqrt|succ
+write [wW][rR][iI][tT][eE]
+writeln [wW][rR][iI][tT][eE][lL][nN]
+sys_proc write|writeln
+boolt [bB][oO][oO][lL][eE][aA][nN]
+cht [cC][hH][aA][rR]
+intt [iI][nN][tT][eE][gG][eE][rR]
+realt [rR][eE][aA][lL]
+sys_type boolt|cht|intt|realt
+%%
+
+"(" {updatePos(); return LP;}
+")" {updatePos(); return RP;}
+"[" {updatePos(); return LB;}
+"]" {updatePos(); return RB;}
+"." {updatePos(); return DOT;}
+".." {updatePos(); return DOTDOT;}
+"," {updatePos(); return COMMA; }
+":" {updatePos(); return COLON;} //应该是:SEMI应该是;
+";" {updatePos(); return SEMI;} //name == id
+"+" {updatePos(); return PLUS;}
+"-" {updatePos(); return MINUS;}
+"*" {updatePos(); return MUL;}
+"/" {updatePos(); return REALDIV;}
+{div} {updatePos(); return INTDIV;}
+{mod} {updatePos(); return MOD; }
+">=" {updatePos(); return GE;}
+">" {updatePos(); return GT;}
+"<=" {updatePos(); return LE;}
+"<" {updatePos(); return LT;}
+"=" {updatePos(); return EQUAL;}
+"<>" {updatePos(); return UNEQUAL;}
+":=" {updatePos(); return ASSIGN;}
+{program} {updatePos(); return PROGRAM;}
+{const} {updatePos(); return CONST;}
+{type} {updatePos(); return TYPE;}
+{var} {updatePos(); return VAR;}
+{array} {updatePos(); return ARRAY;}
+{of} {updatePos(); return OF;}
+{record} {updatePos(); return RECORD;}
+{end} {updatePos(); return END;}
+{function} {updatePos(); return FUNCTION;}
+{procedure} {updatePos(); return PROCEDURE;}
+{begin} {updatePos(); return BEGIN_T;}
+{read} {updatePos(); return READ;}
+{if} {updatePos(); return IF;}
+{then} {updatePos(); return THEN;}
+{else} {updatePos(); return ELSE;}
+{repeat} {updatePos(); return REPEAT;}
+{until} {updatePos(); return UNTIL;}
+{while} {updatePos(); return WHILE;}
+{do} {updatePos(); return DO;}
+{for} {updatePos(); return FOR;}
+{to} {updatePos(); return TO;}
+{downto} {updatePos(); return DOWNTO;}
+{case} {updatePos(); return CASE;}
+{goto} {updatePos(); return GOTO;}
+{and} {updatePos(); return AND;}
+{or} {updatePos(); return OR;}
+{not} {updatePos(); return NOT;}
+[a-zA-Z][0-9a-zA-Z]* {updatePos(); yylval.sval = yytext; return ID;}
+{integer} {
+ updatePos();
+ int getNum;
+ sscanf(yytext, "%d", &getNum);
+ yylval.ival = getNum;
+ return INTEGER;
+}
+{real} {
+ updatePos();
+ double getNum;
+ sscanf(yytext, "%lf", &getNum);
+ yylval.rval = getNum;
+ return REAL;
+}
+
+\'{char}\' { updatePos(); yylval.cval = yytext[1]; return CHAR; }
+{string} { updatePos(); yylval.sval = yytext+1; yytext[strlen(yytext)-1] = 0; return STRING; }
+
+{sys_con} {updatePos(); return SYS_CON;}
+{sys_funct} {updatePos(); return SYS_FUNCT;}
+{sys_proc} {updatePos(); return SYS_PROC;}
+{sys_type} {updatePos(); return SYS_TYPE;}
+\n {updatePos(); EM_newline();}
+\r\n {updatePos(); EM_newline();}
+\/\/[^\n]* {}
+"{"([^\*]|(\*)*[^\*/])*(\*)*"}" {for(int i = 1; i id sys_con sys_funct sys_proc sys_type
%type type_decl simple_type_decl array_type_decl record_type_decl
%type field_decl_list field_decl name_list parameters para_type_list para_decl_list var_para_list val_para_list
-%type stat;
+%type error_stmt;
%start program
%%
-program : program_head routine DOT {/*set root for abstract syntax tree*/ A_synTreeRoot = $2; /*printf("Program parsed.\n");*/}
-program_head : PROGRAM id SEMI {/*printf("Program head.\n");*/}
+program : program_head routine DOT {/*set root for abstract syntax tree*/ A_synTreeRoot = $2; }
+program_head : PROGRAM id SEMI {}
routine : routine_head routine_body {/*head:declaration with type A_decList, body:expression with type A_exp*/ $$ = A_LetExp(EM_tokPos, $1, $2);}
routine_head : label_part const_part type_part var_part routine_part {
/* placeholder*/
@@ -102,6 +102,8 @@ const_part : CONST const_expr_list {/*const declaration part*/ $$ = $2;}
| {/*no const declaration*/ $$ = NULL;}
const_expr_list : id EQUAL const_value SEMI const_expr_list {/*const declaration list*/ $$ = A_DecList(A_ConstDec(EM_tokPos, $1, $3),$5);}
| id EQUAL const_value SEMI {/*first one in list*/ $$ = A_DecList(A_ConstDec(EM_tokPos, $1, $3), NULL);}
+ | error_stmt const_expr_list {/*run into error*/ $$ = $2;}
+ | error_stmt {$$ = NULL;}
const_value : INTEGER {/*integer value*/ $$ = A_IntExp(EM_tokPos, $1);}
| REAL{/*real value*/ $$ = A_RealExp(EM_tokPos, $1);}
| CHAR{/*char value*/ $$ = A_CharExp(EM_tokPos, $1);}
@@ -113,6 +115,8 @@ type_part : TYPE type_decl_list {/*type declaration part*/ $$ = A_DecList(A_Ty
| {/*no type declaration*/ $$ = NULL;}
type_decl_list : type_definition type_decl_list {/*type declaration list*/ $$ = A_NametyList($1, $2);}
| type_definition {/*last type definition, tail points to NULL*/$$ = A_NametyList($1, NULL);}
+ | error_stmt type_decl_list{/*run into error*/ $$ = $2;}
+ | error_stmt {$$ = NULL;}
type_definition : id EQUAL type_decl SEMI {/*type declaration*/$$ =A_Namety($1, $3);}
type_decl : simple_type_decl {/*simple type*/ $$ = $1;}
| array_type_decl {/*array type*/ $$ = $1;}
@@ -124,7 +128,7 @@ simple_type_decl : sys_type {/*system defined type*/ $$ = A_NameTy(EM_tokPos
| MINUS const_value DOTDOT const_value {/*subrange type*/ A_RangeTy(EM_tokPos, A_OpExp(EM_tokPos, A_minusOp, A_IntExp(EM_tokPos, 0), $2), $4);}
| MINUS const_value DOTDOT MINUS const_value {/*subrange type*/ A_RangeTy(EM_tokPos, A_OpExp(EM_tokPos, A_minusOp, A_IntExp(EM_tokPos, 0), $2), A_OpExp(EM_tokPos, A_minusOp, A_IntExp(EM_tokPos, 0), $5));}
| id DOTDOT id {/*subrange type*/ A_RangeTy(EM_tokPos, A_VarExp(EM_tokPos, A_SimpleVar(EM_tokPos, $1)), A_VarExp(EM_tokPos, A_SimpleVar(EM_tokPos, $3)));}
-array_type_decl : ARRAY LB simple_type_decl RB OF type_decl {/*array type, simple_type_dec is range of array, type_dec is actual type of array element*/ $$ = A_ArrayTy(EM_tokPos, $3, $6->u.name);}
+array_type_decl : ARRAY LB simple_type_decl RB OF type_decl {/*array type, simple_type_dec is range of array, type_dec is actual type of array element*/ $$ = A_ArrayTy(EM_tokPos, $3, $6);}
record_type_decl : RECORD field_decl_list END {/*record type*/ $$ = A_RecordTy(EM_tokPos, $2);}
field_decl_list : field_decl field_decl_list {/*link parts of fieldlists*/ $$ = A_linkFieldList($1, $2); }
@@ -138,6 +142,8 @@ var_part : VAR var_decl_list {/*variable declaration part*/ $$ = $2;}
| {/*no variable declaration*/ $$ = NULL;}
var_decl_list : var_decl var_decl_list {/*variable declaration list*/ $$ = A_linkDecList($1, $2);}
| var_decl {$$ = $1;}
+ | error_stmt var_decl_list {$$ = $2;}
+ | error_stmt {$$ = NULL;}
var_decl : name_list COLON type_decl SEMI {/*change name_list to variable declaration list*/ $$ = A_setDecListType(A_unDecList($1), $3);}
@@ -160,11 +166,11 @@ var_para_list : VAR name_list {$$ = $2;}
val_para_list : name_list {$$ = $1;}
-routine_body : compound_stmt {/*set routine body as A_exp*/ $$ = $1;}
+routine_body : compound_stmt {/*set routine body as A_exp*/ $$ = $1;}
compound_stmt : BEGIN_T stmt_list END { $$ = A_SeqExp(EM_tokPos, $2);}
stmt_list : stmt SEMI stmt_list { /*statement in routine body*/$$ = A_ExpList($1, $3);}
| {$$ = NULL;}
- | stat {$$ = NULL;}
+ | error_stmt stmt_list {$$ = $2;}
stmt : INTEGER COLON non_label_stmt {$$ = $3;}
| non_label_stmt { $$ = $1;}
non_label_stmt : assign_stmt { $$ = $1;}
@@ -211,13 +217,13 @@ goto_stmt : GOTO INTEGER {/*goto statement*/ $$ = A_GotoExp(EM_tokPos, A_IntExp
expression_list : expression COMMA expression_list { $$ = A_ExpList($1, $3);}
| expression {$$ = A_ExpList($1, NULL);}
-expression : expression GE expr {/*greater equal expression*/ $$ = A_OpExp(EM_tokPos, A_geOp, $1, $3);}
- | expression GT expr {/*greater than expression*/ $$ = A_OpExp(EM_tokPos, A_gtOp, $1, $3);}
- | expression LE expr {/*less equal expression*/ $$ = A_OpExp(EM_tokPos, A_leOp, $1, $3); }
- | expression LT expr {/*less than expression*/ $$ = A_OpExp(EM_tokPos, A_ltOp, $1, $3);}
- | expression EQUAL expr {/*equal expression*/ $$ = A_OpExp(EM_tokPos, A_eqOp, $1, $3);}
- | expression UNEQUAL expr {/*unequal expression*/ $$ = A_OpExp(EM_tokPos, A_neqOp, $1, $3);}
- | expr{ $$ = $1;}
+ expression : expression GE expr {/*greater equal expression*/ $$ = A_OpExp(EM_tokPos, A_geOp, $1, $3);}
+ | expression GT expr {/*greater than expression*/ $$ = A_OpExp(EM_tokPos, A_gtOp, $1, $3);}
+ | expression LE expr {/*less equal expression*/ $$ = A_OpExp(EM_tokPos, A_leOp, $1, $3); }
+ | expression LT expr {/*less than expression*/ $$ = A_OpExp(EM_tokPos, A_ltOp, $1, $3);}
+ | expression EQUAL expr {/*equal expression*/ $$ = A_OpExp(EM_tokPos, A_eqOp, $1, $3);}
+ | expression UNEQUAL expr {/*unequal expression*/ $$ = A_OpExp(EM_tokPos, A_neqOp, $1, $3);}
+ | expr{ $$ = $1;}
expr : expr PLUS term {$$ = A_OpExp(EM_tokPos, A_plusOp, $1, $3);}
| expr MINUS term {$$ = A_OpExp(EM_tokPos, A_minusOp, $1, $3);}
@@ -248,7 +254,7 @@ sys_funct: SYS_FUNCT {$$ = S_Symbol($1);}
sys_proc: SYS_PROC {$$ = S_Symbol($1);}
sys_type: SYS_TYPE {$$ = S_Symbol($1);}
-stat: error SEMI {/*jump to next semi after error */}
+error_stmt: error SEMI {/*jump to next semi after error */}
%%
int yyerror(char* msg) {
@@ -271,7 +277,7 @@ A_fieldList A_linkFieldList(A_fieldList front, A_fieldList tail) {
A_fieldList A_setFieldListType(A_fieldList fieldList, A_ty ty) {
A_fieldList front = fieldList;
for (;fieldList;fieldList = fieldList->tail) {
- fieldList->head->typ = ty->u.name;
+ fieldList->head->typ = ty;
}
return front;
@@ -290,7 +296,7 @@ A_decList A_linkDecList(A_decList front, A_decList tail) {
A_decList A_setDecListType(A_decList decList, A_ty ty) {
A_decList front = decList;
for (;decList;decList = decList->tail) {
- decList->head->u.var.typ = ty->u.name;
+ decList->head->u.var.typ = ty;
}
return front;
diff --git a/src/absyn.c b/CompilerPascal/absyn.c
similarity index 97%
rename from src/absyn.c
rename to CompilerPascal/absyn.c
index 1ba4208..c4b2b55 100644
--- a/src/absyn.c
+++ b/CompilerPascal/absyn.c
@@ -245,7 +245,7 @@ A_dec A_ConstDec(A_pos pos, S_symbol constt, A_exp init) {
return p;
}
-A_dec A_VarDec(A_pos pos, S_symbol var, S_symbol typ, A_exp init) {
+A_dec A_VarDec(A_pos pos, S_symbol var, A_ty typ, A_exp init) {
A_dec p = checked_malloc(sizeof(*p));
p->kind=A_varDec;
p->pos=pos;
@@ -280,7 +280,7 @@ A_ty A_RecordTy(A_pos pos, A_fieldList record) {
return p;
}
-A_ty A_ArrayTy(A_pos pos, A_ty range, S_symbol element) {
+A_ty A_ArrayTy(A_pos pos, A_ty range, A_ty element) {
A_ty p = checked_malloc(sizeof(*p));
p->kind=A_arrayTy;
p->pos=pos;
@@ -306,7 +306,7 @@ A_ty A_EnumType(A_pos pos, A_fieldList valueList) {
return p;
}
-A_field A_Field(A_pos pos, S_symbol name, S_symbol typ) {
+A_field A_Field(A_pos pos, S_symbol name, A_ty typ) {
A_field p = checked_malloc(sizeof(*p));
p->pos=pos;
p->name=name;
diff --git a/src/absyn.h b/CompilerPascal/absyn.h
similarity index 88%
rename from src/absyn.h
rename to CompilerPascal/absyn.h
index 71a8435..fd1100f 100644
--- a/src/absyn.h
+++ b/CompilerPascal/absyn.h
@@ -30,7 +30,7 @@ typedef struct A_nametyList_ *A_nametyList;
typedef struct A_efield_ *A_efield;
typedef struct A_efieldList_ *A_efieldList;
-typedef enum {A_plusOp, A_minusOp, A_timesOp, A_divideOp, A_realDivideOp,
+typedef enum {A_plusOp, A_minusOp, A_timesOp, A_realDivideOp,A_divideOp,
A_modOp, A_eqOp, A_neqOp, A_ltOp, A_leOp, A_gtOp, A_geOp} A_oper;
struct A_var_
@@ -42,12 +42,14 @@ struct A_var_
struct {A_var var;
A_exp exp;} subscript;
} u;
- };
+};
struct A_exp_
- {enum {A_varExp, A_nilExp, A_intExp, A_realExp, A_charExp, A_boolExp, A_stringExp, A_callExp,
+ {enum {A_varExp, A_nilExp, A_intExp, A_realExp,
+ A_charExp, A_boolExp, A_stringExp, A_callExp,
A_opExp, A_recordExp, A_seqExp, A_assignExp, A_ifExp,
- A_whileExp, A_repeatExp, A_forExp, A_caseExp, A_caseValExp, A_gotoExp, A_breakExp, A_letExp, A_arrayExp} kind;
+ A_whileExp, A_repeatExp, A_forExp, A_caseExp, A_caseValExp,
+ A_gotoExp, A_breakExp, A_letExp, A_arrayExp} kind;
A_pos pos;
union {
A_var var;
@@ -73,32 +75,32 @@ struct A_exp_
struct {A_decList decs; A_exp body;} let;
struct {S_symbol typ; A_exp size, init;} array;
} u;
- };
+};
struct A_dec_
{enum {A_functionDec, A_constDec, A_varDec, A_typeDec} kind;
A_pos pos;
union {A_fundecList function;
/* escape may change after the initial declaration */
- struct {S_symbol var; S_symbol typ; A_exp init; bool escape;} var;
+ struct {S_symbol var; A_ty typ; A_exp init; bool escape;} var;
struct {S_symbol constt; A_exp init; bool escape;} constt;
A_nametyList type;
} u;
};
-
+//еļA_nameTy
struct A_ty_ {enum {A_nameTy, A_recordTy, A_arrayTy, A_rangeTy, A_enumType} kind;
A_pos pos;
union {S_symbol name;
- A_fieldList record;
- struct {struct A_ty_* range; S_symbol element;} arrayy;
+ A_fieldList record;
+ struct {A_ty range; A_ty element;} arrayy;
struct {A_exp lo, hi;} rangee;
A_fieldList enumm;
} u;
};
/* Linked lists and nodes of lists */
-
-struct A_field_ {S_symbol name, typ; A_pos pos; bool escape;};
+//nameΪtypΪñ
+struct A_field_ {S_symbol name; A_ty typ; A_pos pos; bool escape;};
struct A_fieldList_ {A_field head; A_fieldList tail;};
struct A_expList_ {A_exp head; A_expList tail;};
struct A_fundec_ {A_pos pos;
@@ -144,18 +146,18 @@ A_exp A_LetExp(A_pos pos, A_decList decs, A_exp body);
A_expList A_ExpList(A_exp head, A_expList tail);
A_dec A_ConstDec(A_pos pos, S_symbol constt, A_exp init);
-A_dec A_VarDec(A_pos pos, S_symbol var, S_symbol typ, A_exp init);
+A_dec A_VarDec(A_pos pos, S_symbol var, A_ty typ, A_exp init);
A_dec A_TypeDec(A_pos pos, A_nametyList type);
A_dec A_FunctionDec(A_pos pos, A_fundecList function);
A_decList A_DecList(A_dec head, A_decList tail);
A_ty A_NameTy(A_pos pos, S_symbol name);
A_ty A_RecordTy(A_pos pos, A_fieldList record);
-A_ty A_ArrayTy(A_pos pos, A_ty range, S_symbol element);
+A_ty A_ArrayTy(A_pos pos, A_ty range, A_ty element);
A_ty A_RangeTy(A_pos pos, A_exp lo, A_exp hi);
A_ty A_EnumType(A_pos pos, A_fieldList valueList);
-A_field A_Field(A_pos pos, S_symbol name, S_symbol typ);
+A_field A_Field(A_pos pos, S_symbol name, A_ty typ);
A_fieldList A_FieldList(A_field head, A_fieldList tail);
A_fundec A_Fundec(A_pos pos, S_symbol name, A_fieldList params, S_symbol result,
diff --git a/CompilerPascal/assem.c b/CompilerPascal/assem.c
new file mode 100644
index 0000000..60e088b
--- /dev/null
+++ b/CompilerPascal/assem.c
@@ -0,0 +1,157 @@
+/*
+ * mipscodegen.c - Functions to translate to Assem-instructions for
+ * the Jouette assembly language using Maximal Munch.
+ */
+
+#include
+#include /* for atoi */
+#include /* for strcpy */
+#include "util.h"
+#include "symbol.h"
+#include "absyn.h"
+#include "temp.h"
+#include "tree.h"
+#include "assem.h"
+#include "frame.h"
+#include "errormsg.h"
+
+AS_targets AS_Targets(Temp_labelList labels) {
+ AS_targets p = checked_malloc (sizeof *p);
+ p->labels=labels;
+ return p;
+}
+
+AS_instr AS_Oper(string a, Temp_tempList d, Temp_tempList s, AS_targets j) {
+ AS_instr p = (AS_instr) checked_malloc (sizeof *p);
+ p->kind = I_OPER;
+ p->u.OPER.assem=a;
+ p->u.OPER.dst=d;
+ p->u.OPER.src=s;
+ p->u.OPER.jumps=j;
+ return p;
+}
+
+AS_instr AS_Label(string a, Temp_label label) {
+ AS_instr p = (AS_instr) checked_malloc (sizeof *p);
+ p->kind = I_LABEL;
+ p->u.LABEL.assem=a;
+ p->u.LABEL.label=label;
+ return p;
+}
+
+AS_instr AS_Move(string a, Temp_tempList d, Temp_tempList s) {
+ AS_instr p = (AS_instr) checked_malloc (sizeof *p);
+ p->kind = I_MOVE;
+ p->u.MOVE.assem=a;
+ p->u.MOVE.dst=d;
+ p->u.MOVE.src=s;
+ return p;
+}
+
+AS_instrList AS_InstrList(AS_instr head, AS_instrList tail)
+{AS_instrList p = (AS_instrList) checked_malloc (sizeof *p);
+ p->head=head; p->tail=tail;
+ return p;
+}
+
+/* put list b at the end of list a */
+AS_instrList AS_splice(AS_instrList a, AS_instrList b) {
+ AS_instrList p;
+ if (a==NULL) return b;
+ for(p=a; p->tail!=NULL; p=p->tail) ;
+ p->tail=b;
+ return a;
+}
+
+static Temp_temp nthTemp(Temp_tempList list, int i) {
+ assert(list);
+ if (i==0) return list->head;
+ else return nthTemp(list->tail,i-1);
+}
+
+static Temp_label nthLabel(Temp_labelList list, int i) {
+ assert(list);
+ if (i==0) return list->head;
+ else return nthLabel(list->tail,i-1);
+}
+
+
+/* first param is string created by this function by reading 'assem' string
+ * and replacing `d `s and `j stuff.
+ * Last param is function to use to determine what to do with each temp.
+ */
+static void format(char *result, string assem,
+ Temp_tempList dst, Temp_tempList src,
+ AS_targets jumps, Temp_map m)
+{
+ char *p;
+ int i = 0; /* offset to result string */
+ for(p = assem; p && *p != '\0'; p++)
+ if (*p == '`')
+ switch(*(++p)) {
+ case 's': {int n = atoi(++p);
+ string s = Temp_look(m, nthTemp(src,n));
+ strcpy(result+i, s);
+ i += strlen(s);
+ }
+ break;
+ case 'd': {int n = atoi(++p);
+ string s = Temp_look(m, nthTemp(dst,n));
+ if (!s) {
+ result[i] = '\0';
+ return;
+ }
+ strcpy(result+i, s);
+ i += strlen(s);
+ }
+ break;
+ case 'j': assert(jumps);
+ {int n = atoi(++p);
+ string s = Temp_labelstring(nthLabel(jumps->labels,n));
+ strcpy(result+i, s);
+ i += strlen(s);
+ }
+ break;
+ case '`': result[i] = '`'; i++;
+ break;
+ default: assert(0);
+ }
+ else {result[i] = *p; i++; }
+ result[i] = '\0';
+}
+
+
+void AS_print(FILE *out, AS_instr i, Temp_map m)
+{
+ char r[200]; /* result */
+ switch (i->kind) {
+ case I_OPER:
+ format(r, i->u.OPER.assem, i->u.OPER.dst, i->u.OPER.src, i->u.OPER.jumps, m);
+ fprintf(out, "%s", r);
+ break;
+ case I_LABEL:
+ format(r, i->u.LABEL.assem, NULL, NULL, NULL, m);
+ fprintf(out, "%s", r);
+ /* i->u.LABEL->label); */
+ break;
+ case I_MOVE:
+ format(r, i->u.MOVE.assem, i->u.MOVE.dst, i->u.MOVE.src, NULL, m);
+ fprintf(out, "%s", r);
+ break;
+ }
+}
+
+/* c should be COL_color; temporarily it is not */
+void AS_printInstrList (FILE *out, AS_instrList iList, Temp_map m)
+{
+ for (; iList; iList=iList->tail) {
+ AS_print(out, iList->head, m);
+ }
+ fprintf(out, "\n");
+}
+
+AS_proc AS_Proc(string p, AS_instrList b, string e)
+{AS_proc proc = checked_malloc(sizeof(*proc));
+ proc->prolog=p; proc->body=b; proc->epilog=e;
+ return proc;
+}
diff --git a/CompilerPascal/assem.h b/CompilerPascal/assem.h
new file mode 100644
index 0000000..94270e8
--- /dev/null
+++ b/CompilerPascal/assem.h
@@ -0,0 +1,45 @@
+#ifndef ASSEM_H_
+#define ASSEM_H_
+/*
+ * assem.h - Function prototypes to translate to Assem-instructions
+ * using Maximal Munch.
+ */
+#include "temp.h"
+#include "util.h"
+
+
+typedef struct {Temp_labelList labels;} *AS_targets;
+AS_targets AS_Targets(Temp_labelList labels);
+
+typedef struct AS_instr_ *AS_instr;
+struct AS_instr_ { enum {I_OPER, I_LABEL, I_MOVE} kind;
+ union {struct {string assem; Temp_tempList dst, src;
+ AS_targets jumps;} OPER;
+ struct {string assem; Temp_label label;} LABEL;
+ struct {string assem; Temp_tempList dst, src;} MOVE;
+ } u;
+ };
+
+AS_instr AS_Oper(string a, Temp_tempList d, Temp_tempList s, AS_targets j);
+AS_instr AS_Label(string a, Temp_label label);
+AS_instr AS_Move(string a, Temp_tempList d, Temp_tempList s);
+
+void AS_print(FILE *out, AS_instr i, Temp_map m);
+
+typedef struct AS_instrList_ *AS_instrList;
+struct AS_instrList_ { AS_instr head; AS_instrList tail;};
+AS_instrList AS_InstrList(AS_instr head, AS_instrList tail);
+
+AS_instrList AS_splice(AS_instrList a, AS_instrList b);
+void AS_printInstrList (FILE *out, AS_instrList iList, Temp_map m);
+
+typedef struct AS_proc_ *AS_proc;
+struct AS_proc_ {
+ string prolog;
+ AS_instrList body;
+ string epilog;
+};
+
+AS_proc AS_Proc(string p, AS_instrList b, string e);
+
+#endif
diff --git a/CompilerPascal/canon.c b/CompilerPascal/canon.c
new file mode 100644
index 0000000..5dab950
--- /dev/null
+++ b/CompilerPascal/canon.c
@@ -0,0 +1,308 @@
+/*
+ * canon.c - Functions to convert the IR trees into basic blocks and traces.
+ *
+ */
+#include
+#include "util.h"
+#include "symbol.h"
+#include "temp.h"
+#include "tree.h"
+#include "canon.h"
+
+typedef struct expRefList_ *expRefList;
+struct expRefList_ {T_exp *head; expRefList tail;};
+
+/* local function prototypes */
+static T_stm do_stm(T_stm stm);
+static struct stmExp do_exp(T_exp exp);
+static C_stmListList mkBlocks(T_stmList stms, Temp_label done);
+static T_stmList getNext(void);
+
+static expRefList ExpRefList(T_exp *head, expRefList tail)
+{expRefList p = (expRefList) checked_malloc (sizeof *p);
+ p->head=head; p->tail=tail;
+ return p;
+}
+
+static bool isNop(T_stm x)
+{ return x->kind == T_EXP && x->u.EXP->kind == T_CONST;
+ }
+
+static T_stm seq(T_stm x, T_stm y)
+{
+ if (isNop(x)) return y;
+ if (isNop(y)) return x;
+ return T_Seq(x,y);
+}
+
+static bool commute(T_stm x, T_exp y)
+{
+ if (isNop(x)) return TRUE;
+ if (y->kind == T_NAME || y->kind == T_CONST) return TRUE;
+ return FALSE;
+}
+
+struct stmExp {T_stm s; T_exp e;};
+
+static T_stm reorder(expRefList rlist) {
+ if (!rlist) return T_Exp(T_Const(0)); /* nop */
+ else if ((*rlist->head)->kind==T_CALL) {
+ Temp_temp t = Temp_newtemp();
+ *rlist->head = T_Eseq(T_Move(T_Temp(t),*rlist->head),T_Temp(t));
+ return reorder(rlist);
+ }
+ else {
+ struct stmExp hd = do_exp(*rlist->head);
+ T_stm s = reorder(rlist->tail);
+ if (commute(s,hd.e)) {
+ *rlist->head=hd.e;
+ return seq(hd.s,s);
+ } else {
+ Temp_temp t = Temp_newtemp();
+ *rlist->head=T_Temp(t);
+ return seq(hd.s, seq(T_Move(T_Temp(t),hd.e), s));
+ }
+ }
+ }
+
+static expRefList get_call_rlist(T_exp exp)
+{expRefList rlist, curr;
+ T_expList args = exp->u.CALL.args;
+ curr = rlist = ExpRefList(&exp->u.CALL.fun, NULL);
+ for (;args; args=args->tail) {
+ curr = curr->tail = ExpRefList(&args->head, NULL);
+ }
+ return rlist;
+}
+
+static struct stmExp StmExp(T_stm stm, T_exp exp) {
+ struct stmExp x;
+ x.s = stm;
+ x.e = exp;
+ return x;
+}
+
+static struct stmExp do_exp(T_exp exp)
+{
+ switch(exp->kind) {
+ case T_BINOP:
+ return StmExp(reorder(ExpRefList(&exp->u.BINOP.left,
+ ExpRefList(&exp->u.BINOP.right, NULL))),
+ exp);
+ case T_MEM:
+ return StmExp(reorder(ExpRefList(&exp->u.MEM, NULL)), exp);
+ case T_ESEQ:
+ {struct stmExp x = do_exp(exp->u.ESEQ.exp);
+ return StmExp(seq(do_stm(exp->u.ESEQ.stm), x.s), x.e);
+ }
+ case T_CALL:
+ return StmExp(reorder(get_call_rlist(exp)), exp);
+ default:
+ return StmExp(reorder(NULL), exp);
+ }
+}
+
+/* processes stm so that it contains no ESEQ nodes */
+static T_stm do_stm(T_stm stm)
+{
+ switch (stm->kind) {
+ case T_SEQ:
+ return seq(do_stm(stm->u.SEQ.left), do_stm(stm->u.SEQ.right));
+ case T_JUMP:
+ return seq(reorder(ExpRefList(&stm->u.JUMP.exp, NULL)), stm);
+ case T_CJUMP:
+ return seq(reorder(ExpRefList(&stm->u.CJUMP.left,
+ ExpRefList(&stm->u.CJUMP.right,NULL))), stm);
+ case T_MOVE:
+ if (stm->u.MOVE.dst->kind == T_TEMP && stm->u.MOVE.src->kind == T_CALL)
+ return seq(reorder(get_call_rlist(stm->u.MOVE.src)), stm);
+ else if (stm->u.MOVE.dst->kind == T_TEMP)
+ return seq(reorder(ExpRefList(&stm->u.MOVE.src, NULL)), stm);
+ else if (stm->u.MOVE.dst->kind == T_MEM)
+ return seq(reorder(ExpRefList(&stm->u.MOVE.dst->u.MEM,
+ ExpRefList(&stm->u.MOVE.src, NULL))), stm);
+ else if (stm->u.MOVE.dst->kind == T_ESEQ) {
+ T_stm s = stm->u.MOVE.dst->u.ESEQ.stm;
+ stm->u.MOVE.dst = stm->u.MOVE.dst->u.ESEQ.exp;
+ return do_stm(T_Seq(s, stm));
+ }
+ assert(0); /* dst should be temp or mem only */
+ case T_EXP:
+ if (stm->u.EXP->kind == T_CALL)
+ return seq(reorder(get_call_rlist(stm->u.EXP)), stm);
+ else return seq(reorder(ExpRefList(&stm->u.EXP, NULL)), stm);
+ default:
+ return stm;
+ }
+}
+
+/* linear gets rid of the top-level SEQ's, producing a list */
+static T_stmList linear(T_stm stm, T_stmList right)
+{
+ if (stm->kind == T_SEQ)
+ return linear(stm->u.SEQ.left,linear(stm->u.SEQ.right,right));
+ else return T_StmList(stm, right);
+}
+
+/* From an arbitrary Tree statement, produce a list of cleaned trees
+ satisfying the following properties:
+ 1. No SEQ's or ESEQ's
+ 2. The parent of every CALL is an EXP(..) or a MOVE(TEMP t,..) */
+T_stmList C_linearize(T_stm stm)
+{
+ return linear(do_stm(stm), NULL);
+}
+
+static C_stmListList StmListList(T_stmList head, C_stmListList tail)
+{C_stmListList p = (C_stmListList) checked_malloc (sizeof *p);
+ p->head=head; p->tail=tail;
+ return p;
+}
+
+/* Go down a list looking for end of basic block */
+static C_stmListList next(T_stmList prevstms, T_stmList stms, Temp_label done)
+{
+ if (!stms)
+ return next(prevstms,
+ T_StmList(T_Jump(T_Name(done), Temp_LabelList(done, NULL)),
+ NULL), done);
+ if (stms->head->kind == T_JUMP || stms->head->kind == T_CJUMP) {
+ C_stmListList stmLists;
+ prevstms->tail = stms;
+ stmLists = mkBlocks(stms->tail, done);
+ stms->tail = NULL;
+ return stmLists;
+ }
+ else if (stms->head->kind == T_LABEL) {
+ Temp_label lab = stms->head->u.LABEL;
+ return next(prevstms, T_StmList(T_Jump(T_Name(lab), Temp_LabelList(lab, NULL)),
+ stms), done);
+ }
+ else {
+ prevstms->tail = stms;
+ return next(stms, stms->tail, done);
+ }
+}
+
+/* Create the beginning of a basic block */
+static C_stmListList mkBlocks(T_stmList stms, Temp_label done)
+{
+ if (!stms) {
+ return NULL;
+ }
+ if (stms->head->kind != T_LABEL) {
+ return mkBlocks(T_StmList(T_Label(Temp_newlabel()), stms), done);
+ }
+ /* else there already is a label */
+ return StmListList(stms, next(stms, stms->tail, done));
+}
+
+ /* basicBlocks : Tree.stm list -> (Tree.stm list list * Tree.label)
+ From a list of cleaned trees, produce a list of
+ basic blocks satisfying the following properties:
+ 1. and 2. as above;
+ 3. Every block begins with a LABEL;
+ 4. A LABEL appears only at the beginning of a block;
+ 5. Any JUMP or CJUMP is the last stm in a block;
+ 6. Every block ends with a JUMP or CJUMP;
+ Also produce the "label" to which control will be passed
+ upon exit.
+ */
+struct C_block C_basicBlocks(T_stmList stmList)
+{
+ struct C_block b;
+ b.label = Temp_newlabel();
+ b.stmLists = mkBlocks(stmList, b.label);
+
+ return b;
+}
+
+static S_table block_env;
+static struct C_block global_block;
+
+static T_stmList getLast(T_stmList list)
+{
+ T_stmList last = list;
+ while (last->tail->tail) last = last->tail;
+ return last;
+}
+
+static void trace(T_stmList list)
+{
+ T_stmList last = getLast(list);
+ T_stm lab = list->head;
+ T_stm s = last->tail->head;
+ S_enter(block_env, lab->u.LABEL, NULL);
+ if (s->kind == T_JUMP) {
+ T_stmList target = (T_stmList) S_look(block_env, s->u.JUMP.jumps->head);
+ if (!s->u.JUMP.jumps->tail && target) {
+ last->tail = target; /* merge the 2 lists removing JUMP stm */
+ trace(target);
+ }
+ else last->tail->tail = getNext(); /* merge and keep JUMP stm */
+ }
+ /* we want false label to follow CJUMP */
+ else if (s->kind == T_CJUMP) {
+ T_stmList true = (T_stmList) S_look(block_env, s->u.CJUMP.true);
+ T_stmList false = (T_stmList) S_look(block_env, s->u.CJUMP.false);
+ if (false) {
+ last->tail->tail = false;
+ trace(false);
+ }
+ else if (true) { /* convert so that existing label is a false label */
+ last->tail->head = T_Cjump(T_notRel(s->u.CJUMP.op), s->u.CJUMP.left,
+ s->u.CJUMP.right, s->u.CJUMP.false,
+ s->u.CJUMP.true);
+ last->tail->tail = true;
+ trace(true);
+ }
+ else {
+ Temp_label false = Temp_newlabel();
+ last->tail->head = T_Cjump(s->u.CJUMP.op, s->u.CJUMP.left,
+ s->u.CJUMP.right, s->u.CJUMP.true, false);
+ last->tail->tail = T_StmList(T_Label(false), getNext());
+ }
+ }
+ else assert(0);
+}
+
+/* get the next block from the list of stmLists, using only those that have
+ * not been traced yet */
+static T_stmList getNext()
+{
+ if (!global_block.stmLists)
+ return T_StmList(T_Label(global_block.label), NULL);
+ else {
+ T_stmList s = global_block.stmLists->head;
+ if (S_look(block_env, s->head->u.LABEL)) {/* label exists in the table */
+ trace(s);
+ return s;
+ }
+ else {
+ global_block.stmLists = global_block.stmLists->tail;
+ return getNext();
+ }
+ }
+}
+ /* traceSchedule : Tree.stm list list * Tree.label -> Tree.stm list
+ From a list of basic blocks satisfying properties 1-6,
+ along with an "exit" label,
+ produce a list of stms such that:
+ 1. and 2. as above;
+ 7. Every CJUMP(_,t,f) is immediately followed by LABEL f.
+ The blocks are reordered to satisfy property 7; also
+ in this reordering as many JUMP(T.NAME(lab)) statements
+ as possible are eliminated by falling through into T.LABEL(lab).
+ */
+T_stmList C_traceSchedule(struct C_block b)
+{ C_stmListList sList;
+ block_env = S_empty();
+ global_block = b;
+
+ for (sList=global_block.stmLists; sList; sList=sList->tail) {
+ S_enter(block_env, sList->head->head->u.LABEL, sList->head);
+ }
+
+ return getNext();
+}
+
diff --git a/CompilerPascal/canon.h b/CompilerPascal/canon.h
new file mode 100644
index 0000000..4199241
--- /dev/null
+++ b/CompilerPascal/canon.h
@@ -0,0 +1,46 @@
+/*
+ * canon.h - Definitions for canon.c which converts the IR trees into
+ * basic blocks and traces.
+ *
+ */
+
+#ifndef CANON_H_
+#define CANON_H_
+
+#include "tree.h"
+typedef struct C_stmListList_ *C_stmListList;
+struct C_block { C_stmListList stmLists; Temp_label label;};
+struct C_stmListList_ { T_stmList head; C_stmListList tail;};
+
+T_stmList C_linearize(T_stm stm);
+ /* From an arbitrary Tree statement, produce a list of cleaned trees
+ satisfying the following properties:
+ 1. No SEQ's or ESEQ's
+ 2. The parent of every CALL is an EXP(..) or a MOVE(TEMP t,..)
+ */
+
+struct C_block C_basicBlocks(T_stmList stmList);
+ /* basicBlocks : Tree.stm list -> (Tree.stm list list * Tree.label)
+ From a list of cleaned trees, produce a list of
+ basic blocks satisfying the following properties:
+ 1. and 2. as above;
+ 3. Every block begins with a LABEL;
+ 4. A LABEL appears only at the beginning of a block;
+ 5. Any JUMP or CJUMP is the last stm in a block;
+ 6. Every block ends with a JUMP or CJUMP;
+ Also produce the "label" to which control will be passed
+ upon exit.
+ */
+
+T_stmList C_traceSchedule(struct C_block b);
+ /* traceSchedule : Tree.stm list list * Tree.label -> Tree.stm list
+ From a list of basic blocks satisfying properties 1-6,
+ along with an "exit" label,
+ produce a list of stms such that:
+ 1. and 2. as above;
+ 7. Every CJUMP(_,t,f) is immediately followed by LABEL f.
+ The blocks are reordered to satisfy property 7; also
+ in this reordering as many JUMP(T.NAME(lab)) statements
+ as possible are eliminated by falling through into T.LABEL(lab).
+ */
+#endif
diff --git a/CompilerPascal/codegen.c b/CompilerPascal/codegen.c
new file mode 100644
index 0000000..73972fb
--- /dev/null
+++ b/CompilerPascal/codegen.c
@@ -0,0 +1,228 @@
+#include "codegen.h"
+#include
+
+static AS_instrList iList = NULL, last = NULL;
+extern Temp_map F_tempMap;
+
+
+static void emit(AS_instr instr) {
+ if (last != NULL) {
+ last = last->tail = AS_InstrList(instr, NULL);
+ } else {
+ last = iList = AS_InstrList(instr, NULL);
+ }
+}
+
+AS_instrList F_codegen(F_frame frame, T_stmList stmList) {
+ AS_instrList ret = NULL;
+ T_stmList sl = stmList;
+ for(;sl;sl = sl->tail)
+ munchStm(sl->head);
+ ret = iList;
+ iList = last = NULL;
+ return ret;
+}
+
+static Temp_temp munchExp(T_exp e) {
+ char buffer[80];
+ Temp_temp ret = Temp_newtemp();
+ switch(e->kind) {
+ case T_TEMP: {
+ ret = e->u.TEMP;
+ break;
+ }
+ case T_ESEQ: {
+ munchStm(e->u.ESEQ.stm);
+ ret = munchExp(e->u.ESEQ.exp);
+ break;
+ }
+ case T_NAME: {
+ Temp_enter(F_TEMPMAP, ret, Temp_labelstring(e->u.NAME));
+ break;
+ }
+ case T_CONST: {
+ sprintf(buffer, "%d", e->u.CONST);
+ emit(AS_Move(String(buffer), Temp_TempList(ret, NULL), NULL));
+ break;
+ }
+ case T_CALL: {
+ ret = munchExp(e->u.CALL.fun);
+ emit(AS_Oper(String("call `s0"), NULL, Temp_TempList(ret, munchArgs(0, e->u.CALL.args)), NULL));
+ break;
+ }
+ case T_BINOP: {
+ char *oper=NULL;
+ char *sign=NULL;
+ T_exp left=e->u.BINOP.left;
+ T_exp right=e->u.BINOP.right;
+ if(e->u.BINOP.op==T_plus)
+ {
+ oper="add";
+ sign="+";
+ }
+ else if(e->u.BINOP.op==T_minus)
+ {
+ oper="sub";
+ sign="-";
+ }
+ else if(e->u.BINOP.op==T_mul)
+ {
+ oper="mul";
+ sign="*";
+ }
+ else if(e->u.BINOP.op==T_div)
+ {
+ oper="div";
+ sign="/";
+ }
+ else
+ {
+ printf("Invalid operator\n");
+ exit(15);
+ }
+ if (left->kind == T_CONST)
+ { /* BINOP(op, CONST, e) */
+ sprintf(buffer, "%s $%x, `d0", oper, left->u.CONST);
+ emit(AS_Oper(String(buffer), Temp_TempList(ret = munchExp(right), NULL), NULL, NULL));
+ }
+ else if (right->kind == T_CONST)
+ { /* BINOP(op, e, CONST) */
+ sprintf(buffer,"%s $%x, `d0", oper, right->u.CONST);
+ emit(AS_Oper(String(buffer), Temp_TempList(ret = munchExp(left), NULL), NULL, NULL));
+ }
+ else
+ { /* BINOP(op, e, e) */
+ sprintf(buffer,"%s `s0, `d0",oper);
+ emit(AS_Oper(String(buffer), Temp_TempList(ret = munchExp(right), NULL), Temp_TempList(munchExp(left), NULL), NULL));
+ }
+ break;
+ }
+ case T_MEM: {
+ T_exp mem = e->u.MEM.exp;
+ if (mem->kind == T_BINOP && mem->u.BINOP.op == T_plus)
+ {
+ T_exp left=mem->u.BINOP.left;
+ T_exp right=mem->u.BINOP.right;
+ if (left->kind == T_CONST)
+ { /* MEM(BINOP(+, CONST, e)) */
+ sprintf(buffer,"mov %d(`s0), `d0",left->u.CONST);
+ emit(AS_Move(String(buffer), Temp_TempList(ret, NULL), Temp_TempList(munchExp(right), NULL)));
+ }
+ else if (right->kind == T_CONST)
+ { /*MEM(BINOP(+, e, CONST)) */
+ sprintf(buffer,"mov %d(`s0), `d0",right->u.CONST);
+ emit(AS_Move(String(buffer), Temp_TempList(ret, NULL), Temp_TempList(munchExp(left), NULL)));
+ }
+ else
+ {
+ printf("MEM(BINOP) error\n");
+ exit(16);
+ }
+ }
+ break;
+ }
+ default: {
+ printf("T_exp error!\n");
+ exit(14);
+ }
+
+ }
+
+}
+
+static void munchStm(T_stm s) {
+ if (!s)
+ return;
+ char buffer[80];
+
+ switch(s->kind) {
+ case T_EXP: {
+ munchExp(s->u.EXP);
+ break;
+ }
+ case T_SEQ: {
+ munchStm(s->u.SEQ.left);
+ munchStm(s->u.SEQ.right);
+ break;
+ }
+ case T_MOVE: {
+ T_exp dst=s->u.MOVE.dst;
+ T_exp src=s->u.MOVE.src;
+ if(dst->kind==T_TEMP) {
+ if (src->kind == T_CONST) {
+ sprintf(buffer, "addi `d0, $0, %d", src->u.CONST);
+ emit(AS_Move(String(buffer), Temp_TempList(munchExp(dst), NULL), NULL, NULL));
+ } else {
+ emit(AS_Move(String("addi `d0, `s0, 0"), Temp_TempList(munchExp(dst), NULL), Temp_TempList(munchExp(src), NULL)));
+ }
+ }
+ else if (dst->kind = T_MEM) {
+ if(dst->u.MEM.exp->kind == T_BINOP && dst->u.MEM.exp->u.BINOP.op == T_plus)
+ {
+ if(dst->u.MEM.exp->u.BINOP.right->kind == T_CONST) /* MOVE (MEM(BINOP(+, e, CONST)), e) */
+ {
+ sprintf(buffer, "sw `s1, %d(`s0)", dst->u.MEM.exp->u.BINOP.right->u.CONST);
+ emit(AS_Move(String(buffer), NULL, Temp_TempList(munchExp(dst->u.MEM.exp->u.BINOP.left), Temp_TempList(munchExp(src), NULL))));
+ }
+ if(dst->u.MEM.exp->u.BINOP.left->kind == T_CONST) /* MOVE (MEM(BINOP(+, CONST, e)), e) */
+ {
+ sprintf(buffer, "mov `s1, %d(`s0)", dst->u.MEM.exp->u.BINOP.left->u.CONST);
+ emit(AS_Move(String(buffer), NULL, Temp_TempList(munchExp(dst->u.MEM.exp->u.BINOP.right), Temp_TempList(munchExp(src), NULL))));
+ }
+ }
+ else if(dst->u.MEM.exp->kind == T_CONST)
+ { /* MOVE(MEM(CONST), e) */
+ sprintf(buffer, "sw `s0, %d($0)", dst->u.MEM.exp->u.CONST);
+ emit(AS_Move(String(buffer), NULL, Temp_TempList(munchExp(src), NULL)));
+ }
+ else if(src->kind == T_MEM) /* MOVE(MEM(e), MEM(e)) */
+ emit(AS_Move("mov `s1, (`s0)", NULL, Temp_TempList(munchExp(dst->u.MEM.exp), Temp_TempList(munchExp(src->u.MEM.exp), NULL))));
+
+ }
+ break;
+ }
+ case T_LABEL: {
+ sprintf(buffer, "%s:", Temp_labelstring(s->u.LABEL));
+ emit(AS_Label(String(buffer), s->u.LABEL));
+ break;
+ }
+ case T_JUMP: {
+ Temp_temp exp = munchExp(s->u.JUMP.exp);
+ emit(AS_Oper(String("jump `d0"), Temp_TempList(exp, NULL), NULL, AS_Targets(s->u.JUMP.jumps)));
+ break;
+ }
+ case T_CJUMP: {
+ char * cmp;
+ Temp_temp left = munchExp(s->u.CJUMP.left);
+ Temp_temp right = munchExp(s->u.CJUMP.right);
+ emit(AS_Oper(String("cmp `s0, `s1"), NULL, Temp_TempList(left, Temp_TempList(right, NULL)), NULL));
+ if(s->u.CJUMP.op==T_eq) //==
+ cmp="beq";
+ else if(s->u.CJUMP.op==T_ne) //<>
+ cmp="bne";
+ else
+ {
+ printf("Invalid compare sign!\n");
+ exit(12);
+ }
+ sprintf(buffer, "%s `j0", cmp);
+ emit(AS_Oper(String(buffer), NULL, NULL, AS_Targets(Temp_LabelList(s->u.CJUMP.true, NULL))));
+ break;
+ }
+ default: {
+ printf("T_stm Error!\n");
+ }
+
+ }
+}
+
+static Temp_tempList munchArgs(int i, T_expList args) {
+ if (!args)
+ return NULL;
+
+ char buffer[80];
+ Temp_tempList list = munchArgs(i+1,args->tail);
+ Temp_temp regArg = munchExp(args->head);
+ emit(AS_Oper(String("push `s0"), NULL, Temp_TempList(regArg, NULL), NULL));
+ return (regArg,list);
+}
diff --git a/CompilerPascal/codegen.h b/CompilerPascal/codegen.h
new file mode 100644
index 0000000..e9c844a
--- /dev/null
+++ b/CompilerPascal/codegen.h
@@ -0,0 +1,11 @@
+#ifndef CODEGEN_H_
+#define CODEGEN_H_
+#include "assem.h"
+#include "frame.h"
+#include "tree.h"
+
+AS_instrList F_codegen(F_frame frame, T_stmList stmList);
+static Temp_temp munchExp(T_exp e);
+static void munchStm(T_stm s);
+static Temp_tempList munchArgs(int i, T_expList args);
+#endif
\ No newline at end of file
diff --git a/CompilerPascal/drawtree.c b/CompilerPascal/drawtree.c
new file mode 100644
index 0000000..a12ec1e
--- /dev/null
+++ b/CompilerPascal/drawtree.c
@@ -0,0 +1,215 @@
+#include
+#include "util.h"
+#include "symbol.h"
+#include "temp.h"
+#include "tree.h"
+#include "drawtree.h"
+
+
+/* local function prototype */
+static void dr_tree_exp(FILE *out, T_exp exp);
+
+static char bin_oper[][12] = {
+ "PLUS", "MINUS", "TIMES", "DIVIDE",
+ "AND", "OR", "LSHIFT", "RSHIFT", "ARSHIFT", "XOR"};
+
+static char rel_oper[][12] = {
+ "EQ", "NE", "LT", "GT", "LE", "GE", "ULT", "ULE", "UGT", "UGE"};
+
+// count of node
+// this will act as number of node
+static int count = 0;
+
+static void dr_stm(FILE *out, T_stm stm)
+{
+ if (!stm)
+ return;
+ switch (stm->kind) {
+ case T_SEQ: {
+ count++;
+ int n1 = count;
+ fprintf(out, "node%d->", n1);
+ dr_stm(out, stm->u.SEQ.left);
+ fprintf(out, "node%d->", n1);
+ dr_stm(out, stm->u.SEQ.right);
+ fprintf(out, "node%d[label=\"SEQ\"];\n", n1);
+ break;
+ }
+ case T_LABEL: {
+ count++;
+ int n1 = count;
+ count++;
+ int n2 = count;
+ fprintf(out, "node%d->node%d;\n", n1, n2);
+ fprintf(out, "node%d[label=\"LABEL\"];\n", n1);
+ fprintf(out, "node%d[label=\"%s\"];\n", n2, S_name(stm->u.LABEL));
+ break;
+ }
+ case T_JUMP: {
+ count++;
+ int n1 = count;
+ fprintf(out, "node%d->", n1);
+ dr_tree_exp(out, stm->u.JUMP.exp);
+ fprintf(out, "node%d[label=\"JUMP\"];\n", n1);
+ break;
+ }
+ case T_CJUMP: {
+ count++;
+ int n1 = count;
+ count++;
+ int n2 = count;
+ count++;
+ int n3 = count;
+ count++;
+ int n4 = count;
+
+ fprintf(out, "node%d->node%d;\n", n1, n2);
+ fprintf(out, "node%d->", n1);
+ dr_tree_exp(out, stm->u.CJUMP.left);
+ fprintf(out, "node%d->", n1);
+ dr_tree_exp(out, stm->u.CJUMP.right);
+ if (stm->u.CJUMP.true)
+ fprintf(out, "node%d->node%d;\n", n1, n3);
+ if(stm->u.CJUMP.false)
+ fprintf(out, "node%d->node%d;\n", n1, n4);
+ fprintf(out, "node%d[label=\"CJUMP\"];\n", n1);
+ fprintf(out, "node%d[label=\"%s\"];\n", n2, rel_oper[stm->u.CJUMP.op]);
+ fprintf(out, "node%d[label=\"%s\"];\n", n3, S_name(stm->u.CJUMP.true));
+ fprintf(out, "node%d[label=\"%s\"];\n", n4, S_name(stm->u.CJUMP.false));
+ break;
+ }
+ case T_MOVE: {
+ count++;
+ int n1 = count;
+ fprintf(out, "node%d->", n1);
+ dr_tree_exp(out, stm->u.MOVE.dst);
+ fprintf(out, "node%d->", n1);
+ dr_tree_exp(out, stm->u.MOVE.src);
+ fprintf(out, "node%d[label=\"MOVE\"];\n", n1);
+ break;
+ }
+ case T_EXP: {
+ count++;
+ int n1 = count;
+ fprintf(out, "node%d->", n1);
+ dr_tree_exp(out, stm->u.EXP);
+ fprintf(out, "node%d[label=\"EXP\"];\n", n1);
+ break;
+ }
+
+ }
+}
+
+static void dr_tree_exp(FILE *out, T_exp exp)
+{
+ if (!exp)
+ return;
+ switch (exp->kind) {
+ case T_BINOP: {
+ count++;
+ int n1 = count;
+ count++;
+ int n2 = count;
+ fprintf(out, "node%d->node%d;\n", n1, n2);
+ fprintf(out, "node%d->", n1);
+ dr_tree_exp(out,exp->u.BINOP.left);
+ fprintf(out, "node%d->", n1);
+ dr_tree_exp(out,exp->u.BINOP.right);
+ fprintf(out, "node%d[label=\"BINOP\"];\n", n1);
+ fprintf(out, "node%d[label=\"%s\"];\n", n2, bin_oper[exp->u.BINOP.op]);
+ break;
+ }
+ case T_MEM: {
+ count++;
+ int n1 = count;
+ fprintf(out, "node%d->", n1);
+ dr_tree_exp(out, exp->u.MEM.exp);
+ fprintf(out, "node%d[label=\"MEM\"];\n", n1);
+ break;
+ }
+ case T_TEMP: {
+ count++;
+ int n1 = count;
+ count++;
+ int n2 = count;
+ fprintf(out, "node%d->node%d;\n", n1, n2);
+ fprintf(out, "node%d[label=\"TEMP\"];\n", n1);
+ fprintf(out, "node%d[label=\"t%s\"];\n", n2, Temp_look(Temp_name(), exp->u.TEMP));
+ break;
+ }
+ case T_ESEQ: {
+ count++;
+ int n1 = count;
+ fprintf(out, "node%d->", n1);
+ dr_stm(out, exp->u.ESEQ.stm);
+ fprintf(out, "node%d->", n1);
+ dr_tree_exp(out, exp->u.ESEQ.exp);
+ fprintf(out, "node%d[label=\"ESEQ\"];\n", n1);
+ break;
+ }
+ case T_NAME: {
+ count++;
+ int n1 = count;
+ count++;
+ int n2 = count;
+ fprintf(out, "node%d->node%d;\n", n1, n2);
+ fprintf(out, "node%d[label=\"NAME\"];\n", n1);
+ fprintf(out, "node%d[label=\"%s\"];\n", n2, S_name(exp->u.NAME));
+ break;
+ }
+ case T_CONST: {
+ count++;
+ int n1 = count;
+ count++;
+ int n2 = count;
+ fprintf(out, "node%d->node%d;\n", n1, n2);
+ fprintf(out, "node%d[label=\"CONST\"];\n", n1);
+ fprintf(out, "node%d[label=\"%d\"];\n", n2, exp->u.CONST);
+ break;
+ }
+ case T_DOUBLE: {
+ count++;
+ int n1 = count;
+ count++;
+ int n2 = count;
+ fprintf(out, "node%d->node%d;\n", n1, n2);
+ fprintf(out, "node%d[label=\"DOUBLE\"];\n", n1);
+ fprintf(out, "node%d[label=\"%lf\"];\n", n2, exp->u.DOUBLE);
+ break;
+ }
+ case T_CHAR: {
+ count++;
+ int n1 = count;
+ count++;
+ int n2 = count;
+ fprintf(out, "node%d->node%d;\n", n1, n2);
+ fprintf(out, "node%d[label=\"CHAR\"];\n", n1);
+ fprintf(out, "node%d[label=\"%c\"];\n", n2, exp->u.CHAR);
+ break;
+ }
+ case T_CALL: {
+ count++;
+ int n1 = count;
+ T_expList args = exp->u.CALL.args;
+ fprintf(out, "node%d->", n1);
+ dr_tree_exp(out, exp->u.CALL.fun);
+ for (;args; args=args->tail) {
+ fprintf(out, "node%d->", n1);
+ dr_tree_exp(out, args->head);
+ }
+ fprintf(out, "node%d[label=\"CALL\"];\n", n1);
+ break;
+ }
+ } /* end of switch */
+}
+
+void drawStmList (FILE *out, T_stmList stmList)
+{
+ // setting of graph
+ fprintf(out, "digraph g {\n");
+ fprintf(out, "node[peripheries=2, style=filled;]\n");
+ for (; stmList; stmList=stmList->tail) {
+ dr_stm(out, stmList->head);
+ }
+ fprintf(out, "}");
+}
\ No newline at end of file
diff --git a/CompilerPascal/drawtree.h b/CompilerPascal/drawtree.h
new file mode 100644
index 0000000..72cf2dc
--- /dev/null
+++ b/CompilerPascal/drawtree.h
@@ -0,0 +1,8 @@
+#ifndef DRAW_TREE_H_
+#define DRAW_TREE_H_
+// visualize IR tree, output .dot file
+#include
+#include "tree.h"
+
+void drawStmList(FILE *out, T_stmList stmList);
+#endif
\ No newline at end of file
diff --git a/CompilerPascal/env.c b/CompilerPascal/env.c
new file mode 100644
index 0000000..e36690f
--- /dev/null
+++ b/CompilerPascal/env.c
@@ -0,0 +1,82 @@
+#include
+#include "util.h"
+#include "symbol.h"
+#include "absyn.h"
+#include "temp.h"
+#include "tree.h"
+#include "frame.h"
+#include "translate.h"
+#include "env.h"
+
+Environments Newvarenv(Tr_access acc,Type ty,int isConst)
+{
+ Environments tmp=checked_malloc(sizeof(*tmp));
+ if(isConst)
+ tmp->flag = CONST;
+ else
+ tmp->flag=VAR;
+ tmp->u.var.init = initVar;
+ tmp->u.var.ty=ty;
+ tmp->u.var.acc=acc;
+ return tmp;
+}
+Environments Newfunenv(Tr_level l,Temp_label label,Typelist param,Type output)
+{
+ Environments tmp=checked_malloc(sizeof(*tmp));
+ tmp->flag=FUN;
+ tmp->u.fun.param=param;
+ tmp->u.fun.output=output;
+ tmp->u.fun.lev=l;
+ tmp->u.fun.label=label;
+ return tmp;
+}
+
+S_table Base_varenv(void) //⣬Ӧǰıͣ
+{
+ S_table base=S_empty();
+ S_enter(base,S_Symbol("integer"),INT_type());
+ S_enter(base,S_Symbol("string"),STRING_type());
+ S_enter(base,S_Symbol("real"),REAL_type());
+
+ //¼
+ S_enter(base,S_Symbol("char"),CHAR_type());
+ S_enter(base,S_Symbol("boolean"),BOOLEAN_type());
+ return base;
+}
+S_table Base_funenv(void) //ʱ䣬Ժ˵
+{
+ S_table base = S_empty();
+ S_enter(base,
+ S_Symbol("write"),
+ Newfunenv(Tr_outermost(), Temp_newlabel(), Newtypelist(STRING_type(), NULL), VOID_type())
+ ); //void write(string)
+ S_enter(base,
+ S_Symbol("writeln"),
+ Newfunenv(Tr_outermost(), Temp_newlabel(), Newtypelist(STRING_type(), NULL), VOID_type())
+ ); //void writeln(string)
+ S_enter(base, S_Symbol("abs"),
+ Newfunenv(Tr_outermost(), Temp_newlabel(), Newtypelist(INT_type(), NULL), INT_type())
+ ); //int abs(int)
+ S_enter(base, S_Symbol("chr"),
+ Newfunenv(Tr_outermost(), Temp_newlabel(), Newtypelist(INT_type(), NULL), STRING_type())
+ ); //string chr(int)
+ S_enter(base, S_Symbol("odd"),
+ Newfunenv(Tr_outermost(), Temp_newlabel(), Newtypelist(INT_type(), NULL), BOOLEAN_type())
+ ); //boolean odd(int)
+ S_enter(base, S_Symbol("ord"),
+ Newfunenv(Tr_outermost(), Temp_newlabel(), Newtypelist(CHAR_type(), NULL), INT_type())
+ ); //int ord(char)
+ S_enter(base, S_Symbol("pred"),
+ Newfunenv(Tr_outermost(), Temp_newlabel(), Newtypelist(INT_type(), NULL), INT_type())
+ ); //int pred(int)
+ S_enter(base, S_Symbol("succ"),
+ Newfunenv(Tr_outermost(), Temp_newlabel(), Newtypelist(INT_type(), NULL), INT_type())
+ ); //int succ(int)
+ S_enter(base, S_Symbol("sqr"),
+ Newfunenv(Tr_outermost(), Temp_newlabel(), Newtypelist(INT_type(), NULL), INT_type())
+ ); //int sqr(int)
+ S_enter(base, S_Symbol("sqr"),
+ Newfunenv(Tr_outermost(), Temp_newlabel(), Newtypelist(INT_type(), NULL), REAL_type())
+ ); //real sqrt(int)
+ return base;
+}
\ No newline at end of file
diff --git a/src/env.h b/CompilerPascal/env.h
similarity index 81%
rename from src/env.h
rename to CompilerPascal/env.h
index 8ca719a..ff89db5 100644
--- a/src/env.h
+++ b/CompilerPascal/env.h
@@ -2,7 +2,7 @@
#define ENV_H
#include "translate.h"
-
+#include "types.h"
typedef struct environments *Environments;
struct environments
@@ -10,10 +10,11 @@ struct environments
enum { VAR, FUN, CONST } flag;
union
{
- struct { Tr_access acc; Type ty;} var;
+ struct { Tr_access acc; Type ty; A_exp init; } var;
struct { Tr_level lev; Temp_label label; Typelist param; Type output; } fun;
} u;
};
+static A_exp initVar = NULL;
Environments Newvarenv(Tr_access acc,Type ty,int isConst);
Environments Newfunenv(Tr_level l,Temp_label label,Typelist param,Type output);
diff --git a/src/errormsg.c b/CompilerPascal/errormsg.c
similarity index 100%
rename from src/errormsg.c
rename to CompilerPascal/errormsg.c
diff --git a/src/errormsg.h b/CompilerPascal/errormsg.h
similarity index 100%
rename from src/errormsg.h
rename to CompilerPascal/errormsg.h
diff --git a/CompilerPascal/escape.c b/CompilerPascal/escape.c
new file mode 100644
index 0000000..da04984
--- /dev/null
+++ b/CompilerPascal/escape.c
@@ -0,0 +1,179 @@
+#include "escape.h"
+#include "symbol.h"
+#include "util.h"
+#include "absyn.h"
+
+typedef struct escapeEntry_ *escapeEntry;
+struct escapeEntry_ {
+ int depth;
+ bool* escape;
+};
+static escapeEntry EscapeEntry(int depth, bool *escape) {
+ escapeEntry entry = checked_malloc(sizeof(*entry));
+ entry->depth = depth;
+ entry->escape = escape;
+ *escape = FALSE;
+ return entry;
+}
+
+static S_table escapeEnv;
+
+static void traverseExp(S_table env, int depth, A_exp e);
+static void traverseDec(S_table env, int depth, A_dec d);
+static void traverseVar(S_table env, int depth, A_var v);
+
+// static functions
+static void traverseExp(S_table env, int depth, A_exp e) {
+ // endpoint of recursing
+ if (!e) {
+ return;
+ }
+ switch (e->kind) {
+ case A_varExp:
+ traverseVar(env, depth, e->u.var);
+ break;
+ case A_intExp:
+ case A_realExp:
+ case A_charExp:
+ case A_boolExp:
+ case A_stringExp:
+ break;
+ case A_callExp:
+ for (A_expList args = e->u.call.args;args;args = args->tail) {
+ traverseExp(env, depth, args->head);
+ }
+ break;
+ case A_opExp:
+ traverseExp(env, depth, e->u.op.left);
+ traverseExp(env, depth, e->u.op.right);
+ break;
+ case A_recordExp:
+ for (A_efieldList fields = e->u.record.fields;fields;fields = fields->tail) {
+ traverseExp(env, depth, fields->head->exp);
+ }
+ break;
+ case A_seqExp:
+ for (A_expList list = e->u.seq;list;list = list->tail) {
+ traverseExp(env, depth, list->head);
+ }
+ break;
+ case A_assignExp:
+ traverseVar(env, depth, e->u.assign.var);
+ traverseExp(env, depth, e->u.assign.exp);
+ break;
+ case A_ifExp:
+ traverseExp(env, depth, e->u.iff.test);
+ traverseExp(env, depth, e->u.iff.then);
+ traverseExp(env, depth, e->u.iff.elsee);
+ break;
+ case A_whileExp:
+ traverseExp(env, depth, e->u.whilee.test);
+ traverseExp(env, depth, e->u.whilee.body);
+ break;
+ case A_repeatExp:
+ traverseExp(env, depth, e->u.repeatt.body);
+ traverseExp(env, depth, e->u.repeatt.test);
+ break;
+ case A_caseExp:
+ traverseExp(env, depth, e->u.casee.exp);
+ for (A_expList list = e->u.casee.valList;list;list = list->tail) {
+ traverseExp(env, depth, list->head);
+ }
+ break;
+ case A_caseValExp:
+ traverseExp(env, depth, e->u.caseval.val);
+ traverseExp(env, depth, e->u.caseval.action);
+ break;
+ case A_gotoExp:
+ traverseExp(env, depth, e->u.gotoo.label);
+ break;
+ case A_letExp:
+ S_beginScope(env);
+ for (A_decList decs = e->u.let.decs;decs;decs = decs->tail) {
+ traverseDec(env, depth, decs->head);
+ }
+ traverseExp(env, depth, e->u.let.body);
+ S_endScope(env,3);
+ break;
+ case A_arrayExp:
+ traverseExp(env, depth, e->u.array.size);
+ traverseExp(env, depth, e->u.array.init);
+ break;
+ default:
+ assert(0);
+ }
+}
+
+static void traverseDec(S_table env, int depth, A_dec d) {
+ if (!d)
+ return;
+ A_fundec func;
+ switch (d->kind) {
+ case A_functionDec: {
+ A_fundecList funcList = d->u.function;
+ for (;funcList;funcList = funcList->tail) {
+ func = funcList->head;
+ // go deepper in depth
+ depth++;
+ S_beginScope(env);
+ // check for params
+ A_fieldList params = func->params;
+ for (;params;params = params->tail) {
+ A_field param = params->head;
+ S_enter(env, param->name, EscapeEntry(depth, &(param->escape)));
+ }
+ traverseExp(env, depth, func->body);
+ S_endScope(env, 3);
+ depth--;
+ }
+ break;
+ }
+ case A_constDec:
+ S_enter(env, d->u.constt.constt, EscapeEntry(depth, &(d->u.constt.escape)));
+ break;
+ case A_varDec:
+ S_enter(env, d->u.var.var, EscapeEntry(depth, &(d->u.var.escape)));
+ traverseExp(env, depth, d->u.var.init);
+ break;
+ case A_typeDec:
+ // don't care about escape
+ break;
+ default:
+ // can't get here
+ assert(0);
+ }
+
+ return;
+}
+
+static void traverseVar(S_table env, int depth, A_var v) {
+ if (!v)
+ return;
+ switch (v->kind) {
+ case A_simpleVar: {
+ // look up in table
+ escapeEntry entry = (escapeEntry)S_look(env, v->u.simple);
+ // used at depth > decalaration depth
+ // set escape to true
+ if (entry&&depth>entry->depth) {
+ *(entry->escape) = TRUE;
+ }
+ break;
+ }
+ case A_fieldVar:
+ traverseVar(env, depth, v->u.field.var);
+ break;
+ case A_subscriptVar:
+ traverseVar(env, depth, v->u.subscript.var);
+ traverseExp(env, depth, v->u.subscript.exp);
+ break;
+ default:
+ assert(0);
+ }
+}
+
+void Esc_findEscape(A_exp exp) {
+ int depth = 0;
+ escapeEnv = S_empty();
+ traverseExp(escapeEnv, depth, exp);
+}
\ No newline at end of file
diff --git a/CompilerPascal/escape.h b/CompilerPascal/escape.h
new file mode 100644
index 0000000..92df317
--- /dev/null
+++ b/CompilerPascal/escape.h
@@ -0,0 +1,5 @@
+#ifndef _ESCAPE_H_
+#define _ESCAPE_H_
+#include "absyn.h"
+void Esc_findEscape(A_exp exp);
+#endif
\ No newline at end of file
diff --git a/src/frame.h b/CompilerPascal/frame.h
similarity index 86%
rename from src/frame.h
rename to CompilerPascal/frame.h
index 72966d2..2f8de07 100644
--- a/src/frame.h
+++ b/CompilerPascal/frame.h
@@ -1,8 +1,10 @@
#ifndef FRAME_H
#define FRAME_H
+
#include "util.h"
#include "temp.h"
#include "tree.h"
+#define F_TEMPMAP (F_tempMap ? F_tempMap : (F_tempMap = Temp_empty()))
typedef struct F_access_ *F_access;
typedef struct F_accessList_ *F_accessList;
@@ -41,10 +43,10 @@ Temp_temp F_Fp(void);
extern const int F_wordSize;
F_accessList F_AccessList(F_access head, F_accessList tail);
-F_frame F_newFrame(Temp_label name, U_boolList formals);
+F_frame F_newFrame(Temp_label name, U_boolList formals, U_intList formalsSizes);
Temp_label F_name(F_frame f);
F_accessList F_formals(F_frame f);
-F_access F_allocLocal(F_frame f, bool escape);
+F_access F_allocLocal(F_frame f, bool escape, int size);
// return address of access
// T_exp is address of stack frame
diff --git a/CompilerPascal/lex.yy.c b/CompilerPascal/lex.yy.c
new file mode 100644
index 0000000..65eb19d
--- /dev/null
+++ b/CompilerPascal/lex.yy.c
@@ -0,0 +1,2017 @@
+/* A lexical scanner generated by flex */
+
+/* Scanner skeleton version:
+ * $Header: /home/daffy/u0/vern/flex/RCS/flex.skl,v 2.91 96/09/10 16:58:48 vern Exp $
+ */
+
+#define FLEX_SCANNER
+#define YY_FLEX_MAJOR_VERSION 2
+#define YY_FLEX_MINOR_VERSION 5
+
+#include
+
+
+/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */
+#ifdef c_plusplus
+#ifndef __cplusplus
+#define __cplusplus
+#endif
+#endif
+
+
+#ifdef __cplusplus
+
+#include
+#include
+
+/* Use prototypes in function declarations. */
+#define YY_USE_PROTOS
+
+/* The "const" storage-class-modifier is valid. */
+#define YY_USE_CONST
+
+#else /* ! __cplusplus */
+
+#if __STDC__
+
+#define YY_USE_PROTOS
+#define YY_USE_CONST
+
+#endif /* __STDC__ */
+#endif /* ! __cplusplus */
+
+#ifdef __TURBOC__
+ #pragma warn -rch
+ #pragma warn -use
+#include
+#include
+#define YY_USE_CONST
+#define YY_USE_PROTOS
+#endif
+
+#ifdef YY_USE_CONST
+#define yyconst const
+#else
+#define yyconst
+#endif
+
+
+#ifdef YY_USE_PROTOS
+#define YY_PROTO(proto) proto
+#else
+#define YY_PROTO(proto) ()
+#endif
+
+/* Returned upon end-of-file. */
+#define YY_NULL 0
+
+/* Promotes a possibly negative, possibly signed char to an unsigned
+ * integer for use as an array index. If the signed char is negative,
+ * we want to instead treat it as an 8-bit unsigned char, hence the
+ * double cast.
+ */
+#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
+
+/* Enter a start condition. This macro really ought to take a parameter,
+ * but we do it the disgusting crufty way forced on us by the ()-less
+ * definition of BEGIN.
+ */
+#define BEGIN yy_start = 1 + 2 *
+
+/* Translate the current start state into a value that can be later handed
+ * to BEGIN to return to the state. The YYSTATE alias is for lex
+ * compatibility.
+ */
+#define YY_START ((yy_start - 1) / 2)
+#define YYSTATE YY_START
+
+/* Action number for EOF rule of a given start state. */
+#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
+
+/* Special action meaning "start processing a new file". */
+#define YY_NEW_FILE yyrestart( yyin )
+
+#define YY_END_OF_BUFFER_CHAR 0
+
+/* Size of default input buffer. */
+#define YY_BUF_SIZE 16384
+
+typedef struct yy_buffer_state *YY_BUFFER_STATE;
+
+extern int yyleng;
+extern FILE *yyin, *yyout;
+
+#define EOB_ACT_CONTINUE_SCAN 0
+#define EOB_ACT_END_OF_FILE 1
+#define EOB_ACT_LAST_MATCH 2
+
+/* The funky do-while in the following #define is used to turn the definition
+ * int a single C statement (which needs a semi-colon terminator). This
+ * avoids problems with code like:
+ *
+ * if ( condition_holds )
+ * yyless( 5 );
+ * else
+ * do_something_else();
+ *
+ * Prior to using the do-while the compiler would get upset at the
+ * "else" because it interpreted the "if" statement as being all
+ * done when it reached the ';' after the yyless() call.
+ */
+
+/* Return all but the first 'n' matched characters back to the input stream. */
+
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ *yy_cp = yy_hold_char; \
+ YY_RESTORE_YY_MORE_OFFSET \
+ yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \
+ YY_DO_BEFORE_ACTION; /* set up yytext again */ \
+ } \
+ while ( 0 )
+
+#define unput(c) yyunput( c, yytext_ptr )
+
+/* The following is because we cannot portably get our hands on size_t
+ * (without autoconf's help, which isn't available because we want
+ * flex-generated scanners to compile on their own).
+ */
+typedef unsigned int yy_size_t;
+
+
+struct yy_buffer_state
+ {
+ FILE *yy_input_file;
+
+ char *yy_ch_buf; /* input buffer */
+ char *yy_buf_pos; /* current position in input buffer */
+
+ /* Size of input buffer in bytes, not including room for EOB
+ * characters.
+ */
+ yy_size_t yy_buf_size;
+
+ /* Number of characters read into yy_ch_buf, not including EOB
+ * characters.
+ */
+ int yy_n_chars;
+
+ /* Whether we "own" the buffer - i.e., we know we created it,
+ * and can realloc() it to grow it, and should free() it to
+ * delete it.
+ */
+ int yy_is_our_buffer;
+
+ /* Whether this is an "interactive" input source; if so, and
+ * if we're using stdio for input, then we want to use getc()
+ * instead of fread(), to make sure we stop fetching input after
+ * each newline.
+ */
+ int yy_is_interactive;
+
+ /* Whether we're considered to be at the beginning of a line.
+ * If so, '^' rules will be active on the next match, otherwise
+ * not.
+ */
+ int yy_at_bol;
+
+ /* Whether to try to fill the input buffer when we reach the
+ * end of it.
+ */
+ int yy_fill_buffer;
+
+ int yy_buffer_status;
+#define YY_BUFFER_NEW 0
+#define YY_BUFFER_NORMAL 1
+ /* When an EOF's been seen but there's still some text to process
+ * then we mark the buffer as YY_EOF_PENDING, to indicate that we
+ * shouldn't try reading from the input source any more. We might
+ * still have a bunch of tokens to match, though, because of
+ * possible backing-up.
+ *
+ * When we actually see the EOF, we change the status to "new"
+ * (via yyrestart()), so that the user can continue scanning by
+ * just pointing yyin at a new input file.
+ */
+#define YY_BUFFER_EOF_PENDING 2
+ };
+
+static YY_BUFFER_STATE yy_current_buffer = 0;
+
+/* We provide macros for accessing buffer states in case in the
+ * future we want to put the buffer states in a more general
+ * "scanner state".
+ */
+#define YY_CURRENT_BUFFER yy_current_buffer
+
+
+/* yy_hold_char holds the character lost when yytext is formed. */
+static char yy_hold_char;
+
+static int yy_n_chars; /* number of characters read into yy_ch_buf */
+
+
+int yyleng;
+
+/* Points to current character in buffer. */
+static char *yy_c_buf_p = (char *) 0;
+static int yy_init = 1; /* whether we need to initialize */
+static int yy_start = 0; /* start state number */
+
+/* Flag which is used to allow yywrap()'s to do buffer switches
+ * instead of setting up a fresh yyin. A bit of a hack ...
+ */
+static int yy_did_buffer_switch_on_eof;
+
+void yyrestart YY_PROTO(( FILE *input_file ));
+
+void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer ));
+void yy_load_buffer_state YY_PROTO(( void ));
+YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size ));
+void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b ));
+void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file ));
+void yy_flush_buffer YY_PROTO(( YY_BUFFER_STATE b ));
+#define YY_FLUSH_BUFFER yy_flush_buffer( yy_current_buffer )
+
+YY_BUFFER_STATE yy_scan_buffer YY_PROTO(( char *base, yy_size_t size ));
+YY_BUFFER_STATE yy_scan_string YY_PROTO(( yyconst char *yy_str ));
+YY_BUFFER_STATE yy_scan_bytes YY_PROTO(( yyconst char *bytes, int len ));
+
+static void *yy_flex_alloc YY_PROTO(( yy_size_t ));
+static void *yy_flex_realloc YY_PROTO(( void *, yy_size_t ));
+static void yy_flex_free YY_PROTO(( void * ));
+
+#define yy_new_buffer yy_create_buffer
+
+#define yy_set_interactive(is_interactive) \
+ { \
+ if ( ! yy_current_buffer ) \
+ yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \
+ yy_current_buffer->yy_is_interactive = is_interactive; \
+ }
+
+#define yy_set_bol(at_bol) \
+ { \
+ if ( ! yy_current_buffer ) \
+ yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \
+ yy_current_buffer->yy_at_bol = at_bol; \
+ }
+
+#define YY_AT_BOL() (yy_current_buffer->yy_at_bol)
+
+typedef unsigned char YY_CHAR;
+FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
+typedef int yy_state_type;
+extern char *yytext;
+#define yytext_ptr yytext
+
+static yy_state_type yy_get_previous_state YY_PROTO(( void ));
+static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state ));
+static int yy_get_next_buffer YY_PROTO(( void ));
+static void yy_fatal_error YY_PROTO(( yyconst char msg[] ));
+
+/* Done after the current pattern has been matched and before the
+ * corresponding action - sets up yytext.
+ */
+#define YY_DO_BEFORE_ACTION \
+ yytext_ptr = yy_bp; \
+ yyleng = (int) (yy_cp - yy_bp); \
+ yy_hold_char = *yy_cp; \
+ *yy_cp = '\0'; \
+ yy_c_buf_p = yy_cp;
+
+#define YY_NUM_RULES 65
+#define YY_END_OF_BUFFER 66
+static yyconst short int yy_accept[203] =
+ { 0,
+ 0, 0, 66, 64, 63, 59, 64, 64, 64, 1,
+ 2, 12, 10, 7, 11, 5, 13, 51, 8, 9,
+ 19, 20, 17, 50, 50, 50, 50, 50, 50, 50,
+ 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
+ 50, 3, 4, 50, 50, 50, 50, 50, 50, 50,
+ 50, 50, 50, 50, 50, 64, 60, 0, 0, 6,
+ 61, 0, 51, 22, 18, 21, 16, 50, 50, 50,
+ 50, 50, 50, 50, 41, 50, 50, 50, 50, 50,
+ 35, 50, 50, 28, 48, 50, 50, 50, 43, 50,
+ 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
+
+ 48, 50, 50, 50, 50, 50, 50, 0, 0, 0,
+ 62, 54, 53, 61, 52, 47, 50, 50, 50, 50,
+ 14, 50, 50, 30, 42, 50, 50, 15, 49, 50,
+ 50, 50, 50, 50, 50, 50, 26, 50, 50, 50,
+ 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
+ 62, 50, 50, 45, 50, 50, 37, 50, 46, 50,
+ 50, 34, 50, 50, 36, 25, 50, 50, 50, 50,
+ 50, 50, 50, 50, 27, 33, 24, 50, 50, 50,
+ 50, 50, 50, 39, 40, 50, 50, 44, 50, 50,
+ 50, 29, 38, 50, 50, 50, 23, 50, 31, 50,
+
+ 32, 0
+ } ;
+
+static yyconst int yy_ec[256] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
+ 1, 1, 4, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 2, 1, 5, 1, 1, 1, 1, 6, 7,
+ 8, 9, 10, 11, 12, 13, 14, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 16, 17, 18,
+ 19, 20, 1, 1, 21, 22, 23, 24, 25, 26,
+ 27, 28, 29, 30, 30, 31, 32, 33, 34, 35,
+ 30, 36, 37, 38, 39, 40, 41, 30, 42, 30,
+ 43, 44, 45, 44, 44, 44, 46, 47, 48, 49,
+
+ 50, 51, 27, 52, 53, 30, 30, 54, 55, 56,
+ 57, 58, 59, 60, 61, 62, 63, 40, 64, 65,
+ 42, 30, 66, 1, 67, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1
+ } ;
+
+static yyconst int yy_meta[68] =
+ { 0,
+ 1, 2, 3, 1, 2, 2, 1, 1, 1, 1,
+ 1, 1, 2, 4, 5, 1, 1, 1, 1, 1,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 6, 6, 2, 2, 2, 6, 6, 6, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 6, 6, 1, 1
+ } ;
+
+static yyconst short int yy_base[209] =
+ { 0,
+ 0, 0, 382, 383, 383, 383, 378, 0, 0, 383,
+ 383, 383, 383, 383, 383, 367, 365, 55, 359, 383,
+ 52, 383, 358, 40, 44, 53, 48, 48, 46, 41,
+ 0, 57, 50, 54, 80, 53, 65, 84, 58, 71,
+ 67, 383, 383, 87, 72, 103, 93, 95, 96, 112,
+ 92, 108, 103, 131, 116, 155, 383, 371, 369, 383,
+ 0, 359, 162, 383, 383, 383, 383, 0, 121, 118,
+ 346, 120, 134, 332, 130, 137, 155, 146, 147, 146,
+ 0, 161, 149, 0, 0, 152, 172, 164, 0, 157,
+ 159, 163, 171, 310, 313, 157, 315, 306, 302, 317,
+
+ 316, 178, 204, 302, 307, 280, 289, 187, 193, 217,
+ 220, 333, 383, 0, 322, 0, 192, 187, 207, 200,
+ 0, 200, 216, 0, 0, 219, 202, 0, 0, 220,
+ 220, 214, 220, 216, 226, 224, 0, 224, 0, 279,
+ 0, 268, 266, 269, 271, 234, 252, 265, 262, 249,
+ 265, 250, 230, 0, 227, 235, 0, 237, 0, 255,
+ 246, 0, 249, 269, 0, 0, 250, 266, 202, 196,
+ 149, 73, 0, 75, 0, 0, 0, 260, 266, 269,
+ 275, 274, 262, 0, 0, 31, 32, 0, 268, 264,
+ 275, 0, 0, 22, 275, 274, 0, 0, 0, 276,
+
+ 0, 383, 333, 338, 340, 346, 352, 358
+ } ;
+
+static yyconst short int yy_def[209] =
+ { 0,
+ 202, 1, 202, 202, 202, 202, 202, 203, 204, 202,
+ 202, 202, 202, 202, 202, 202, 202, 202, 202, 202,
+ 202, 202, 202, 205, 205, 205, 205, 205, 205, 205,
+ 205, 205, 205, 205, 205, 205, 205, 205, 205, 205,
+ 205, 202, 202, 205, 205, 205, 205, 205, 205, 205,
+ 205, 205, 205, 205, 205, 206, 202, 203, 202, 202,
+ 207, 202, 202, 202, 202, 202, 202, 205, 205, 205,
+ 205, 205, 205, 205, 205, 205, 205, 205, 205, 205,
+ 205, 205, 205, 205, 205, 205, 205, 205, 205, 205,
+ 205, 205, 205, 205, 205, 205, 205, 205, 205, 205,
+
+ 205, 205, 205, 205, 205, 205, 205, 206, 208, 206,
+ 206, 203, 202, 207, 202, 205, 205, 205, 205, 205,
+ 205, 205, 205, 205, 205, 205, 205, 205, 205, 205,
+ 205, 205, 205, 205, 205, 205, 205, 205, 205, 205,
+ 205, 205, 205, 205, 205, 205, 205, 205, 205, 205,
+ 206, 205, 205, 205, 205, 205, 205, 205, 205, 205,
+ 205, 205, 205, 205, 205, 205, 205, 205, 205, 205,
+ 205, 205, 205, 205, 205, 205, 205, 205, 205, 205,
+ 205, 205, 205, 205, 205, 205, 205, 205, 205, 205,
+ 205, 205, 205, 205, 205, 205, 205, 205, 205, 205,
+
+ 205, 0, 202, 202, 202, 202, 202, 202
+ } ;
+
+static yyconst short int yy_nxt[451] =
+ { 0,
+ 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
+ 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
+ 24, 25, 26, 27, 28, 29, 30, 31, 32, 31,
+ 31, 33, 34, 35, 36, 37, 31, 38, 39, 40,
+ 41, 31, 42, 4, 43, 44, 45, 46, 27, 28,
+ 47, 31, 48, 31, 49, 34, 50, 51, 31, 52,
+ 53, 54, 39, 55, 31, 56, 4, 62, 71, 63,
+ 65, 66, 69, 72, 80, 70, 74, 198, 76, 78,
+ 77, 75, 81, 82, 79, 194, 73, 83, 86, 87,
+ 91, 92, 173, 71, 93, 69, 71, 80, 72, 70,
+
+ 74, 76, 78, 77, 75, 84, 82, 81, 79, 73,
+ 83, 88, 86, 91, 87, 85, 92, 89, 93, 69,
+ 81, 71, 70, 72, 187, 90, 78, 86, 95, 82,
+ 84, 79, 87, 94, 141, 88, 73, 84, 97, 85,
+ 89, 99, 69, 93, 116, 81, 70, 85, 72, 78,
+ 98, 102, 82, 117, 96, 79, 119, 103, 88, 73,
+ 100, 104, 84, 109, 89, 105, 120, 93, 110, 116,
+ 122, 101, 90, 123, 62, 107, 63, 117, 124, 126,
+ 119, 125, 88, 127, 128, 130, 129, 89, 134, 120,
+ 106, 135, 131, 122, 132, 109, 136, 123, 137, 138,
+
+ 110, 109, 126, 124, 186, 125, 133, 127, 130, 128,
+ 129, 130, 152, 134, 135, 153, 139, 131, 141, 132,
+ 136, 111, 137, 138, 131, 109, 132, 145, 109, 133,
+ 110, 154, 156, 110, 130, 159, 155, 152, 133, 153,
+ 157, 158, 160, 162, 164, 173, 161, 163, 165, 146,
+ 166, 132, 167, 111, 168, 156, 154, 162, 159, 151,
+ 155, 133, 176, 141, 177, 157, 158, 160, 162, 164,
+ 163, 165, 178, 109, 179, 166, 167, 168, 110, 180,
+ 184, 181, 162, 111, 182, 176, 111, 172, 177, 183,
+ 185, 175, 190, 188, 189, 191, 178, 192, 179, 193,
+
+ 201, 195, 196, 184, 180, 181, 197, 199, 182, 200,
+ 174, 173, 139, 139, 183, 185, 188, 190, 189, 139,
+ 191, 171, 192, 193, 195, 201, 196, 141, 170, 197,
+ 199, 111, 169, 200, 58, 58, 115, 112, 58, 59,
+ 59, 150, 149, 59, 68, 68, 108, 108, 108, 108,
+ 108, 108, 114, 114, 148, 114, 114, 114, 110, 110,
+ 110, 147, 110, 110, 139, 139, 144, 143, 142, 140,
+ 139, 121, 118, 115, 113, 112, 67, 64, 61, 60,
+ 57, 202, 3, 202, 202, 202, 202, 202, 202, 202,
+ 202, 202, 202, 202, 202, 202, 202, 202, 202, 202,
+
+ 202, 202, 202, 202, 202, 202, 202, 202, 202, 202,
+ 202, 202, 202, 202, 202, 202, 202, 202, 202, 202,
+ 202, 202, 202, 202, 202, 202, 202, 202, 202, 202,
+ 202, 202, 202, 202, 202, 202, 202, 202, 202, 202,
+ 202, 202, 202, 202, 202, 202, 202, 202, 202, 202
+ } ;
+
+static yyconst short int yy_chk[451] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 18, 25, 18,
+ 21, 21, 24, 26, 30, 24, 27, 194, 28, 29,
+ 28, 27, 32, 33, 29, 187, 26, 34, 36, 37,
+ 39, 40, 186, 25, 41, 24, 45, 30, 26, 24,
+
+ 27, 28, 29, 28, 27, 35, 33, 32, 29, 26,
+ 34, 38, 36, 39, 37, 35, 40, 38, 41, 44,
+ 48, 45, 44, 46, 174, 38, 47, 51, 45, 49,
+ 35, 47, 52, 44, 172, 38, 46, 50, 47, 35,
+ 38, 49, 44, 55, 69, 48, 44, 50, 46, 47,
+ 48, 51, 49, 70, 46, 47, 72, 52, 54, 46,
+ 50, 53, 50, 56, 54, 53, 73, 55, 56, 69,
+ 75, 50, 54, 76, 63, 55, 63, 70, 77, 79,
+ 72, 78, 54, 80, 82, 86, 83, 54, 88, 73,
+ 54, 90, 87, 75, 87, 108, 91, 76, 92, 93,
+
+ 108, 109, 79, 77, 171, 78, 87, 80, 86, 82,
+ 83, 102, 117, 88, 90, 118, 96, 87, 96, 87,
+ 91, 56, 92, 93, 103, 110, 103, 102, 111, 87,
+ 110, 119, 122, 111, 102, 127, 120, 117, 103, 118,
+ 123, 126, 130, 131, 133, 170, 130, 132, 134, 103,
+ 135, 103, 136, 108, 138, 122, 119, 146, 127, 109,
+ 120, 103, 153, 169, 155, 123, 126, 130, 131, 133,
+ 132, 134, 156, 151, 158, 135, 136, 138, 151, 160,
+ 167, 161, 146, 110, 163, 153, 111, 146, 155, 164,
+ 168, 152, 180, 178, 179, 181, 156, 182, 158, 183,
+
+ 200, 189, 190, 167, 160, 161, 191, 195, 163, 196,
+ 150, 149, 148, 147, 164, 168, 178, 180, 179, 145,
+ 181, 144, 182, 183, 189, 200, 190, 143, 142, 191,
+ 195, 151, 140, 196, 203, 203, 115, 112, 203, 204,
+ 204, 107, 106, 204, 205, 205, 206, 206, 206, 206,
+ 206, 206, 207, 207, 105, 207, 207, 207, 208, 208,
+ 208, 104, 208, 208, 101, 100, 99, 98, 97, 95,
+ 94, 74, 71, 62, 59, 58, 23, 19, 17, 16,
+ 7, 3, 202, 202, 202, 202, 202, 202, 202, 202,
+ 202, 202, 202, 202, 202, 202, 202, 202, 202, 202,
+
+ 202, 202, 202, 202, 202, 202, 202, 202, 202, 202,
+ 202, 202, 202, 202, 202, 202, 202, 202, 202, 202,
+ 202, 202, 202, 202, 202, 202, 202, 202, 202, 202,
+ 202, 202, 202, 202, 202, 202, 202, 202, 202, 202,
+ 202, 202, 202, 202, 202, 202, 202, 202, 202, 202
+ } ;
+
+static yy_state_type yy_last_accepting_state;
+static char *yy_last_accepting_cpos;
+
+/* The intent behind this definition is that it'll catch
+ * any uses of REJECT which flex missed.
+ */
+#define REJECT reject_used_but_not_detected
+#define yymore() yymore_used_but_not_detected
+#define YY_MORE_ADJ 0
+#define YY_RESTORE_YY_MORE_OFFSET
+char *yytext;
+#line 1 "Pascal.l"
+#define INITIAL 0
+#line 2 "Pascal.l"
+#include
+#include
+#include "util.h"
+#include "errormsg.h"
+#include "symbol.h"
+#include "absyn.h"
+#include "y.tab.h"
+
+#define YY_NO_UNISTD_H
+// update EM_tokPos
+void updatePos(void);
+int charPos;
+#line 544 "lex.yy.c"
+
+/* Macros after this point can all be overridden by user definitions in
+ * section 1.
+ */
+
+#ifndef YY_SKIP_YYWRAP
+#ifdef __cplusplus
+extern "C" int yywrap YY_PROTO(( void ));
+#else
+extern int yywrap YY_PROTO(( void ));
+#endif
+#endif
+
+#ifndef YY_NO_UNPUT
+static void yyunput YY_PROTO(( int c, char *buf_ptr ));
+#endif
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy YY_PROTO(( char *, yyconst char *, int ));
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen YY_PROTO(( yyconst char * ));
+#endif
+
+#ifndef YY_NO_INPUT
+#ifdef __cplusplus
+static int yyinput YY_PROTO(( void ));
+#else
+static int input YY_PROTO(( void ));
+#endif
+#endif
+
+#if YY_STACK_USED
+static int yy_start_stack_ptr = 0;
+static int yy_start_stack_depth = 0;
+static int *yy_start_stack = 0;
+#ifndef YY_NO_PUSH_STATE
+static void yy_push_state YY_PROTO(( int new_state ));
+#endif
+#ifndef YY_NO_POP_STATE
+static void yy_pop_state YY_PROTO(( void ));
+#endif
+#ifndef YY_NO_TOP_STATE
+static int yy_top_state YY_PROTO(( void ));
+#endif
+
+#else
+#define YY_NO_PUSH_STATE 1
+#define YY_NO_POP_STATE 1
+#define YY_NO_TOP_STATE 1
+#endif
+
+#ifdef YY_MALLOC_DECL
+YY_MALLOC_DECL
+#else
+#if __STDC__
+#ifndef __cplusplus
+#include
+#endif
+#else
+/* Just try to get by without declaring the routines. This will fail
+ * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int)
+ * or sizeof(void*) != sizeof(int).
+ */
+#endif
+#endif
+
+/* Amount of stuff to slurp up with each read. */
+#ifndef YY_READ_BUF_SIZE
+#define YY_READ_BUF_SIZE 8192
+#endif
+
+/* Copy whatever the last rule matched to the standard output. */
+
+#ifndef ECHO
+/* This used to be an fputs(), but since the string might contain NUL's,
+ * we now use fwrite().
+ */
+#define ECHO (void) fwrite( yytext, yyleng, 1, yyout )
+#endif
+
+/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
+ * is returned in "result".
+ */
+#ifndef YY_INPUT
+#define YY_INPUT(buf,result,max_size) \
+ if ( yy_current_buffer->yy_is_interactive ) \
+ { \
+ int c = '*', n; \
+ for ( n = 0; n < max_size && \
+ (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
+ buf[n] = (char) c; \
+ if ( c == '\n' ) \
+ buf[n++] = (char) c; \
+ if ( c == EOF && ferror( yyin ) ) \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ result = n; \
+ } \
+ else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \
+ && ferror( yyin ) ) \
+ YY_FATAL_ERROR( "input in flex scanner failed" );
+#endif
+
+/* No semi-colon after return; correct usage is to write "yyterminate();" -
+ * we don't want an extra ';' after the "return" because that will cause
+ * some compilers to complain about unreachable statements.
+ */
+#ifndef yyterminate
+#define yyterminate() return YY_NULL
+#endif
+
+/* Number of entries by which start-condition stack grows. */
+#ifndef YY_START_STACK_INCR
+#define YY_START_STACK_INCR 25
+#endif
+
+/* Report a fatal error. */
+#ifndef YY_FATAL_ERROR
+#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
+#endif
+
+/* Default declaration of generated scanner - a define so the user can
+ * easily add parameters.
+ */
+#ifndef YY_DECL
+#define YY_DECL int yylex YY_PROTO(( void ))
+#endif
+
+/* Code executed at the beginning of each rule, after yytext and yyleng
+ * have been set up.
+ */
+#ifndef YY_USER_ACTION
+#define YY_USER_ACTION
+#endif
+
+/* Code executed at the end of each rule. */
+#ifndef YY_BREAK
+#define YY_BREAK break;
+#endif
+
+#define YY_RULE_SETUP \
+ YY_USER_ACTION
+
+YY_DECL
+ {
+ register yy_state_type yy_current_state;
+ register char *yy_cp, *yy_bp;
+ register int yy_act;
+
+#line 69 "Pascal.l"
+
+
+#line 698 "lex.yy.c"
+
+ if ( yy_init )
+ {
+ yy_init = 0;
+
+#ifdef YY_USER_INIT
+ YY_USER_INIT;
+#endif
+
+ if ( ! yy_start )
+ yy_start = 1; /* first start state */
+
+ if ( ! yyin )
+ yyin = stdin;
+
+ if ( ! yyout )
+ yyout = stdout;
+
+ if ( ! yy_current_buffer )
+ yy_current_buffer =
+ yy_create_buffer( yyin, YY_BUF_SIZE );
+
+ yy_load_buffer_state();
+ }
+
+ while ( 1 ) /* loops until end-of-file is reached */
+ {
+ yy_cp = yy_c_buf_p;
+
+ /* Support of yytext. */
+ *yy_cp = yy_hold_char;
+
+ /* yy_bp points to the position in yy_ch_buf of the start of
+ * the current run.
+ */
+ yy_bp = yy_cp;
+
+ yy_current_state = yy_start;
+yy_match:
+ do
+ {
+ register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
+ if ( yy_accept[yy_current_state] )
+ {
+ yy_last_accepting_state = yy_current_state;
+ yy_last_accepting_cpos = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 203 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ ++yy_cp;
+ }
+ while ( yy_base[yy_current_state] != 383 );
+
+yy_find_action:
+ yy_act = yy_accept[yy_current_state];
+ if ( yy_act == 0 )
+ { /* have to back up */
+ yy_cp = yy_last_accepting_cpos;
+ yy_current_state = yy_last_accepting_state;
+ yy_act = yy_accept[yy_current_state];
+ }
+
+ YY_DO_BEFORE_ACTION;
+
+
+do_action: /* This label is used only to access EOF actions. */
+
+
+ switch ( yy_act )
+ { /* beginning of action switch */
+ case 0: /* must back up */
+ /* undo the effects of YY_DO_BEFORE_ACTION */
+ *yy_cp = yy_hold_char;
+ yy_cp = yy_last_accepting_cpos;
+ yy_current_state = yy_last_accepting_state;
+ goto yy_find_action;
+
+case 1:
+YY_RULE_SETUP
+#line 71 "Pascal.l"
+{updatePos(); return LP;}
+ YY_BREAK
+case 2:
+YY_RULE_SETUP
+#line 72 "Pascal.l"
+{updatePos(); return RP;}
+ YY_BREAK
+case 3:
+YY_RULE_SETUP
+#line 73 "Pascal.l"
+{updatePos(); return LB;}
+ YY_BREAK
+case 4:
+YY_RULE_SETUP
+#line 74 "Pascal.l"
+{updatePos(); return RB;}
+ YY_BREAK
+case 5:
+YY_RULE_SETUP
+#line 75 "Pascal.l"
+{updatePos(); return DOT;}
+ YY_BREAK
+case 6:
+YY_RULE_SETUP
+#line 76 "Pascal.l"
+{updatePos(); return DOTDOT;}
+ YY_BREAK
+case 7:
+YY_RULE_SETUP
+#line 77 "Pascal.l"
+{updatePos(); return COMMA; }
+ YY_BREAK
+case 8:
+YY_RULE_SETUP
+#line 78 "Pascal.l"
+{updatePos(); return COLON;} //应该是:SEMI应该是;
+ YY_BREAK
+case 9:
+YY_RULE_SETUP
+#line 79 "Pascal.l"
+{updatePos(); return SEMI;} //name == id
+ YY_BREAK
+case 10:
+YY_RULE_SETUP
+#line 80 "Pascal.l"
+{updatePos(); return PLUS;}
+ YY_BREAK
+case 11:
+YY_RULE_SETUP
+#line 81 "Pascal.l"
+{updatePos(); return MINUS;}
+ YY_BREAK
+case 12:
+YY_RULE_SETUP
+#line 82 "Pascal.l"
+{updatePos(); return MUL;}
+ YY_BREAK
+case 13:
+YY_RULE_SETUP
+#line 83 "Pascal.l"
+{updatePos(); return REALDIV;}
+ YY_BREAK
+case 14:
+YY_RULE_SETUP
+#line 84 "Pascal.l"
+{updatePos(); return INTDIV;}
+ YY_BREAK
+case 15:
+YY_RULE_SETUP
+#line 85 "Pascal.l"
+{updatePos(); return MOD; }
+ YY_BREAK
+case 16:
+YY_RULE_SETUP
+#line 86 "Pascal.l"
+{updatePos(); return GE;}
+ YY_BREAK
+case 17:
+YY_RULE_SETUP
+#line 87 "Pascal.l"
+{updatePos(); return GT;}
+ YY_BREAK
+case 18:
+YY_RULE_SETUP
+#line 88 "Pascal.l"
+{updatePos(); return LE;}
+ YY_BREAK
+case 19:
+YY_RULE_SETUP
+#line 89 "Pascal.l"
+{updatePos(); return LT;}
+ YY_BREAK
+case 20:
+YY_RULE_SETUP
+#line 90 "Pascal.l"
+{updatePos(); return EQUAL;}
+ YY_BREAK
+case 21:
+YY_RULE_SETUP
+#line 91 "Pascal.l"
+{updatePos(); return UNEQUAL;}
+ YY_BREAK
+case 22:
+YY_RULE_SETUP
+#line 92 "Pascal.l"
+{updatePos(); return ASSIGN;}
+ YY_BREAK
+case 23:
+YY_RULE_SETUP
+#line 93 "Pascal.l"
+{updatePos(); return PROGRAM;}
+ YY_BREAK
+case 24:
+YY_RULE_SETUP
+#line 94 "Pascal.l"
+{updatePos(); return CONST;}
+ YY_BREAK
+case 25:
+YY_RULE_SETUP
+#line 95 "Pascal.l"
+{updatePos(); return TYPE;}
+ YY_BREAK
+case 26:
+YY_RULE_SETUP
+#line 96 "Pascal.l"
+{updatePos(); return VAR;}
+ YY_BREAK
+case 27:
+YY_RULE_SETUP
+#line 97 "Pascal.l"
+{updatePos(); return ARRAY;}
+ YY_BREAK
+case 28:
+YY_RULE_SETUP
+#line 98 "Pascal.l"
+{updatePos(); return OF;}
+ YY_BREAK
+case 29:
+YY_RULE_SETUP
+#line 99 "Pascal.l"
+{updatePos(); return RECORD;}
+ YY_BREAK
+case 30:
+YY_RULE_SETUP
+#line 100 "Pascal.l"
+{updatePos(); return END;}
+ YY_BREAK
+case 31:
+YY_RULE_SETUP
+#line 101 "Pascal.l"
+{updatePos(); return FUNCTION;}
+ YY_BREAK
+case 32:
+YY_RULE_SETUP
+#line 102 "Pascal.l"
+{updatePos(); return PROCEDURE;}
+ YY_BREAK
+case 33:
+YY_RULE_SETUP
+#line 103 "Pascal.l"
+{updatePos(); return BEGIN_T;}
+ YY_BREAK
+case 34:
+YY_RULE_SETUP
+#line 104 "Pascal.l"
+{updatePos(); return READ;}
+ YY_BREAK
+case 35:
+YY_RULE_SETUP
+#line 105 "Pascal.l"
+{updatePos(); return IF;}
+ YY_BREAK
+case 36:
+YY_RULE_SETUP
+#line 106 "Pascal.l"
+{updatePos(); return THEN;}
+ YY_BREAK
+case 37:
+YY_RULE_SETUP
+#line 107 "Pascal.l"
+{updatePos(); return ELSE;}
+ YY_BREAK
+case 38:
+YY_RULE_SETUP
+#line 108 "Pascal.l"
+{updatePos(); return REPEAT;}
+ YY_BREAK
+case 39:
+YY_RULE_SETUP
+#line 109 "Pascal.l"
+{updatePos(); return UNTIL;}
+ YY_BREAK
+case 40:
+YY_RULE_SETUP
+#line 110 "Pascal.l"
+{updatePos(); return WHILE;}
+ YY_BREAK
+case 41:
+YY_RULE_SETUP
+#line 111 "Pascal.l"
+{updatePos(); return DO;}
+ YY_BREAK
+case 42:
+YY_RULE_SETUP
+#line 112 "Pascal.l"
+{updatePos(); return FOR;}
+ YY_BREAK
+case 43:
+YY_RULE_SETUP
+#line 113 "Pascal.l"
+{updatePos(); return TO;}
+ YY_BREAK
+case 44:
+YY_RULE_SETUP
+#line 114 "Pascal.l"
+{updatePos(); return DOWNTO;}
+ YY_BREAK
+case 45:
+YY_RULE_SETUP
+#line 115 "Pascal.l"
+{updatePos(); return CASE;}
+ YY_BREAK
+case 46:
+YY_RULE_SETUP
+#line 116 "Pascal.l"
+{updatePos(); return GOTO;}
+ YY_BREAK
+case 47:
+YY_RULE_SETUP
+#line 117 "Pascal.l"
+{updatePos(); return AND;}
+ YY_BREAK
+case 48:
+YY_RULE_SETUP
+#line 118 "Pascal.l"
+{updatePos(); return OR;}
+ YY_BREAK
+case 49:
+YY_RULE_SETUP
+#line 119 "Pascal.l"
+{updatePos(); return NOT;}
+ YY_BREAK
+case 50:
+YY_RULE_SETUP
+#line 120 "Pascal.l"
+{updatePos(); yylval.sval = yytext; return ID;}
+ YY_BREAK
+case 51:
+YY_RULE_SETUP
+#line 121 "Pascal.l"
+{
+ updatePos();
+ int getNum;
+ sscanf(yytext, "%d", &getNum);
+ yylval.ival = getNum;
+ return INTEGER;
+}
+ YY_BREAK
+case 52:
+YY_RULE_SETUP
+#line 128 "Pascal.l"
+{
+ updatePos();
+ double getNum;
+ sscanf(yytext, "%lf", &getNum);
+ yylval.rval = getNum;
+ return REAL;
+}
+ YY_BREAK
+case 53:
+YY_RULE_SETUP
+#line 136 "Pascal.l"
+{ updatePos(); yylval.cval = yytext[1]; return CHAR; }
+ YY_BREAK
+case 54:
+YY_RULE_SETUP
+#line 137 "Pascal.l"
+{ updatePos(); yylval.sval = yytext+1; yytext[strlen(yytext)-1] = 0; return STRING; }
+ YY_BREAK
+case 55:
+YY_RULE_SETUP
+#line 139 "Pascal.l"
+{updatePos(); return SYS_CON;}
+ YY_BREAK
+case 56:
+YY_RULE_SETUP
+#line 140 "Pascal.l"
+{updatePos(); return SYS_FUNCT;}
+ YY_BREAK
+case 57:
+YY_RULE_SETUP
+#line 141 "Pascal.l"
+{updatePos(); return SYS_PROC;}
+ YY_BREAK
+case 58:
+YY_RULE_SETUP
+#line 142 "Pascal.l"
+{updatePos(); return SYS_TYPE;}
+ YY_BREAK
+case 59:
+YY_RULE_SETUP
+#line 143 "Pascal.l"
+{updatePos(); EM_newline();}
+ YY_BREAK
+case 60:
+YY_RULE_SETUP
+#line 144 "Pascal.l"
+{updatePos(); EM_newline();}
+ YY_BREAK
+case 61:
+YY_RULE_SETUP
+#line 145 "Pascal.l"
+{}
+ YY_BREAK
+case 62:
+YY_RULE_SETUP
+#line 146 "Pascal.l"
+{for(int i = 1; iyy_buffer_status == YY_BUFFER_NEW )
+ {
+ /* We're scanning a new file or input source. It's
+ * possible that this happened because the user
+ * just pointed yyin at a new source and called
+ * yylex(). If so, then we have to assure
+ * consistency between yy_current_buffer and our
+ * globals. Here is the right place to do so, because
+ * this is the first action (other than possibly a
+ * back-up) that will match for the new input source.
+ */
+ yy_n_chars = yy_current_buffer->yy_n_chars;
+ yy_current_buffer->yy_input_file = yyin;
+ yy_current_buffer->yy_buffer_status = YY_BUFFER_NORMAL;
+ }
+
+ /* Note that here we test for yy_c_buf_p "<=" to the position
+ * of the first EOB in the buffer, since yy_c_buf_p will
+ * already have been incremented past the NUL character
+ * (since all states make transitions on EOB to the
+ * end-of-buffer state). Contrast this with the test
+ * in input().
+ */
+ if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] )
+ { /* This was really a NUL. */
+ yy_state_type yy_next_state;
+
+ yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state();
+
+ /* Okay, we're now positioned to make the NUL
+ * transition. We couldn't have
+ * yy_get_previous_state() go ahead and do it
+ * for us because it doesn't know how to deal
+ * with the possibility of jamming (and we don't
+ * want to build jamming into it because then it
+ * will run more slowly).
+ */
+
+ yy_next_state = yy_try_NUL_trans( yy_current_state );
+
+ yy_bp = yytext_ptr + YY_MORE_ADJ;
+
+ if ( yy_next_state )
+ {
+ /* Consume the NUL. */
+ yy_cp = ++yy_c_buf_p;
+ yy_current_state = yy_next_state;
+ goto yy_match;
+ }
+
+ else
+ {
+ yy_cp = yy_c_buf_p;
+ goto yy_find_action;
+ }
+ }
+
+ else switch ( yy_get_next_buffer() )
+ {
+ case EOB_ACT_END_OF_FILE:
+ {
+ yy_did_buffer_switch_on_eof = 0;
+
+ if ( yywrap() )
+ {
+ /* Note: because we've taken care in
+ * yy_get_next_buffer() to have set up
+ * yytext, we can now set up
+ * yy_c_buf_p so that if some total
+ * hoser (like flex itself) wants to
+ * call the scanner after we return the
+ * YY_NULL, it'll still work - another
+ * YY_NULL will get returned.
+ */
+ yy_c_buf_p = yytext_ptr + YY_MORE_ADJ;
+
+ yy_act = YY_STATE_EOF(YY_START);
+ goto do_action;
+ }
+
+ else
+ {
+ if ( ! yy_did_buffer_switch_on_eof )
+ YY_NEW_FILE;
+ }
+ break;
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ yy_c_buf_p =
+ yytext_ptr + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state();
+
+ yy_cp = yy_c_buf_p;
+ yy_bp = yytext_ptr + YY_MORE_ADJ;
+ goto yy_match;
+
+ case EOB_ACT_LAST_MATCH:
+ yy_c_buf_p =
+ &yy_current_buffer->yy_ch_buf[yy_n_chars];
+
+ yy_current_state = yy_get_previous_state();
+
+ yy_cp = yy_c_buf_p;
+ yy_bp = yytext_ptr + YY_MORE_ADJ;
+ goto yy_find_action;
+ }
+ break;
+ }
+
+ default:
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--no action found" );
+ } /* end of action switch */
+ } /* end of scanning one token */
+ } /* end of yylex */
+
+
+/* yy_get_next_buffer - try to read in a new buffer
+ *
+ * Returns a code representing an action:
+ * EOB_ACT_LAST_MATCH -
+ * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
+ * EOB_ACT_END_OF_FILE - end of file
+ */
+
+static int yy_get_next_buffer()
+ {
+ register char *dest = yy_current_buffer->yy_ch_buf;
+ register char *source = yytext_ptr;
+ register int number_to_move, i;
+ int ret_val;
+
+ if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] )
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--end of buffer missed" );
+
+ if ( yy_current_buffer->yy_fill_buffer == 0 )
+ { /* Don't try to fill the buffer, so this is an EOF. */
+ if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 )
+ {
+ /* We matched a single character, the EOB, so
+ * treat this as a final EOF.
+ */
+ return EOB_ACT_END_OF_FILE;
+ }
+
+ else
+ {
+ /* We matched some text prior to the EOB, first
+ * process it.
+ */
+ return EOB_ACT_LAST_MATCH;
+ }
+ }
+
+ /* Try to read more data. */
+
+ /* First move last chars to start of buffer. */
+ number_to_move = (int) (yy_c_buf_p - yytext_ptr) - 1;
+
+ for ( i = 0; i < number_to_move; ++i )
+ *(dest++) = *(source++);
+
+ if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_EOF_PENDING )
+ /* don't do the read, it's not guaranteed to return an EOF,
+ * just force an EOF
+ */
+ yy_current_buffer->yy_n_chars = yy_n_chars = 0;
+
+ else
+ {
+ int num_to_read =
+ yy_current_buffer->yy_buf_size - number_to_move - 1;
+
+ while ( num_to_read <= 0 )
+ { /* Not enough room in the buffer - grow it. */
+#ifdef YY_USES_REJECT
+ YY_FATAL_ERROR(
+"input buffer overflow, can't enlarge buffer because scanner uses REJECT" );
+#else
+
+ /* just a shorter name for the current buffer */
+ YY_BUFFER_STATE b = yy_current_buffer;
+
+ int yy_c_buf_p_offset =
+ (int) (yy_c_buf_p - b->yy_ch_buf);
+
+ if ( b->yy_is_our_buffer )
+ {
+ int new_size = b->yy_buf_size * 2;
+
+ if ( new_size <= 0 )
+ b->yy_buf_size += b->yy_buf_size / 8;
+ else
+ b->yy_buf_size *= 2;
+
+ b->yy_ch_buf = (char *)
+ /* Include room in for 2 EOB chars. */
+ yy_flex_realloc( (void *) b->yy_ch_buf,
+ b->yy_buf_size + 2 );
+ }
+ else
+ /* Can't grow it, we don't own it. */
+ b->yy_ch_buf = 0;
+
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR(
+ "fatal error - scanner input buffer overflow" );
+
+ yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
+
+ num_to_read = yy_current_buffer->yy_buf_size -
+ number_to_move - 1;
+#endif
+ }
+
+ if ( num_to_read > YY_READ_BUF_SIZE )
+ num_to_read = YY_READ_BUF_SIZE;
+
+ /* Read in more data. */
+ YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]),
+ yy_n_chars, num_to_read );
+
+ yy_current_buffer->yy_n_chars = yy_n_chars;
+ }
+
+ if ( yy_n_chars == 0 )
+ {
+ if ( number_to_move == YY_MORE_ADJ )
+ {
+ ret_val = EOB_ACT_END_OF_FILE;
+ yyrestart( yyin );
+ }
+
+ else
+ {
+ ret_val = EOB_ACT_LAST_MATCH;
+ yy_current_buffer->yy_buffer_status =
+ YY_BUFFER_EOF_PENDING;
+ }
+ }
+
+ else
+ ret_val = EOB_ACT_CONTINUE_SCAN;
+
+ yy_n_chars += number_to_move;
+ yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
+ yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
+
+ yytext_ptr = &yy_current_buffer->yy_ch_buf[0];
+
+ return ret_val;
+ }
+
+
+/* yy_get_previous_state - get the state just before the EOB char was reached */
+
+static yy_state_type yy_get_previous_state()
+ {
+ register yy_state_type yy_current_state;
+ register char *yy_cp;
+
+ yy_current_state = yy_start;
+
+ for ( yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp )
+ {
+ register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
+ if ( yy_accept[yy_current_state] )
+ {
+ yy_last_accepting_state = yy_current_state;
+ yy_last_accepting_cpos = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 203 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ }
+
+ return yy_current_state;
+ }
+
+
+/* yy_try_NUL_trans - try to make a transition on the NUL character
+ *
+ * synopsis
+ * next_state = yy_try_NUL_trans( current_state );
+ */
+
+#ifdef YY_USE_PROTOS
+static yy_state_type yy_try_NUL_trans( yy_state_type yy_current_state )
+#else
+static yy_state_type yy_try_NUL_trans( yy_current_state )
+yy_state_type yy_current_state;
+#endif
+ {
+ register int yy_is_jam;
+ register char *yy_cp = yy_c_buf_p;
+
+ register YY_CHAR yy_c = 1;
+ if ( yy_accept[yy_current_state] )
+ {
+ yy_last_accepting_state = yy_current_state;
+ yy_last_accepting_cpos = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 203 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ yy_is_jam = (yy_current_state == 202);
+
+ return yy_is_jam ? 0 : yy_current_state;
+ }
+
+
+#ifndef YY_NO_UNPUT
+#ifdef YY_USE_PROTOS
+static void yyunput( int c, register char *yy_bp )
+#else
+static void yyunput( c, yy_bp )
+int c;
+register char *yy_bp;
+#endif
+ {
+ register char *yy_cp = yy_c_buf_p;
+
+ /* undo effects of setting up yytext */
+ *yy_cp = yy_hold_char;
+
+ if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
+ { /* need to shift things up to make room */
+ /* +2 for EOB chars. */
+ register int number_to_move = yy_n_chars + 2;
+ register char *dest = &yy_current_buffer->yy_ch_buf[
+ yy_current_buffer->yy_buf_size + 2];
+ register char *source =
+ &yy_current_buffer->yy_ch_buf[number_to_move];
+
+ while ( source > yy_current_buffer->yy_ch_buf )
+ *--dest = *--source;
+
+ yy_cp += (int) (dest - source);
+ yy_bp += (int) (dest - source);
+ yy_current_buffer->yy_n_chars =
+ yy_n_chars = yy_current_buffer->yy_buf_size;
+
+ if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
+ YY_FATAL_ERROR( "flex scanner push-back overflow" );
+ }
+
+ *--yy_cp = (char) c;
+
+
+ yytext_ptr = yy_bp;
+ yy_hold_char = *yy_cp;
+ yy_c_buf_p = yy_cp;
+ }
+#endif /* ifndef YY_NO_UNPUT */
+
+
+#ifdef __cplusplus
+static int yyinput()
+#else
+static int input()
+#endif
+ {
+ int c;
+
+ *yy_c_buf_p = yy_hold_char;
+
+ if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
+ {
+ /* yy_c_buf_p now points to the character we want to return.
+ * If this occurs *before* the EOB characters, then it's a
+ * valid NUL; if not, then we've hit the end of the buffer.
+ */
+ if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] )
+ /* This was really a NUL. */
+ *yy_c_buf_p = '\0';
+
+ else
+ { /* need more input */
+ int offset = yy_c_buf_p - yytext_ptr;
+ ++yy_c_buf_p;
+
+ switch ( yy_get_next_buffer() )
+ {
+ case EOB_ACT_LAST_MATCH:
+ /* This happens because yy_g_n_b()
+ * sees that we've accumulated a
+ * token and flags that we need to
+ * try matching the token before
+ * proceeding. But for input(),
+ * there's no matching to consider.
+ * So convert the EOB_ACT_LAST_MATCH
+ * to EOB_ACT_END_OF_FILE.
+ */
+
+ /* Reset buffer status. */
+ yyrestart( yyin );
+
+ /* fall through */
+
+ case EOB_ACT_END_OF_FILE:
+ {
+ if ( yywrap() )
+ return EOF;
+
+ if ( ! yy_did_buffer_switch_on_eof )
+ YY_NEW_FILE;
+#ifdef __cplusplus
+ return yyinput();
+#else
+ return input();
+#endif
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ yy_c_buf_p = yytext_ptr + offset;
+ break;
+ }
+ }
+ }
+
+ c = *(unsigned char *) yy_c_buf_p; /* cast for 8-bit char's */
+ *yy_c_buf_p = '\0'; /* preserve yytext */
+ yy_hold_char = *++yy_c_buf_p;
+
+
+ return c;
+ }
+
+
+#ifdef YY_USE_PROTOS
+void yyrestart( FILE *input_file )
+#else
+void yyrestart( input_file )
+FILE *input_file;
+#endif
+ {
+ if ( ! yy_current_buffer )
+ yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE );
+
+ yy_init_buffer( yy_current_buffer, input_file );
+ yy_load_buffer_state();
+ }
+
+
+#ifdef YY_USE_PROTOS
+void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer )
+#else
+void yy_switch_to_buffer( new_buffer )
+YY_BUFFER_STATE new_buffer;
+#endif
+ {
+ if ( yy_current_buffer == new_buffer )
+ return;
+
+ if ( yy_current_buffer )
+ {
+ /* Flush out information for old buffer. */
+ *yy_c_buf_p = yy_hold_char;
+ yy_current_buffer->yy_buf_pos = yy_c_buf_p;
+ yy_current_buffer->yy_n_chars = yy_n_chars;
+ }
+
+ yy_current_buffer = new_buffer;
+ yy_load_buffer_state();
+
+ /* We don't actually know whether we did this switch during
+ * EOF (yywrap()) processing, but the only time this flag
+ * is looked at is after yywrap() is called, so it's safe
+ * to go ahead and always set it.
+ */
+ yy_did_buffer_switch_on_eof = 1;
+ }
+
+
+#ifdef YY_USE_PROTOS
+void yy_load_buffer_state( void )
+#else
+void yy_load_buffer_state()
+#endif
+ {
+ yy_n_chars = yy_current_buffer->yy_n_chars;
+ yytext_ptr = yy_c_buf_p = yy_current_buffer->yy_buf_pos;
+ yyin = yy_current_buffer->yy_input_file;
+ yy_hold_char = *yy_c_buf_p;
+ }
+
+
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_create_buffer( FILE *file, int size )
+#else
+YY_BUFFER_STATE yy_create_buffer( file, size )
+FILE *file;
+int size;
+#endif
+ {
+ YY_BUFFER_STATE b;
+
+ b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
+
+ b->yy_buf_size = size;
+
+ /* yy_ch_buf has to be 2 characters longer than the size given because
+ * we need to put in 2 end-of-buffer characters.
+ */
+ b->yy_ch_buf = (char *) yy_flex_alloc( b->yy_buf_size + 2 );
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
+
+ b->yy_is_our_buffer = 1;
+
+ yy_init_buffer( b, file );
+
+ return b;
+ }
+
+
+#ifdef YY_USE_PROTOS
+void yy_delete_buffer( YY_BUFFER_STATE b )
+#else
+void yy_delete_buffer( b )
+YY_BUFFER_STATE b;
+#endif
+ {
+ if ( ! b )
+ return;
+
+ if ( b == yy_current_buffer )
+ yy_current_buffer = (YY_BUFFER_STATE) 0;
+
+ if ( b->yy_is_our_buffer )
+ yy_flex_free( (void *) b->yy_ch_buf );
+
+ yy_flex_free( (void *) b );
+ }
+
+
+#ifndef YY_ALWAYS_INTERACTIVE
+#ifndef YY_NEVER_INTERACTIVE
+extern int isatty YY_PROTO(( int ));
+#endif
+#endif
+
+#ifdef YY_USE_PROTOS
+void yy_init_buffer( YY_BUFFER_STATE b, FILE *file )
+#else
+void yy_init_buffer( b, file )
+YY_BUFFER_STATE b;
+FILE *file;
+#endif
+
+
+ {
+ yy_flush_buffer( b );
+
+ b->yy_input_file = file;
+ b->yy_fill_buffer = 1;
+
+#if YY_ALWAYS_INTERACTIVE
+ b->yy_is_interactive = 1;
+#else
+#if YY_NEVER_INTERACTIVE
+ b->yy_is_interactive = 0;
+#else
+ b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
+#endif
+#endif
+ }
+
+
+#ifdef YY_USE_PROTOS
+void yy_flush_buffer( YY_BUFFER_STATE b )
+#else
+void yy_flush_buffer( b )
+YY_BUFFER_STATE b;
+#endif
+
+ {
+ if ( ! b )
+ return;
+
+ b->yy_n_chars = 0;
+
+ /* We always need two end-of-buffer characters. The first causes
+ * a transition to the end-of-buffer state. The second causes
+ * a jam in that state.
+ */
+ b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
+ b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
+
+ b->yy_buf_pos = &b->yy_ch_buf[0];
+
+ b->yy_at_bol = 1;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ if ( b == yy_current_buffer )
+ yy_load_buffer_state();
+ }
+
+
+#ifndef YY_NO_SCAN_BUFFER
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_scan_buffer( char *base, yy_size_t size )
+#else
+YY_BUFFER_STATE yy_scan_buffer( base, size )
+char *base;
+yy_size_t size;
+#endif
+ {
+ YY_BUFFER_STATE b;
+
+ if ( size < 2 ||
+ base[size-2] != YY_END_OF_BUFFER_CHAR ||
+ base[size-1] != YY_END_OF_BUFFER_CHAR )
+ /* They forgot to leave room for the EOB's. */
+ return 0;
+
+ b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
+
+ b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
+ b->yy_buf_pos = b->yy_ch_buf = base;
+ b->yy_is_our_buffer = 0;
+ b->yy_input_file = 0;
+ b->yy_n_chars = b->yy_buf_size;
+ b->yy_is_interactive = 0;
+ b->yy_at_bol = 1;
+ b->yy_fill_buffer = 0;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ yy_switch_to_buffer( b );
+
+ return b;
+ }
+#endif
+
+
+#ifndef YY_NO_SCAN_STRING
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_scan_string( yyconst char *yy_str )
+#else
+YY_BUFFER_STATE yy_scan_string( yy_str )
+yyconst char *yy_str;
+#endif
+ {
+ int len;
+ for ( len = 0; yy_str[len]; ++len )
+ ;
+
+ return yy_scan_bytes( yy_str, len );
+ }
+#endif
+
+
+#ifndef YY_NO_SCAN_BYTES
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_scan_bytes( yyconst char *bytes, int len )
+#else
+YY_BUFFER_STATE yy_scan_bytes( bytes, len )
+yyconst char *bytes;
+int len;
+#endif
+ {
+ YY_BUFFER_STATE b;
+ char *buf;
+ yy_size_t n;
+ int i;
+
+ /* Get memory for full buffer, including space for trailing EOB's. */
+ n = len + 2;
+ buf = (char *) yy_flex_alloc( n );
+ if ( ! buf )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
+
+ for ( i = 0; i < len; ++i )
+ buf[i] = bytes[i];
+
+ buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR;
+
+ b = yy_scan_buffer( buf, n );
+ if ( ! b )
+ YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
+
+ /* It's okay to grow etc. this buffer, and we should throw it
+ * away when we're done.
+ */
+ b->yy_is_our_buffer = 1;
+
+ return b;
+ }
+#endif
+
+
+#ifndef YY_NO_PUSH_STATE
+#ifdef YY_USE_PROTOS
+static void yy_push_state( int new_state )
+#else
+static void yy_push_state( new_state )
+int new_state;
+#endif
+ {
+ if ( yy_start_stack_ptr >= yy_start_stack_depth )
+ {
+ yy_size_t new_size;
+
+ yy_start_stack_depth += YY_START_STACK_INCR;
+ new_size = yy_start_stack_depth * sizeof( int );
+
+ if ( ! yy_start_stack )
+ yy_start_stack = (int *) yy_flex_alloc( new_size );
+
+ else
+ yy_start_stack = (int *) yy_flex_realloc(
+ (void *) yy_start_stack, new_size );
+
+ if ( ! yy_start_stack )
+ YY_FATAL_ERROR(
+ "out of memory expanding start-condition stack" );
+ }
+
+ yy_start_stack[yy_start_stack_ptr++] = YY_START;
+
+ BEGIN(new_state);
+ }
+#endif
+
+
+#ifndef YY_NO_POP_STATE
+static void yy_pop_state()
+ {
+ if ( --yy_start_stack_ptr < 0 )
+ YY_FATAL_ERROR( "start-condition stack underflow" );
+
+ BEGIN(yy_start_stack[yy_start_stack_ptr]);
+ }
+#endif
+
+
+#ifndef YY_NO_TOP_STATE
+static int yy_top_state()
+ {
+ return yy_start_stack[yy_start_stack_ptr - 1];
+ }
+#endif
+
+#ifndef YY_EXIT_FAILURE
+#define YY_EXIT_FAILURE 2
+#endif
+
+#ifdef YY_USE_PROTOS
+static void yy_fatal_error( yyconst char msg[] )
+#else
+static void yy_fatal_error( msg )
+char msg[];
+#endif
+ {
+ (void) fprintf( stderr, "%s\n", msg );
+ exit( YY_EXIT_FAILURE );
+ }
+
+
+
+/* Redefine yyless() so it works in section 3 code. */
+
+#undef yyless
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ yytext[yyleng] = yy_hold_char; \
+ yy_c_buf_p = yytext + n; \
+ yy_hold_char = *yy_c_buf_p; \
+ *yy_c_buf_p = '\0'; \
+ yyleng = n; \
+ } \
+ while ( 0 )
+
+
+/* Internal utility routines. */
+
+#ifndef yytext_ptr
+#ifdef YY_USE_PROTOS
+static void yy_flex_strncpy( char *s1, yyconst char *s2, int n )
+#else
+static void yy_flex_strncpy( s1, s2, n )
+char *s1;
+yyconst char *s2;
+int n;
+#endif
+ {
+ register int i;
+ for ( i = 0; i < n; ++i )
+ s1[i] = s2[i];
+ }
+#endif
+
+#ifdef YY_NEED_STRLEN
+#ifdef YY_USE_PROTOS
+static int yy_flex_strlen( yyconst char *s )
+#else
+static int yy_flex_strlen( s )
+yyconst char *s;
+#endif
+ {
+ register int n;
+ for ( n = 0; s[n]; ++n )
+ ;
+
+ return n;
+ }
+#endif
+
+
+#ifdef YY_USE_PROTOS
+static void *yy_flex_alloc( yy_size_t size )
+#else
+static void *yy_flex_alloc( size )
+yy_size_t size;
+#endif
+ {
+ return (void *) malloc( size );
+ }
+
+#ifdef YY_USE_PROTOS
+static void *yy_flex_realloc( void *ptr, yy_size_t size )
+#else
+static void *yy_flex_realloc( ptr, size )
+void *ptr;
+yy_size_t size;
+#endif
+ {
+ /* The cast to (char *) in the following accommodates both
+ * implementations that use char* generic pointers, and those
+ * that use void* generic pointers. It works with the latter
+ * because both ANSI C and C++ allow castless assignment from
+ * any pointer type to void*, and deal with argument conversions
+ * as though doing an assignment.
+ */
+ return (void *) realloc( (char *) ptr, size );
+ }
+
+#ifdef YY_USE_PROTOS
+static void yy_flex_free( void *ptr )
+#else
+static void yy_flex_free( ptr )
+void *ptr;
+#endif
+ {
+ free( ptr );
+ }
+
+#if YY_MAIN
+int main()
+ {
+ yylex();
+ return 0;
+ }
+#endif
+#line 149 "Pascal.l"
+
+void updatePos(void) {
+ EM_tokPos = charPos;
+ charPos += yyleng;
+ for(int i = 0; i='A'&&yytext[i]<='Z')
+ yytext[i] = yytext[i]-'A'+'a';
+ }
+}
+int yywrap(){
+ charPos = 1;
+ return 1;
+}
\ No newline at end of file
diff --git a/CompilerPascal/main.c b/CompilerPascal/main.c
new file mode 100644
index 0000000..2831a8e
--- /dev/null
+++ b/CompilerPascal/main.c
@@ -0,0 +1,78 @@
+// tree root from paring
+#include "absyn.h"
+#include "prabsyn.h"
+#include "errormsg.h"
+#include "semant.h"
+#include "printtree.h"
+#include "drawtree.h"
+#include "canon.h"
+#include "escape.h"
+#include "frame.h"
+#include "assem.h"
+#include
+
+extern A_exp A_synTreeRoot;
+extern Temp_map F_tempMap;
+extern int yyparse(void);
+static void doProc(FILE* out, F_frame frame, T_stm body) {
+ // linearize and trace schedule
+ T_stmList stmList = C_linearize(body);
+ stmList = C_traceSchedule(C_basicBlocks(stmList));
+
+ fprintf(stdout, "\n------\n");
+ printStmList(stdout, stmList);
+ FILE* fileout = fopen("IRTree.dot", "w+");
+ if (!fileout)
+ return 0;
+ fprintf(stdout, "\n------\n");
+ drawStmList(fileout, stmList);
+ fclose(fileout);
+
+ AS_proc proc;
+ AS_instrList iList;
+ iList = F_codegen(frame, stmList);
+
+ fprintf(out, "BEGIN %s\n", Temp_labelstring(F_name(frame)));
+ AS_printInstrList(out, iList, Temp_layerMap(F_tempMap,Temp_name()));
+ fprintf(out, "END %s\n\n", Temp_labelstring(F_name(frame)));
+}
+
+int parse(string fname) {
+ // reset filename and line number
+ // open given file in the same time
+ EM_reset(fname);
+ int res = yyparse();
+ if (!res) {
+ } else {
+ printf("Syntax not passed! Please check your syntax.\n");
+ }
+ // restore stdin
+ fclose(stdin);
+ return res;
+}
+
+int main(int argc, char* argv[]) {
+ FILE* out = stdout;
+ if (argc < 2)
+ parse("test/1.pas");
+ else
+ parse(argv[1]);
+ fprintf(out, "\n---Abstract Syntax Tree---\n");
+ pr_exp(out, A_synTreeRoot, 0);
+ // find escape of variables
+ Esc_findEscape(A_synTreeRoot);
+
+ fprintf(out, "\n---IR Tree---\n");
+ F_fragList fragList = transProg(A_synTreeRoot);
+ T_stmList head = NULL, tail = NULL;
+
+ for (;fragList;fragList = fragList->tail) {
+ doProc(out, fragList->head->u.proc.frame, fragList->head->u.proc.body);
+ }
+
+
+ while (1) {
+ int r = 1;
+ }
+ return 0;
+}
\ No newline at end of file
diff --git a/src/mipsframe.c b/CompilerPascal/mipsframe.c
similarity index 79%
rename from src/mipsframe.c
rename to CompilerPascal/mipsframe.c
index 8ad3538..2b048e8 100644
--- a/src/mipsframe.c
+++ b/CompilerPascal/mipsframe.c
@@ -1,5 +1,6 @@
#include "frame.h"
#include "util.h"
+#include "temp.h"
const int F_wordSize = 4;
Temp_map F_tempMap = NULL;
@@ -11,7 +12,7 @@ static Temp_temp F_ra = NULL;
struct F_access_ {
enum {inFrame, inReg} kind;
union {
- int offset; /*in frame, offset from fp*/
+ struct { int offset; int size; } frame;/*in frame, offset from fp, occupy size in memory*/
Temp_temp reg; /*in reg, reg number*/
} u;
};
@@ -20,14 +21,15 @@ struct F_frame_ {
Temp_label name;
F_accessList formals;
F_accessList formalsTail;
- int localCount; /*local variables allocated so far*/
+ int ptrPos; /*local variables allocated in frame so far*/
};
// in frame
-static F_access InFrame(int offset) {
+static F_access InFrame(int offset, int size) {
F_access access = checked_malloc(sizeof(*access));
access->kind = inFrame;
- access->u.offset = offset;
+ access->u.frame.offset = offset;
+ access->u.frame.size = size;
return access;
}
@@ -47,13 +49,17 @@ F_accessList F_AccessList(F_access head, F_accessList tail) {
}
-F_frame F_newFrame(Temp_label name, U_boolList formals) {
+F_frame F_newFrame(Temp_label name, U_boolList formals, U_intList formalsSizes) {
F_frame f = checked_malloc(sizeof(*f));
f->name = name;
f->formalsTail = f->formals = NULL;
- for (;formals;formals = formals->tail) {
- F_allocLocal(f, formals->head);
+ f->ptrPos = 0;
+
+ for (;formals, formalsSizes;formals = formals->tail, formalsSizes = formalsSizes->tail) {
+ F_allocLocal(f, formals->head, formalsSizes->head);
}
+
+ return f;
}
Temp_label F_name(F_frame f) {
@@ -65,17 +71,19 @@ F_accessList F_formals(F_frame f) {
return f->formals;
}
-F_access F_allocLocal(F_frame f, bool escape) {
- f->localCount++;
- if (escape) {
+F_access F_allocLocal(F_frame f, bool escape, int size) {
+ // only calculate num of variables in frame
+ if (escape||size > 4) {
// allocate in frame
- F_access frameLocal = InFrame(-1*(f->localCount)*F_wordSize);
+ f->ptrPos -= size;
+ F_access frameLocal = InFrame(f->ptrPos, size);
if (!(f->formals)) {
f->formalsTail = f->formals = F_AccessList(frameLocal, NULL);
} else {
f->formalsTail->tail = F_AccessList(frameLocal, NULL);
f->formalsTail = f->formalsTail->tail;
}
+
return frameLocal;
}
else {
@@ -98,7 +106,7 @@ Temp_temp F_Fp(void) {
}
F_fp = Temp_newtemp();
- Temp_enter(F_tempMap, F_fp, "eax");
+ // Temp_enter(F_tempMap, F_fp, "eax");
return F_fp;
}
@@ -139,7 +147,7 @@ Temp_temp F_Ra(void) {
T_exp F_Exp(F_access access, T_exp framePtr) {
if (access->kind == inFrame)
// in frame, return T_mem
- return T_Mem(T_Binop(T_plus, framePtr, T_Const(access->u.offset)), F_wordSize);
+ return T_Mem(T_Binop(T_plus, framePtr, T_Const(access->u.frame.offset)), access->u.frame.size);
else
// in register, return T_temp
return T_Temp(access->u.reg);
diff --git a/CompilerPascal/pascal.tab.c b/CompilerPascal/pascal.tab.c
new file mode 100644
index 0000000..a969199
--- /dev/null
+++ b/CompilerPascal/pascal.tab.c
@@ -0,0 +1,1895 @@
+
+/* A Bison parser, made from pascal.y
+ by GNU Bison version 1.28 */
+
+#define YYBISON 1 /* Identify Bison output. */
+
+#define LP 257
+#define RP 258
+#define LB 259
+#define RB 260
+#define DOT 261
+#define COMMA 262
+#define COLON 263
+#define SEMI 264
+#define PLUS 265
+#define MINUS 266
+#define MUL 267
+#define REALDIV 268
+#define INTDIV 269
+#define MOD 270
+#define AND 271
+#define OR 272
+#define NOT 273
+#define GE 274
+#define GT 275
+#define LE 276
+#define LT 277
+#define EQUAL 278
+#define UNEQUAL 279
+#define ASSIGN 280
+#define PROGRAM 281
+#define FUNCTION 282
+#define PROCEDURE 283
+#define BEGIN_T 284
+#define END 285
+#define TYPE 286
+#define ARRAY 287
+#define OF 288
+#define RECORD 289
+#define VAR 290
+#define IF 291
+#define THEN 292
+#define ELSE 293
+#define REPEAT 294
+#define TO 295
+#define DOWNTO 296
+#define UNTIL 297
+#define WHILE 298
+#define DO 299
+#define FOR 300
+#define CASE 301
+#define GOTO 302
+#define READ 303
+#define CONST 304
+#define DOTDOT 305
+#define INTEGER 306
+#define REAL 307
+#define CHAR 308
+#define ID 309
+#define STRING 310
+#define SYS_CON 311
+#define SYS_FUNCT 312
+#define SYS_PROC 313
+#define SYS_TYPE 314
+
+#line 1 "pascal.y"
+
+
+#include
+#include "util.h"
+#include "errormsg.h"
+#include "symbol.h"
+#include "absyn.h"
+
+int yyerror(char* msg);
+int yylex(void);
+// root for parsed abstract syntax tree
+A_exp A_synTreeRoot;
+
+// helper function for constructing abstract tree
+// link fieldlists
+A_fieldList A_linkFieldList(A_fieldList front, A_fieldList tail);
+// set type for fieldlist
+A_fieldList A_setFieldListType(A_fieldList fieldList, A_ty ty);
+
+// link declists
+A_decList A_linkDecList(A_decList front, A_decList tail);
+// set type for declist
+A_decList A_setDecListType(A_decList decList, A_ty ty);
+
+// convert fieldlist to declist
+A_decList A_unDecList(A_fieldList fieldList);
+
+
+#line 39 "pascal.y"
+typedef union {
+ int pos;
+ int ival;
+ double rval;
+ char cval;
+ string sval;
+
+ A_var var;
+ A_exp exp;
+ S_symbol sym;
+ A_dec dec;
+ A_decList declist;
+ A_expList explist;
+ A_efieldList efieldlist;
+ A_ty ty;
+ A_fieldList fieldlist;
+ A_fundec fundec;
+ A_fundecList fundeclist;
+ A_namety namety;
+ A_nametyList nametylist;
+} YYSTYPE;
+#include
+
+#ifndef __cplusplus
+#ifndef __STDC__
+#define const
+#endif
+#endif
+
+
+
+#define YYFINAL 276
+#define YYFLAG -32768
+#define YYNTBASE 61
+
+#define YYTRANSLATE(x) ((unsigned)(x) <= 314 ? yytranslate[x] : 122)
+
+static const char yytranslate[] = { 0,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 1, 3, 4, 5, 6,
+ 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+ 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
+ 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
+ 37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
+ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
+ 57, 58, 59, 60
+};
+
+#if YYDEBUG != 0
+static const short yyprhs[] = { 0,
+ 0, 4, 8, 11, 17, 18, 21, 22, 28, 33,
+ 36, 38, 40, 42, 44, 46, 48, 51, 52, 55,
+ 57, 60, 62, 67, 69, 71, 73, 75, 77, 81,
+ 85, 90, 96, 100, 107, 111, 114, 116, 121, 125,
+ 127, 130, 131, 134, 136, 139, 141, 146, 149, 152,
+ 153, 158, 164, 169, 173, 176, 180, 181, 185, 187,
+ 191, 195, 198, 200, 202, 206, 210, 211, 214, 218,
+ 220, 222, 224, 226, 228, 230, 232, 234, 236, 238,
+ 242, 249, 255, 257, 262, 264, 269, 274, 280, 283,
+ 284, 289, 294, 303, 305, 307, 313, 316, 318, 323,
+ 328, 331, 335, 337, 341, 345, 349, 353, 357, 361,
+ 363, 367, 371, 375, 377, 381, 385, 389, 393, 397,
+ 399, 401, 406, 408, 413, 415, 419, 422, 425, 430,
+ 434, 438, 440, 442, 444, 446, 448, 450
+};
+
+static const short yyrhs[] = { 62,
+ 63, 7, 0, 27, 116, 10, 0, 64, 93, 0,
+ 65, 66, 69, 79, 82, 0, 0, 50, 67, 0,
+ 0, 116, 24, 68, 10, 67, 0, 116, 24, 68,
+ 10, 0, 121, 67, 0, 121, 0, 52, 0, 53,
+ 0, 54, 0, 56, 0, 117, 0, 32, 70, 0,
+ 0, 71, 70, 0, 71, 0, 121, 70, 0, 121,
+ 0, 116, 24, 72, 10, 0, 73, 0, 74, 0,
+ 75, 0, 120, 0, 116, 0, 3, 78, 4, 0,
+ 68, 51, 68, 0, 12, 68, 51, 68, 0, 12,
+ 68, 51, 12, 68, 0, 116, 51, 116, 0, 33,
+ 5, 73, 6, 34, 72, 0, 35, 76, 31, 0,
+ 77, 76, 0, 77, 0, 78, 9, 72, 10, 0,
+ 78, 8, 116, 0, 116, 0, 36, 80, 0, 0,
+ 81, 80, 0, 81, 0, 121, 80, 0, 121, 0,
+ 78, 9, 72, 10, 0, 83, 82, 0, 85, 82,
+ 0, 0, 84, 10, 87, 10, 0, 28, 116, 88,
+ 9, 73, 0, 86, 10, 87, 10, 0, 29, 116,
+ 88, 0, 64, 93, 0, 3, 89, 4, 0, 0,
+ 89, 10, 90, 0, 90, 0, 91, 9, 73, 0,
+ 92, 9, 73, 0, 36, 78, 0, 78, 0, 94,
+ 0, 30, 95, 31, 0, 96, 10, 95, 0, 0,
+ 121, 95, 0, 52, 9, 97, 0, 97, 0, 98,
+ 0, 99, 0, 94, 0, 100, 0, 102, 0, 103,
+ 0, 104, 0, 106, 0, 109, 0, 116, 26, 111,
+ 0, 116, 5, 111, 6, 26, 111, 0, 116, 7,
+ 116, 26, 111, 0, 116, 0, 116, 3, 115, 4,
+ 0, 119, 0, 119, 3, 110, 4, 0, 49, 3,
+ 114, 4, 0, 37, 111, 38, 96, 101, 0, 39,
+ 96, 0, 0, 40, 96, 43, 111, 0, 44, 111,
+ 45, 96, 0, 46, 116, 26, 111, 105, 111, 45,
+ 96, 0, 41, 0, 42, 0, 47, 111, 34, 107,
+ 31, 0, 108, 107, 0, 108, 0, 68, 9, 96,
+ 10, 0, 116, 9, 96, 10, 0, 48, 52, 0,
+ 111, 8, 110, 0, 111, 0, 111, 20, 112, 0,
+ 111, 21, 112, 0, 111, 22, 112, 0, 111, 23,
+ 112, 0, 111, 24, 112, 0, 111, 25, 112, 0,
+ 112, 0, 112, 11, 113, 0, 112, 12, 113, 0,
+ 112, 18, 113, 0, 113, 0, 113, 13, 114, 0,
+ 113, 15, 114, 0, 113, 14, 114, 0, 113, 16,
+ 114, 0, 113, 17, 114, 0, 114, 0, 116, 0,
+ 116, 3, 115, 4, 0, 118, 0, 118, 3, 115,
+ 4, 0, 68, 0, 3, 111, 4, 0, 19, 114,
+ 0, 12, 114, 0, 116, 5, 111, 6, 0, 116,
+ 7, 116, 0, 115, 8, 111, 0, 111, 0, 55,
+ 0, 57, 0, 58, 0, 59, 0, 60, 0, 1,
+ 10, 0
+};
+
+#endif
+
+#if YYDEBUG != 0
+static const short yyrline[] = { 0,
+ 81, 82, 83, 84, 98, 101, 102, 103, 104, 105,
+ 106, 107, 108, 109, 110, 111, 114, 115, 116, 117,
+ 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+ 128, 129, 130, 131, 132, 134, 135, 136, 137, 138,
+ 141, 142, 143, 144, 145, 146, 147, 150, 151, 152,
+ 154, 155, 156, 157, 158, 159, 160, 161, 162, 163,
+ 164, 165, 166, 169, 170, 171, 172, 173, 174, 175,
+ 176, 177, 178, 179, 180, 181, 182, 183, 184, 185,
+ 186, 187, 188, 189, 190, 191, 192, 193, 194, 195,
+ 196, 198, 199, 209, 210, 211, 212, 213, 214, 215,
+ 216, 218, 219, 220, 221, 222, 223, 224, 225, 226,
+ 228, 229, 230, 231, 232, 233, 234, 235, 236, 237,
+ 238, 239, 240, 241, 242, 243, 244, 245, 246, 247,
+ 248, 249, 251, 252, 253, 254, 255, 257
+};
+#endif
+
+
+#if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
+
+static const char * const yytname[] = { "$","error","$undefined.","LP","RP",
+"LB","RB","DOT","COMMA","COLON","SEMI","PLUS","MINUS","MUL","REALDIV","INTDIV",
+"MOD","AND","OR","NOT","GE","GT","LE","LT","EQUAL","UNEQUAL","ASSIGN","PROGRAM",
+"FUNCTION","PROCEDURE","BEGIN_T","END","TYPE","ARRAY","OF","RECORD","VAR","IF",
+"THEN","ELSE","REPEAT","TO","DOWNTO","UNTIL","WHILE","DO","FOR","CASE","GOTO",
+"READ","CONST","DOTDOT","INTEGER","REAL","CHAR","ID","STRING","SYS_CON","SYS_FUNCT",
+"SYS_PROC","SYS_TYPE","program","program_head","routine","routine_head","label_part",
+"const_part","const_expr_list","const_value","type_part","type_decl_list","type_definition",
+"type_decl","simple_type_decl","array_type_decl","record_type_decl","field_decl_list",
+"field_decl","name_list","var_part","var_decl_list","var_decl","routine_part",
+"function_decl","function_head","procedure_decl","procedure_head","sub_routine",
+"parameters","para_decl_list","para_type_list","var_para_list","val_para_list",
+"routine_body","compound_stmt","stmt_list","stmt","non_label_stmt","assign_stmt",
+"proc_stmt","if_stmt","else_clause","repeat_stmt","while_stmt","for_stmt","direction",
+"case_stmt","case_expr_list","case_expr","goto_stmt","expression_list","expression",
+"expr","term","factor","args_list","id","sys_con","sys_funct","sys_proc","sys_type",
+"error_stmt", NULL
+};
+#endif
+
+static const short yyr1[] = { 0,
+ 61, 62, 63, 64, 65, 66, 66, 67, 67, 67,
+ 67, 68, 68, 68, 68, 68, 69, 69, 70, 70,
+ 70, 70, 71, 72, 72, 72, 73, 73, 73, 73,
+ 73, 73, 73, 74, 75, 76, 76, 77, 78, 78,
+ 79, 79, 80, 80, 80, 80, 81, 82, 82, 82,
+ 83, 84, 85, 86, 87, 88, 88, 89, 89, 90,
+ 90, 91, 92, 93, 94, 95, 95, 95, 96, 96,
+ 97, 97, 97, 97, 97, 97, 97, 97, 97, 98,
+ 98, 98, 99, 99, 99, 99, 99, 100, 101, 101,
+ 102, 103, 104, 105, 105, 106, 107, 107, 108, 108,
+ 109, 110, 110, 111, 111, 111, 111, 111, 111, 111,
+ 112, 112, 112, 112, 113, 113, 113, 113, 113, 113,
+ 114, 114, 114, 114, 114, 114, 114, 114, 114, 114,
+ 115, 115, 116, 117, 118, 119, 120, 121
+};
+
+static const short yyr2[] = { 0,
+ 3, 3, 2, 5, 0, 2, 0, 5, 4, 2,
+ 1, 1, 1, 1, 1, 1, 2, 0, 2, 1,
+ 2, 1, 4, 1, 1, 1, 1, 1, 3, 3,
+ 4, 5, 3, 6, 3, 2, 1, 4, 3, 1,
+ 2, 0, 2, 1, 2, 1, 4, 2, 2, 0,
+ 4, 5, 4, 3, 2, 3, 0, 3, 1, 3,
+ 3, 2, 1, 1, 3, 3, 0, 2, 3, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 3,
+ 6, 5, 1, 4, 1, 4, 4, 5, 2, 0,
+ 4, 4, 8, 1, 1, 5, 2, 1, 4, 4,
+ 2, 3, 1, 3, 3, 3, 3, 3, 3, 1,
+ 3, 3, 3, 1, 3, 3, 3, 3, 3, 1,
+ 1, 4, 1, 4, 1, 3, 2, 2, 4, 3,
+ 3, 1, 1, 1, 1, 1, 1, 2
+};
+
+static const short yydefact[] = { 0,
+ 0, 5, 133, 0, 0, 0, 7, 2, 1, 0,
+ 3, 64, 0, 18, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 136, 73, 0, 0, 70, 71, 72,
+ 74, 75, 76, 77, 78, 79, 83, 85, 0, 6,
+ 0, 0, 0, 42, 138, 0, 0, 0, 12, 13,
+ 14, 15, 134, 135, 125, 0, 110, 114, 120, 121,
+ 16, 123, 0, 0, 0, 0, 101, 0, 0, 65,
+ 0, 0, 0, 0, 0, 0, 68, 0, 10, 17,
+ 0, 0, 0, 0, 50, 0, 128, 127, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 69, 66, 132, 0, 0, 0, 80, 0,
+ 103, 0, 19, 0, 21, 0, 41, 0, 40, 0,
+ 0, 0, 4, 50, 0, 50, 0, 126, 104, 105,
+ 106, 107, 108, 109, 90, 111, 112, 113, 115, 117,
+ 116, 118, 119, 0, 0, 130, 0, 91, 92, 0,
+ 0, 0, 98, 0, 87, 84, 0, 0, 0, 86,
+ 0, 0, 0, 0, 0, 0, 137, 0, 0, 24,
+ 25, 26, 28, 27, 0, 0, 43, 45, 57, 57,
+ 48, 5, 49, 5, 0, 88, 122, 129, 124, 94,
+ 95, 0, 0, 96, 97, 0, 131, 0, 82, 102,
+ 8, 0, 0, 0, 0, 37, 0, 0, 23, 0,
+ 39, 0, 0, 0, 54, 0, 0, 0, 89, 0,
+ 0, 0, 81, 29, 0, 0, 35, 36, 0, 30,
+ 33, 47, 0, 63, 0, 59, 0, 0, 0, 55,
+ 51, 53, 0, 99, 100, 0, 31, 0, 0, 62,
+ 56, 0, 0, 0, 52, 93, 32, 0, 38, 58,
+ 60, 61, 34, 0, 0, 0
+};
+
+static const short yydefgoto[] = { 274,
+ 2, 5, 226, 7, 14, 40, 55, 44, 80, 81,
+ 179, 180, 181, 182, 215, 216, 126, 85, 127, 128,
+ 133, 134, 135, 136, 137, 227, 224, 245, 246, 247,
+ 248, 11, 25, 26, 27, 28, 29, 30, 31, 196,
+ 32, 33, 34, 202, 35, 162, 163, 36, 120, 115,
+ 57, 58, 59, 116, 60, 61, 62, 38, 184, 39
+};
+
+static const short yypact[] = { -20,
+ -42,-32768,-32768, 24, 37, 41, 4,-32768,-32768, 228,
+-32768,-32768, 14, 70, 86, 252, 284, 252, -42, 252,
+ 62, 106, 116,-32768,-32768, 97, 131,-32768,-32768,-32768,
+-32768,-32768,-32768,-32768,-32768,-32768, 130, 146, 228,-32768,
+ 136, 3, 14, 119,-32768, 252, 252, 252,-32768,-32768,
+-32768,-32768,-32768,-32768,-32768, 388, 95, 275,-32768, 40,
+-32768, 155, 126, 5, 147, 399,-32768, 252, 304,-32768,
+ 228, 252, 252, -42, 252, 252,-32768, 401,-32768,-32768,
+ 23, 159, 152, 14, 57, 356,-32768,-32768, 252, 252,
+ 252, 252, 252, 252, 284, 252, 252, 252, 252, 252,
+ 252, 252, 252, 252, 252, -42, 252, 252, 284, 252,
+ 383, 182,-32768,-32768, 421, 73, 376, 163, 421, 192,
+ 407, 187,-32768, 64,-32768, 156,-32768, 202,-32768, 283,
+ -42, -42,-32768, 57, 194, 57, 196,-32768, 95, 95,
+ 95, 95, 95, 95, 169, 275, 275, 275,-32768,-32768,
+-32768,-32768,-32768, 107, 382,-32768, 118, 421,-32768, 350,
+ 200, 179, 383, 205,-32768,-32768, 252, 185, 252,-32768,
+ 252, 138, -42, 401, 212, -42,-32768, 167, 210,-32768,
+-32768,-32768, 170,-32768, -42, 64,-32768,-32768, 221, 221,
+-32768,-32768,-32768,-32768, 284,-32768,-32768,-32768,-32768,-32768,
+-32768, 252, 284,-32768,-32768, 284, 421, 252, 421,-32768,
+-32768, 134, 174, 241, 197, -42, 168, 401,-32768, -42,
+-32768, 217, -15, 225,-32768, 41, 226, 229,-32768, 344,
+ 233, 236, 421,-32768, 266, 243,-32768,-32768, 64,-32768,
+-32768,-32768, -42, 227, 52,-32768, 238, 242, 241,-32768,
+-32768,-32768, 284,-32768,-32768, 401,-32768, 216, 244, 227,
+-32768, -15, 241, 241,-32768,-32768,-32768, 64,-32768,-32768,
+-32768,-32768,-32768, 256, 260,-32768
+};
+
+static const short yypgoto[] = {-32768,
+-32768,-32768, 264,-32768,-32768, -40, -23,-32768, -9,-32768,
+ -164, -203,-32768,-32768, 53,-32768, -159,-32768, 20,-32768,
+ 18,-32768,-32768,-32768,-32768, 76, 83,-32768, 17,-32768,
+-32768, 55, -3, -34, -16, 213,-32768,-32768,-32768,-32768,
+-32768,-32768,-32768,-32768,-32768, 122,-32768,-32768, 115, -10,
+ 358, 103, 44, -84, -1,-32768,-32768,-32768,-32768, 6
+};
+
+
+#define YYLAST 458
+
+
+static const short yytable[] = { 4,
+ 63, 79, 12, 15, 77, 56, 1, 64, 37, 66,
+ 236, 41, 3, 212, 15, 37, 217, 65, 42, 154,
+ 243, 222, 157, 15, 89, 90, 91, 92, 93, 94,
+ -11, -11, -11, 8, -11, 86, 114, 37, -11, 3,
+ 41, 82, 104, 9, 105, 265, 106, 42, 83, 109,
+ -20, -20, -20, 13, 122, 261, 217, 3, -20, 271,
+ 272, 262, 117, 244, 119, 121, 173, 37, 3, 37,
+ 10, 123, 118, 125, 259, 174, 166, 3, 145, 82,
+ 167, 82, 129, 260, 131, 132, 83, 161, 83, 130,
+ 87, 88, 159, 37, 155, 45, 175, 158, 176, 160,
+ 178, 43, 244, 273, 156, 96, 97, 37, 68, 164,
+ 197, 112, 98, 67, 167, 49, 50, 51, 3, 52,
+ 53, 199, 183, 177, 69, 167, 129, 70, 129, 189,
+ 190, 211, 72, 130, 73, 130, 74, 234, 15, 161,
+ 71, 185, 149, 150, 151, 152, 153, 187, 76, 188,
+ 213, 191, 15, 193, 84, 75, 207, 107, 209, 78,
+ 121, 164, 178, 185, 186, -9, -9, -9, 108, -9,
+ 41, 129, 110, -9, 129, 185, 239, 42, 229, -22,
+ -22, -22, 124, 221, 183, 165, 231, -22, 169, 232,
+ 178, 230, 3, 37, 240, 170, 172, 233, 146, 147,
+ 148, 37, 15, 192, 37, 194, 3, 195, 203, 204,
+ 208, 257, 183, 206, 129, 178, 214, 218, 241, 219,
+ 220, 129, 12, 223, 235, 178, 242, 237, 15, -44,
+ -44, -44, 267, 249, 185, 251, 266, 183, 252, 178,
+ 178, 129, 254, 173, 178, 255, 263, 183, 258, 268,
+ 264, 37, 174, 269, 46, 275, 3, 10, -67, 276,
+ 129, 183, 183, 47, 16, 6, 183, 17, 238, 228,
+ 48, 18, 225, 19, 20, 21, 22, 256, 270, 23,
+ 250, 113, 3, 15, 205, 210, 24, 99, 100, 101,
+ 102, 103, 49, 50, 51, 3, 52, 53, 0, 0,
+ 177, 0, 0, 49, 50, 51, 3, 52, 53, 54,
+ -46, -46, -46, 10, 0, 0, 0, 49, 50, 51,
+ 16, 52, 53, 17, 0, 0, 0, 18, 0, 19,
+ 20, 21, 22, 10, 0, 23, 0, 3, 3, 0,
+ 16, 0, 24, 17, 0, 0, 0, 18, 0, 19,
+ 20, 21, 22, 0, 0, 0, 0, 0, 3, 138,
+ 0, 0, 24, 89, 90, 91, 92, 93, 94, 89,
+ 90, 91, 92, 93, 94, 89, 90, 91, 92, 93,
+ 94, 168, 0, 0, 0, 0, 0, 198, 253, 0,
+ 200, 201, 0, 0, 0, 89, 90, 91, 92, 93,
+ 94, 89, 90, 91, 92, 93, 94, 89, 90, 91,
+ 92, 93, 94, 0, 171, 0, 0, 0, 89, 90,
+ 91, 92, 93, 94, 0, 95, 89, 90, 91, 92,
+ 93, 94, 111, 0, 49, 50, 51, 3, 52, 53,
+ 89, 90, 91, 92, 93, 94, 139, 140, 141, 142,
+ 143, 144, 49, 50, 51, 0, 52, 53
+};
+
+static const short yycheck[] = { 1,
+ 17, 42, 6, 1, 39, 16, 27, 18, 10, 20,
+ 214, 13, 55, 173, 1, 17, 176, 19, 13, 104,
+ 36, 186, 107, 1, 20, 21, 22, 23, 24, 25,
+ 28, 29, 30, 10, 32, 46, 71, 39, 36, 55,
+ 42, 43, 3, 7, 5, 249, 7, 42, 43, 45,
+ 28, 29, 30, 50, 78, 4, 216, 55, 36, 263,
+ 264, 10, 73, 223, 75, 76, 3, 69, 55, 71,
+ 30, 81, 74, 83, 239, 12, 4, 55, 95, 81,
+ 8, 83, 84, 243, 28, 29, 81, 111, 83, 84,
+ 47, 48, 109, 95, 105, 10, 33, 108, 35, 110,
+ 124, 32, 262, 268, 106, 11, 12, 109, 3, 111,
+ 4, 68, 18, 52, 8, 52, 53, 54, 55, 56,
+ 57, 4, 124, 60, 9, 8, 128, 31, 130, 131,
+ 132, 172, 3, 128, 5, 130, 7, 4, 1, 163,
+ 10, 8, 99, 100, 101, 102, 103, 128, 3, 130,
+ 174, 134, 1, 136, 36, 26, 167, 3, 169, 24,
+ 171, 163, 186, 8, 9, 28, 29, 30, 43, 32,
+ 172, 173, 26, 36, 176, 8, 9, 172, 195, 28,
+ 29, 30, 24, 185, 186, 4, 203, 36, 26, 206,
+ 214, 202, 55, 195, 218, 4, 10, 208, 96, 97,
+ 98, 203, 1, 10, 206, 10, 55, 39, 9, 31,
+ 26, 235, 214, 9, 216, 239, 5, 51, 220, 10,
+ 51, 223, 226, 3, 51, 249, 10, 31, 1, 28,
+ 29, 30, 256, 9, 8, 10, 253, 239, 10, 263,
+ 264, 243, 10, 3, 268, 10, 9, 249, 6, 34,
+ 9, 253, 12, 10, 3, 0, 55, 30, 31, 0,
+ 262, 263, 264, 12, 37, 2, 268, 40, 216, 194,
+ 19, 44, 190, 46, 47, 48, 49, 12, 262, 52,
+ 226, 69, 55, 1, 163, 171, 59, 13, 14, 15,
+ 16, 17, 52, 53, 54, 55, 56, 57, -1, -1,
+ 60, -1, -1, 52, 53, 54, 55, 56, 57, 58,
+ 28, 29, 30, 30, -1, -1, -1, 52, 53, 54,
+ 37, 56, 57, 40, -1, -1, -1, 44, -1, 46,
+ 47, 48, 49, 30, -1, 52, -1, 55, 55, -1,
+ 37, -1, 59, 40, -1, -1, -1, 44, -1, 46,
+ 47, 48, 49, -1, -1, -1, -1, -1, 55, 4,
+ -1, -1, 59, 20, 21, 22, 23, 24, 25, 20,
+ 21, 22, 23, 24, 25, 20, 21, 22, 23, 24,
+ 25, 6, -1, -1, -1, -1, -1, 6, 45, -1,
+ 41, 42, -1, -1, -1, 20, 21, 22, 23, 24,
+ 25, 20, 21, 22, 23, 24, 25, 20, 21, 22,
+ 23, 24, 25, -1, 8, -1, -1, -1, 20, 21,
+ 22, 23, 24, 25, -1, 38, 20, 21, 22, 23,
+ 24, 25, 34, -1, 52, 53, 54, 55, 56, 57,
+ 20, 21, 22, 23, 24, 25, 89, 90, 91, 92,
+ 93, 94, 52, 53, 54, -1, 56, 57
+};
+/* -*-C-*- Note some compilers choke on comments on `#line' lines. */
+#line 3 "/usr/local/share/bison.simple"
+/* This file comes from bison-1.28. */
+
+/* Skeleton output parser for bison,
+ Copyright (C) 1984, 1989, 1990 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., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/* As a special exception, when this file is copied by Bison into a
+ Bison output file, you may use that output file without restriction.
+ This special exception was added by the Free Software Foundation
+ in version 1.24 of Bison. */
+
+/* This is the parser code that is written into each bison parser
+ when the %semantic_parser declaration is not specified in the grammar.
+ It was written by Richard Stallman by simplifying the hairy parser
+ used when %semantic_parser is specified. */
+
+#ifndef YYSTACK_USE_ALLOCA
+#ifdef alloca
+#define YYSTACK_USE_ALLOCA
+#else /* alloca not defined */
+#ifdef __GNUC__
+#define YYSTACK_USE_ALLOCA
+#define alloca __builtin_alloca
+#else /* not GNU C. */
+#if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386))
+#define YYSTACK_USE_ALLOCA
+#include
+#else /* not sparc */
+/* We think this test detects Watcom and Microsoft C. */
+/* This used to test MSDOS, but that is a bad idea
+ since that symbol is in the user namespace. */
+#if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__)
+#if 0 /* No need for malloc.h, which pollutes the namespace;
+ instead, just don't use alloca. */
+#include
+#endif
+#else /* not MSDOS, or __TURBOC__ */
+#if defined(_AIX)
+/* I don't know what this was needed for, but it pollutes the namespace.
+ So I turned it off. rms, 2 May 1997. */
+/* #include */
+ #pragma alloca
+#define YYSTACK_USE_ALLOCA
+#else /* not MSDOS, or __TURBOC__, or _AIX */
+#if 0
+#ifdef __hpux /* haible@ilog.fr says this works for HPUX 9.05 and up,
+ and on HPUX 10. Eventually we can turn this on. */
+#define YYSTACK_USE_ALLOCA
+#define alloca __builtin_alloca
+#endif /* __hpux */
+#endif
+#endif /* not _AIX */
+#endif /* not MSDOS, or __TURBOC__ */
+#endif /* not sparc */
+#endif /* not GNU C */
+#endif /* alloca not defined */
+#endif /* YYSTACK_USE_ALLOCA not defined */
+
+#ifdef YYSTACK_USE_ALLOCA
+#define YYSTACK_ALLOC alloca
+#else
+#define YYSTACK_ALLOC malloc
+#endif
+
+/* Note: there must be only one dollar sign in this file.
+ It is replaced by the list of actions, each action
+ as one case of the switch. */
+
+#define yyerrok (yyerrstatus = 0)
+#define yyclearin (yychar = YYEMPTY)
+#define YYEMPTY -2
+#define YYEOF 0
+#define YYACCEPT goto yyacceptlab
+#define YYABORT goto yyabortlab
+#define YYERROR goto yyerrlab1
+/* Like YYERROR except do call yyerror.
+ This remains here temporarily to ease the
+ transition to the new meaning of YYERROR, for GCC.
+ Once GCC version 2 has supplanted version 1, this can go. */
+#define YYFAIL goto yyerrlab
+#define YYRECOVERING() (!!yyerrstatus)
+#define YYBACKUP(token, value) \
+do \
+ if (yychar == YYEMPTY && yylen == 1) \
+ { yychar = (token), yylval = (value); \
+ yychar1 = YYTRANSLATE (yychar); \
+ YYPOPSTACK; \
+ goto yybackup; \
+ } \
+ else \
+ { yyerror ("syntax error: cannot back up"); YYERROR; } \
+while (0)
+
+#define YYTERROR 1
+#define YYERRCODE 256
+
+#ifndef YYPURE
+#define YYLEX yylex()
+#endif
+
+#ifdef YYPURE
+#ifdef YYLSP_NEEDED
+#ifdef YYLEX_PARAM
+#define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
+#else
+#define YYLEX yylex(&yylval, &yylloc)
+#endif
+#else /* not YYLSP_NEEDED */
+#ifdef YYLEX_PARAM
+#define YYLEX yylex(&yylval, YYLEX_PARAM)
+#else
+#define YYLEX yylex(&yylval)
+#endif
+#endif /* not YYLSP_NEEDED */
+#endif
+
+/* If nonreentrant, generate the variables here */
+
+#ifndef YYPURE
+
+int yychar; /* the lookahead symbol */
+YYSTYPE yylval; /* the semantic value of the */
+ /* lookahead symbol */
+
+#ifdef YYLSP_NEEDED
+YYLTYPE yylloc; /* location data for the lookahead */
+ /* symbol */
+#endif
+
+int yynerrs; /* number of parse errors so far */
+#endif /* not YYPURE */
+
+#if YYDEBUG != 0
+int yydebug; /* nonzero means print parse trace */
+/* Since this is uninitialized, it does not stop multiple parsers
+ from coexisting. */
+#endif
+
+/* YYINITDEPTH indicates the initial size of the parser's stacks */
+
+#ifndef YYINITDEPTH
+#define YYINITDEPTH 200
+#endif
+
+/* YYMAXDEPTH is the maximum size the stacks can grow to
+ (effective only if the built-in stack extension method is used). */
+
+#if YYMAXDEPTH == 0
+#undef YYMAXDEPTH
+#endif
+
+#ifndef YYMAXDEPTH
+#define YYMAXDEPTH 10000
+#endif
+
+/* Define __yy_memcpy. Note that the size argument
+ should be passed with type unsigned int, because that is what the non-GCC
+ definitions require. With GCC, __builtin_memcpy takes an arg
+ of type size_t, but it can handle unsigned int. */
+
+#if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
+#define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT)
+#else /* not GNU C or C++ */
+#ifndef __cplusplus
+
+/* This is the most reliable way to avoid incompatibilities
+ in available built-in functions on various systems. */
+static void
+__yy_memcpy (to, from, count)
+ char *to;
+ char *from;
+ unsigned int count;
+{
+ register char *f = from;
+ register char *t = to;
+ register int i = count;
+
+ while (i-- > 0)
+ *t++ = *f++;
+}
+
+#else /* __cplusplus */
+
+/* This is the most reliable way to avoid incompatibilities
+ in available built-in functions on various systems. */
+static void
+__yy_memcpy (char *to, char *from, unsigned int count)
+{
+ register char *t = to;
+ register char *f = from;
+ register int i = count;
+
+ while (i-- > 0)
+ *t++ = *f++;
+}
+
+#endif
+#endif
+
+#line 217 "/usr/local/share/bison.simple"
+
+/* The user can define YYPARSE_PARAM as the name of an argument to be passed
+ into yyparse. The argument should have type void *.
+ It should actually point to an object.
+ Grammar actions can access the variable by casting it
+ to the proper pointer type. */
+
+#ifdef YYPARSE_PARAM
+#ifdef __cplusplus
+#define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
+#define YYPARSE_PARAM_DECL
+#else /* not __cplusplus */
+#define YYPARSE_PARAM_ARG YYPARSE_PARAM
+#define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
+#endif /* not __cplusplus */
+#else /* not YYPARSE_PARAM */
+#define YYPARSE_PARAM_ARG
+#define YYPARSE_PARAM_DECL
+#endif /* not YYPARSE_PARAM */
+
+/* Prevent warning if -Wstrict-prototypes. */
+#ifdef __GNUC__
+#ifdef YYPARSE_PARAM
+int yyparse (void *);
+#else
+int yyparse (void);
+#endif
+#endif
+
+int
+yyparse(YYPARSE_PARAM_ARG)
+ YYPARSE_PARAM_DECL
+{
+ register int yystate;
+ register int yyn;
+ register short *yyssp;
+ register YYSTYPE *yyvsp;
+ int yyerrstatus; /* number of tokens to shift before error messages enabled */
+ int yychar1 = 0; /* lookahead token as an internal (translated) token number */
+
+ short yyssa[YYINITDEPTH]; /* the state stack */
+ YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */
+
+ short *yyss = yyssa; /* refer to the stacks thru separate pointers */
+ YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
+
+#ifdef YYLSP_NEEDED
+ YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */
+ YYLTYPE *yyls = yylsa;
+ YYLTYPE *yylsp;
+
+#define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
+#else
+#define YYPOPSTACK (yyvsp--, yyssp--)
+#endif
+
+ int yystacksize = YYINITDEPTH;
+ int yyfree_stacks = 0;
+
+#ifdef YYPURE
+ int yychar;
+ YYSTYPE yylval;
+ int yynerrs;
+#ifdef YYLSP_NEEDED
+ YYLTYPE yylloc;
+#endif
+#endif
+
+ YYSTYPE yyval; /* the variable used to return */
+ /* semantic values from the action */
+ /* routines */
+
+ int yylen;
+
+#if YYDEBUG != 0
+ if (yydebug)
+ fprintf(stderr, "Starting parse\n");
+#endif
+
+ yystate = 0;
+ yyerrstatus = 0;
+ yynerrs = 0;
+ yychar = YYEMPTY; /* Cause a token to be read. */
+
+ /* Initialize stack pointers.
+ Waste one element of value and location stack
+ so that they stay on the same level as the state stack.
+ The wasted elements are never initialized. */
+
+ yyssp = yyss - 1;
+ yyvsp = yyvs;
+#ifdef YYLSP_NEEDED
+ yylsp = yyls;
+#endif
+
+/* Push a new state, which is found in yystate . */
+/* In all cases, when you get here, the value and location stacks
+ have just been pushed. so pushing a state here evens the stacks. */
+yynewstate:
+
+ *++yyssp = yystate;
+
+ if (yyssp >= yyss + yystacksize - 1)
+ {
+ /* Give user a chance to reallocate the stack */
+ /* Use copies of these so that the &'s don't force the real ones into memory. */
+ YYSTYPE *yyvs1 = yyvs;
+ short *yyss1 = yyss;
+#ifdef YYLSP_NEEDED
+ YYLTYPE *yyls1 = yyls;
+#endif
+
+ /* Get the current used size of the three stacks, in elements. */
+ int size = yyssp - yyss + 1;
+
+#ifdef yyoverflow
+ /* Each stack pointer address is followed by the size of
+ the data in use in that stack, in bytes. */
+#ifdef YYLSP_NEEDED
+ /* This used to be a conditional around just the two extra args,
+ but that might be undefined if yyoverflow is a macro. */
+ yyoverflow("parser stack overflow",
+ &yyss1, size * sizeof (*yyssp),
+ &yyvs1, size * sizeof (*yyvsp),
+ &yyls1, size * sizeof (*yylsp),
+ &yystacksize);
+#else
+ yyoverflow("parser stack overflow",
+ &yyss1, size * sizeof (*yyssp),
+ &yyvs1, size * sizeof (*yyvsp),
+ &yystacksize);
+#endif
+
+ yyss = yyss1; yyvs = yyvs1;
+#ifdef YYLSP_NEEDED
+ yyls = yyls1;
+#endif
+#else /* no yyoverflow */
+ /* Extend the stack our own way. */
+ if (yystacksize >= YYMAXDEPTH)
+ {
+ yyerror("parser stack overflow");
+ if (yyfree_stacks)
+ {
+ free (yyss);
+ free (yyvs);
+#ifdef YYLSP_NEEDED
+ free (yyls);
+#endif
+ }
+ return 2;
+ }
+ yystacksize *= 2;
+ if (yystacksize > YYMAXDEPTH)
+ yystacksize = YYMAXDEPTH;
+#ifndef YYSTACK_USE_ALLOCA
+ yyfree_stacks = 1;
+#endif
+ yyss = (short *) YYSTACK_ALLOC (yystacksize * sizeof (*yyssp));
+ __yy_memcpy ((char *)yyss, (char *)yyss1,
+ size * (unsigned int) sizeof (*yyssp));
+ yyvs = (YYSTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yyvsp));
+ __yy_memcpy ((char *)yyvs, (char *)yyvs1,
+ size * (unsigned int) sizeof (*yyvsp));
+#ifdef YYLSP_NEEDED
+ yyls = (YYLTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yylsp));
+ __yy_memcpy ((char *)yyls, (char *)yyls1,
+ size * (unsigned int) sizeof (*yylsp));
+#endif
+#endif /* no yyoverflow */
+
+ yyssp = yyss + size - 1;
+ yyvsp = yyvs + size - 1;
+#ifdef YYLSP_NEEDED
+ yylsp = yyls + size - 1;
+#endif
+
+#if YYDEBUG != 0
+ if (yydebug)
+ fprintf(stderr, "Stack size increased to %d\n", yystacksize);
+#endif
+
+ if (yyssp >= yyss + yystacksize - 1)
+ YYABORT;
+ }
+
+#if YYDEBUG != 0
+ if (yydebug)
+ fprintf(stderr, "Entering state %d\n", yystate);
+#endif
+
+ goto yybackup;
+ yybackup:
+
+/* Do appropriate processing given the current state. */
+/* Read a lookahead token if we need one and don't already have one. */
+/* yyresume: */
+
+ /* First try to decide what to do without reference to lookahead token. */
+
+ yyn = yypact[yystate];
+ if (yyn == YYFLAG)
+ goto yydefault;
+
+ /* Not known => get a lookahead token if don't already have one. */
+
+ /* yychar is either YYEMPTY or YYEOF
+ or a valid token in external form. */
+
+ if (yychar == YYEMPTY)
+ {
+#if YYDEBUG != 0
+ if (yydebug)
+ fprintf(stderr, "Reading a token: ");
+#endif
+ yychar = YYLEX;
+ }
+
+ /* Convert token to internal form (in yychar1) for indexing tables with */
+
+ if (yychar <= 0) /* This means end of input. */
+ {
+ yychar1 = 0;
+ yychar = YYEOF; /* Don't call YYLEX any more */
+
+#if YYDEBUG != 0
+ if (yydebug)
+ fprintf(stderr, "Now at end of input.\n");
+#endif
+ }
+ else
+ {
+ yychar1 = YYTRANSLATE(yychar);
+
+#if YYDEBUG != 0
+ if (yydebug)
+ {
+ fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
+ /* Give the individual parser a way to print the precise meaning
+ of a token, for further debugging info. */
+#ifdef YYPRINT
+ YYPRINT (stderr, yychar, yylval);
+#endif
+ fprintf (stderr, ")\n");
+ }
+#endif
+ }
+
+ yyn += yychar1;
+ if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
+ goto yydefault;
+
+ yyn = yytable[yyn];
+
+ /* yyn is what to do for this token type in this state.
+ Negative => reduce, -yyn is rule number.
+ Positive => shift, yyn is new state.
+ New state is final state => don't bother to shift,
+ just return success.
+ 0, or most negative number => error. */
+
+ if (yyn < 0)
+ {
+ if (yyn == YYFLAG)
+ goto yyerrlab;
+ yyn = -yyn;
+ goto yyreduce;
+ }
+ else if (yyn == 0)
+ goto yyerrlab;
+
+ if (yyn == YYFINAL)
+ YYACCEPT;
+
+ /* Shift the lookahead token. */
+
+#if YYDEBUG != 0
+ if (yydebug)
+ fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
+#endif
+
+ /* Discard the token being shifted unless it is eof. */
+ if (yychar != YYEOF)
+ yychar = YYEMPTY;
+
+ *++yyvsp = yylval;
+#ifdef YYLSP_NEEDED
+ *++yylsp = yylloc;
+#endif
+
+ /* count tokens shifted since error; after three, turn off error status. */
+ if (yyerrstatus) yyerrstatus--;
+
+ yystate = yyn;
+ goto yynewstate;
+
+/* Do the default action for the current state. */
+yydefault:
+
+ yyn = yydefact[yystate];
+ if (yyn == 0)
+ goto yyerrlab;
+
+/* Do a reduction. yyn is the number of a rule to reduce with. */
+yyreduce:
+ yylen = yyr2[yyn];
+ if (yylen > 0)
+ yyval = yyvsp[1-yylen]; /* implement default value of the action */
+
+#if YYDEBUG != 0
+ if (yydebug)
+ {
+ int i;
+
+ fprintf (stderr, "Reducing via rule %d (line %d), ",
+ yyn, yyrline[yyn]);
+
+ /* Print the symbols being reduced, and their result. */
+ for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
+ fprintf (stderr, "%s ", yytname[yyrhs[i]]);
+ fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
+ }
+#endif
+
+
+ switch (yyn) {
+
+case 1:
+#line 81 "pascal.y"
+{/*set root for abstract syntax tree*/ A_synTreeRoot = yyvsp[-1].exp; ;
+ break;}
+case 2:
+#line 82 "pascal.y"
+{;
+ break;}
+case 3:
+#line 83 "pascal.y"
+{/*head:declaration with type A_decList, body:expression with type A_exp*/ yyval.exp = A_LetExp(EM_tokPos, yyvsp[-1].declist, yyvsp[0].exp);;
+ break;}
+case 4:
+#line 84 "pascal.y"
+{
+ /* placeholder*/
+ A_decList decList = A_DecList(A_TypeDec(0, NULL), NULL);
+ if (yyvsp[-3].declist)
+ A_linkDecList(decList, yyvsp[-3].declist);
+ if (yyvsp[-2].declist)
+ A_linkDecList(decList, yyvsp[-2].declist);
+ if (yyvsp[-1].declist)
+ A_linkDecList(decList, yyvsp[-1].declist);
+ if (yyvsp[0].fundeclist)
+ A_linkDecList(decList, A_DecList(A_FunctionDec(EM_tokPos, yyvsp[0].fundeclist), NULL));
+ yyval.declist = decList->tail;
+ ;
+ break;}
+case 5:
+#line 98 "pascal.y"
+{/*label part is empty in pascal*/ yyval.declist = NULL;;
+ break;}
+case 6:
+#line 101 "pascal.y"
+{/*const declaration part*/ yyval.declist = yyvsp[0].declist;;
+ break;}
+case 7:
+#line 102 "pascal.y"
+{/*no const declaration*/ yyval.declist = NULL;;
+ break;}
+case 8:
+#line 103 "pascal.y"
+{/*const declaration list*/ yyval.declist = A_DecList(A_ConstDec(EM_tokPos, yyvsp[-4].sym, yyvsp[-2].exp),yyvsp[0].declist);;
+ break;}
+case 9:
+#line 104 "pascal.y"
+{/*first one in list*/ yyval.declist = A_DecList(A_ConstDec(EM_tokPos, yyvsp[-3].sym, yyvsp[-1].exp), NULL);;
+ break;}
+case 10:
+#line 105 "pascal.y"
+{/*run into error*/ yyval.declist = yyvsp[0].declist;;
+ break;}
+case 11:
+#line 106 "pascal.y"
+{yyval.declist = NULL;;
+ break;}
+case 12:
+#line 107 "pascal.y"
+{/*integer value*/ yyval.exp = A_IntExp(EM_tokPos, yyvsp[0].ival);;
+ break;}
+case 13:
+#line 108 "pascal.y"
+{/*real value*/ yyval.exp = A_RealExp(EM_tokPos, yyvsp[0].rval);;
+ break;}
+case 14:
+#line 109 "pascal.y"
+{/*char value*/ yyval.exp = A_CharExp(EM_tokPos, yyvsp[0].cval);;
+ break;}
+case 15:
+#line 110 "pascal.y"
+{/*string value*/ yyval.exp = A_StringExp(EM_tokPos, yyvsp[0].sval);;
+ break;}
+case 16:
+#line 111 "pascal.y"
+{/*system const value*/ /*$$ = A_SysConstExp(EM_tokPos, $1);*/;
+ break;}
+case 17:
+#line 114 "pascal.y"
+{/*type declaration part*/ yyval.declist = A_DecList(A_TypeDec(EM_tokPos, yyvsp[0].nametylist), NULL);;
+ break;}
+case 18:
+#line 115 "pascal.y"
+{/*no type declaration*/ yyval.declist = NULL;;
+ break;}
+case 19:
+#line 116 "pascal.y"
+{/*type declaration list*/ yyval.nametylist = A_NametyList(yyvsp[-1].namety, yyvsp[0].nametylist);;
+ break;}
+case 20:
+#line 117 "pascal.y"
+{/*last type definition, tail points to NULL*/yyval.nametylist = A_NametyList(yyvsp[0].namety, NULL);;
+ break;}
+case 21:
+#line 118 "pascal.y"
+{/*run into error*/ yyval.nametylist = yyvsp[0].nametylist;;
+ break;}
+case 22:
+#line 119 "pascal.y"
+{yyval.nametylist = NULL;;
+ break;}
+case 23:
+#line 120 "pascal.y"
+{/*type declaration*/yyval.namety =A_Namety(yyvsp[-3].sym, yyvsp[-1].ty);;
+ break;}
+case 24:
+#line 121 "pascal.y"
+{/*simple type*/ yyval.ty = yyvsp[0].ty;;
+ break;}
+case 25:
+#line 122 "pascal.y"
+{/*array type*/ yyval.ty = yyvsp[0].ty;;
+ break;}
+case 26:
+#line 123 "pascal.y"
+{/*record type*/ yyval.ty = yyvsp[0].ty;;
+ break;}
+case 27:
+#line 124 "pascal.y"
+{/*system defined type*/ yyval.ty = A_NameTy(EM_tokPos, yyvsp[0].sym);;
+ break;}
+case 28:
+#line 125 "pascal.y"
+{/*self define simple type*/ yyval.ty = A_NameTy(EM_tokPos, yyvsp[0].sym);;
+ break;}
+case 29:
+#line 126 "pascal.y"
+{/*enum type*/ yyval.ty = A_EnumType(EM_tokPos, yyvsp[-1].fieldlist);;
+ break;}
+case 30:
+#line 127 "pascal.y"
+{/*subrange type*/ yyval.ty = A_RangeTy(EM_tokPos, yyvsp[-2].exp, yyvsp[0].exp);;
+ break;}
+case 31:
+#line 128 "pascal.y"
+{/*subrange type*/ A_RangeTy(EM_tokPos, A_OpExp(EM_tokPos, A_minusOp, A_IntExp(EM_tokPos, 0), yyvsp[-2].exp), yyvsp[0].exp);;
+ break;}
+case 32:
+#line 129 "pascal.y"
+{/*subrange type*/ A_RangeTy(EM_tokPos, A_OpExp(EM_tokPos, A_minusOp, A_IntExp(EM_tokPos, 0), yyvsp[-3].exp), A_OpExp(EM_tokPos, A_minusOp, A_IntExp(EM_tokPos, 0), yyvsp[0].exp));;
+ break;}
+case 33:
+#line 130 "pascal.y"
+{/*subrange type*/ A_RangeTy(EM_tokPos, A_VarExp(EM_tokPos, A_SimpleVar(EM_tokPos, yyvsp[-2].sym)), A_VarExp(EM_tokPos, A_SimpleVar(EM_tokPos, yyvsp[0].sym)));;
+ break;}
+case 34:
+#line 131 "pascal.y"
+{/*array type, simple_type_dec is range of array, type_dec is actual type of array element*/ yyval.ty = A_ArrayTy(EM_tokPos, yyvsp[-3].ty, yyvsp[0].ty);;
+ break;}
+case 35:
+#line 132 "pascal.y"
+{/*record type*/ yyval.ty = A_RecordTy(EM_tokPos, yyvsp[-1].fieldlist);;
+ break;}
+case 36:
+#line 134 "pascal.y"
+{/*link parts of fieldlists*/ yyval.fieldlist = A_linkFieldList(yyvsp[-1].fieldlist, yyvsp[0].fieldlist); ;
+ break;}
+case 37:
+#line 135 "pascal.y"
+{yyval.fieldlist = yyvsp[0].fieldlist;;
+ break;}
+case 38:
+#line 136 "pascal.y"
+{ /*set type of namelist*/yyval.fieldlist = A_setFieldListType(yyvsp[-3].fieldlist, yyvsp[-1].ty);;
+ break;}
+case 39:
+#line 137 "pascal.y"
+{/*namelist is fieldlist of same unknown type*/ yyval.fieldlist = A_linkFieldList(yyvsp[-2].fieldlist, A_FieldList(A_Field(EM_tokPos, yyvsp[0].sym, NULL), NULL));;
+ break;}
+case 40:
+#line 138 "pascal.y"
+{yyval.fieldlist = A_FieldList(A_Field(EM_tokPos, yyvsp[0].sym, NULL), NULL);;
+ break;}
+case 41:
+#line 141 "pascal.y"
+{/*variable declaration part*/ yyval.declist = yyvsp[0].declist;;
+ break;}
+case 42:
+#line 142 "pascal.y"
+{/*no variable declaration*/ yyval.declist = NULL;;
+ break;}
+case 43:
+#line 143 "pascal.y"
+{/*variable declaration list*/ yyval.declist = A_linkDecList(yyvsp[-1].declist, yyvsp[0].declist);;
+ break;}
+case 44:
+#line 144 "pascal.y"
+{yyval.declist = yyvsp[0].declist;;
+ break;}
+case 45:
+#line 145 "pascal.y"
+{yyval.declist = yyvsp[0].declist;;
+ break;}
+case 46:
+#line 146 "pascal.y"
+{yyval.declist = NULL;;
+ break;}
+case 47:
+#line 147 "pascal.y"
+{/*change name_list to variable declaration list*/ yyval.declist = A_setDecListType(A_unDecList(yyvsp[-3].fieldlist), yyvsp[-1].ty);;
+ break;}
+case 48:
+#line 150 "pascal.y"
+{/*routine declaration part, new function*/ yyval.fundeclist = A_FundecList(yyvsp[-1].fundec, yyvsp[0].fundeclist);;
+ break;}
+case 49:
+#line 151 "pascal.y"
+{/*routine declaration part, new routine*/ yyval.fundeclist = A_FundecList(yyvsp[-1].fundec, yyvsp[0].fundeclist);;
+ break;}
+case 50:
+#line 152 "pascal.y"
+{yyval.fundeclist = NULL;;
+ break;}
+case 51:
+#line 154 "pascal.y"
+{/*set function body*/yyval.fundec = yyvsp[-3].fundec; yyval.fundec->body = yyvsp[-1].exp;;
+ break;}
+case 52:
+#line 155 "pascal.y"
+{/*declare function head*/yyval.fundec = A_Fundec(EM_tokPos, yyvsp[-3].sym, yyvsp[-2].fieldlist, yyvsp[0].ty->u.name, NULL);;
+ break;}
+case 53:
+#line 156 "pascal.y"
+{/*set procedure body*/ yyval.fundec = yyvsp[-3].fundec; yyval.fundec->body = yyvsp[-1].exp;;
+ break;}
+case 54:
+#line 157 "pascal.y"
+{/*declare procedure head, return type is NULL*/ yyval.fundec = A_Fundec(EM_tokPos, yyvsp[-1].sym, yyvsp[0].fieldlist, NULL, NULL);;
+ break;}
+case 55:
+#line 158 "pascal.y"
+{/*sub_routine in declaration*/yyval.exp = A_LetExp(EM_tokPos, yyvsp[-1].declist, yyvsp[0].exp);;
+ break;}
+case 56:
+#line 159 "pascal.y"
+{/*parameters declaration*/ yyval.fieldlist = yyvsp[-1].fieldlist;;
+ break;}
+case 57:
+#line 160 "pascal.y"
+{/*no parameters*/ yyval.fieldlist = NULL;;
+ break;}
+case 58:
+#line 161 "pascal.y"
+{/*represent parameter declaration as A_fieldList*/ yyval.fieldlist = A_linkFieldList(yyvsp[-2].fieldlist, yyvsp[0].fieldlist);;
+ break;}
+case 59:
+#line 162 "pascal.y"
+{yyval.fieldlist = yyvsp[0].fieldlist;;
+ break;}
+case 60:
+#line 163 "pascal.y"
+{ yyval.fieldlist = A_setFieldListType(yyvsp[-2].fieldlist, yyvsp[0].ty);;
+ break;}
+case 61:
+#line 164 "pascal.y"
+{ yyval.fieldlist = A_setFieldListType(yyvsp[-2].fieldlist, yyvsp[0].ty);;
+ break;}
+case 62:
+#line 165 "pascal.y"
+{yyval.fieldlist = yyvsp[0].fieldlist;;
+ break;}
+case 63:
+#line 166 "pascal.y"
+{yyval.fieldlist = yyvsp[0].fieldlist;;
+ break;}
+case 64:
+#line 169 "pascal.y"
+{/*set routine body as A_exp*/ yyval.exp = yyvsp[0].exp;;
+ break;}
+case 65:
+#line 170 "pascal.y"
+{ yyval.exp = A_SeqExp(EM_tokPos, yyvsp[-1].explist);;
+ break;}
+case 66:
+#line 171 "pascal.y"
+{ /*statement in routine body*/yyval.explist = A_ExpList(yyvsp[-2].exp, yyvsp[0].explist);;
+ break;}
+case 67:
+#line 172 "pascal.y"
+{yyval.explist = NULL;;
+ break;}
+case 68:
+#line 173 "pascal.y"
+{yyval.explist = yyvsp[0].explist;;
+ break;}
+case 69:
+#line 174 "pascal.y"
+{yyval.exp = yyvsp[0].exp;;
+ break;}
+case 70:
+#line 175 "pascal.y"
+{ yyval.exp = yyvsp[0].exp;;
+ break;}
+case 71:
+#line 176 "pascal.y"
+{ yyval.exp = yyvsp[0].exp;;
+ break;}
+case 72:
+#line 177 "pascal.y"
+{/*call function or procedure*/ yyval.exp = yyvsp[0].exp;;
+ break;}
+case 73:
+#line 178 "pascal.y"
+{yyval.exp = yyvsp[0].exp;;
+ break;}
+case 74:
+#line 179 "pascal.y"
+{yyval.exp = yyvsp[0].exp;;
+ break;}
+case 75:
+#line 180 "pascal.y"
+{ yyval.exp = yyvsp[0].exp;;
+ break;}
+case 76:
+#line 181 "pascal.y"
+{yyval.exp = yyvsp[0].exp;;
+ break;}
+case 77:
+#line 182 "pascal.y"
+{yyval.exp = yyvsp[0].exp;;
+ break;}
+case 78:
+#line 183 "pascal.y"
+{yyval.exp = yyvsp[0].exp;;
+ break;}
+case 79:
+#line 184 "pascal.y"
+{yyval.exp = yyvsp[0].exp;;
+ break;}
+case 80:
+#line 185 "pascal.y"
+{/*simple variable assignment*/ yyval.exp = A_AssignExp(EM_tokPos,A_SimpleVar(EM_tokPos, yyvsp[-2].sym), yyvsp[0].exp);;
+ break;}
+case 81:
+#line 186 "pascal.y"
+{/*subscript variable of array assignment*/ yyval.exp = A_AssignExp(EM_tokPos, A_SubscriptVar(EM_tokPos, A_SimpleVar(EM_tokPos, yyvsp[-5].sym), yyvsp[-3].exp),yyvsp[0].exp);;
+ break;}
+case 82:
+#line 187 "pascal.y"
+{/*field variable of record assignment*/yyval.exp = A_AssignExp(EM_tokPos, A_FieldVar(EM_tokPos, A_SimpleVar(EM_tokPos, yyvsp[-4].sym), yyvsp[-2].sym),yyvsp[0].exp);;
+ break;}
+case 83:
+#line 188 "pascal.y"
+{/*call function*/ yyval.exp = A_CallExp(EM_tokPos, yyvsp[0].sym, NULL);;
+ break;}
+case 84:
+#line 189 "pascal.y"
+{/*call function with arguments*/ yyval.exp = A_CallExp(EM_tokPos, yyvsp[-3].sym, yyvsp[-1].explist);;
+ break;}
+case 85:
+#line 190 "pascal.y"
+{/*call system procedure*/yyval.exp = A_CallExp(EM_tokPos, yyvsp[0].sym, NULL);;
+ break;}
+case 86:
+#line 191 "pascal.y"
+{/*call system procedure with arguments*/yyval.exp = A_CallExp(EM_tokPos, yyvsp[-3].sym, yyvsp[-1].explist);;
+ break;}
+case 87:
+#line 192 "pascal.y"
+{;
+ break;}
+case 88:
+#line 193 "pascal.y"
+{/*if statement*/ yyval.exp = A_IfExp(EM_tokPos, yyvsp[-3].exp, yyvsp[-1].exp, yyvsp[0].exp);;
+ break;}
+case 89:
+#line 194 "pascal.y"
+{/*with else clause*/ yyval.exp = yyvsp[0].exp;;
+ break;}
+case 90:
+#line 195 "pascal.y"
+{/*no else clause*/ yyval.exp = NULL;;
+ break;}
+case 91:
+#line 196 "pascal.y"
+{/*repeat statement*/
+ yyval.exp = A_RepeatExp(EM_tokPos, yyvsp[-2].exp, yyvsp[0].exp);;
+ break;}
+case 92:
+#line 198 "pascal.y"
+{/*while statement*/ yyval.exp = A_WhileExp(EM_tokPos, yyvsp[-2].exp, yyvsp[0].exp);;
+ break;}
+case 93:
+#line 199 "pascal.y"
+{/*for statement*/
+ A_var var = A_SimpleVar(EM_tokPos, yyvsp[-6].sym);
+ if (!(yyvsp[-3].cval)) {
+ // to
+ yyval.exp = A_SeqExp(EM_tokPos, A_ExpList(A_AssignExp(EM_tokPos, var, yyvsp[-4].exp), A_ExpList(A_WhileExp(EM_tokPos, A_OpExp(EM_tokPos, A_ltOp, A_VarExp(EM_tokPos, var), yyvsp[-2].exp), yyvsp[0].exp), NULL )));
+ } else {
+ // downto
+ yyval.exp = A_SeqExp(EM_tokPos, A_ExpList(A_AssignExp(EM_tokPos, var, yyvsp[-4].exp), A_ExpList(A_WhileExp(EM_tokPos, A_OpExp(EM_tokPos, A_gtOp, A_VarExp(EM_tokPos ,var), yyvsp[-2].exp), yyvsp[0].exp), NULL )));
+ }
+;
+ break;}
+case 94:
+#line 209 "pascal.y"
+{yyval.cval = 0;;
+ break;}
+case 95:
+#line 210 "pascal.y"
+{yyval.cval = 1;;
+ break;}
+case 96:
+#line 211 "pascal.y"
+{/*case statement, case_expr_list is all the possible value*/ yyval.exp = A_CaseExp(EM_tokPos, yyvsp[-3].exp, yyvsp[-1].explist);;
+ break;}
+case 97:
+#line 212 "pascal.y"
+{yyval.explist = A_ExpList(yyvsp[-1].exp, yyvsp[0].explist);;
+ break;}
+case 98:
+#line 213 "pascal.y"
+{yyval.explist = A_ExpList(yyvsp[0].exp, NULL);;
+ break;}
+case 99:
+#line 214 "pascal.y"
+{yyval.exp = A_CaseValExp(EM_tokPos, yyvsp[-3].exp, yyvsp[-1].exp);;
+ break;}
+case 100:
+#line 215 "pascal.y"
+{yyval.exp = A_CaseValExp(EM_tokPos, A_VarExp(EM_tokPos, A_SimpleVar(EM_tokPos, yyvsp[-3].sym)), yyvsp[-1].exp);;
+ break;}
+case 101:
+#line 216 "pascal.y"
+{/*goto statement*/ yyval.exp = A_GotoExp(EM_tokPos, A_IntExp(EM_tokPos, yyvsp[0].ival));;
+ break;}
+case 102:
+#line 218 "pascal.y"
+{ yyval.explist = A_ExpList(yyvsp[-2].exp, yyvsp[0].explist);;
+ break;}
+case 103:
+#line 219 "pascal.y"
+{yyval.explist = A_ExpList(yyvsp[0].exp, NULL);;
+ break;}
+case 104:
+#line 220 "pascal.y"
+{/*greater equal expression*/ yyval.exp = A_OpExp(EM_tokPos, A_geOp, yyvsp[-2].exp, yyvsp[0].exp);;
+ break;}
+case 105:
+#line 221 "pascal.y"
+{/*greater than expression*/ yyval.exp = A_OpExp(EM_tokPos, A_gtOp, yyvsp[-2].exp, yyvsp[0].exp);;
+ break;}
+case 106:
+#line 222 "pascal.y"
+{/*less equal expression*/ yyval.exp = A_OpExp(EM_tokPos, A_leOp, yyvsp[-2].exp, yyvsp[0].exp); ;
+ break;}
+case 107:
+#line 223 "pascal.y"
+{/*less than expression*/ yyval.exp = A_OpExp(EM_tokPos, A_ltOp, yyvsp[-2].exp, yyvsp[0].exp);;
+ break;}
+case 108:
+#line 224 "pascal.y"
+{/*equal expression*/ yyval.exp = A_OpExp(EM_tokPos, A_eqOp, yyvsp[-2].exp, yyvsp[0].exp);;
+ break;}
+case 109:
+#line 225 "pascal.y"
+{/*unequal expression*/ yyval.exp = A_OpExp(EM_tokPos, A_neqOp, yyvsp[-2].exp, yyvsp[0].exp);;
+ break;}
+case 110:
+#line 226 "pascal.y"
+{ yyval.exp = yyvsp[0].exp;;
+ break;}
+case 111:
+#line 228 "pascal.y"
+{yyval.exp = A_OpExp(EM_tokPos, A_plusOp, yyvsp[-2].exp, yyvsp[0].exp);;
+ break;}
+case 112:
+#line 229 "pascal.y"
+{yyval.exp = A_OpExp(EM_tokPos, A_minusOp, yyvsp[-2].exp, yyvsp[0].exp);;
+ break;}
+case 113:
+#line 230 "pascal.y"
+{/*bool operation or*/ yyval.exp = A_IfExp(EM_tokPos, yyvsp[-2].exp, A_IntExp(EM_tokPos, 1), yyvsp[0].exp);;
+ break;}
+case 114:
+#line 231 "pascal.y"
+{ yyval.exp = yyvsp[0].exp;;
+ break;}
+case 115:
+#line 232 "pascal.y"
+{ yyval.exp = A_OpExp(EM_tokPos, A_timesOp, yyvsp[-2].exp, yyvsp[0].exp);;
+ break;}
+case 116:
+#line 233 "pascal.y"
+{ /*intdiv operation*/ yyval.exp = A_OpExp(EM_tokPos, A_divideOp, yyvsp[-2].exp, yyvsp[0].exp); ;
+ break;}
+case 117:
+#line 234 "pascal.y"
+{ /*real div operaiton*/ yyval.exp = A_OpExp(EM_tokPos, A_realDivideOp, yyvsp[-2].exp, yyvsp[0].exp);;
+ break;}
+case 118:
+#line 235 "pascal.y"
+{ /*mod operation*/ yyval.exp = A_OpExp(EM_tokPos, A_modOp, yyvsp[-2].exp, yyvsp[0].exp);;
+ break;}
+case 119:
+#line 236 "pascal.y"
+{ /*bool operation and*/ yyval.exp = A_IfExp(EM_tokPos, yyvsp[-2].exp, yyvsp[0].exp, A_IntExp(EM_tokPos, 0));;
+ break;}
+case 120:
+#line 237 "pascal.y"
+{ yyval.exp = yyvsp[0].exp;;
+ break;}
+case 121:
+#line 238 "pascal.y"
+{yyval.exp = A_VarExp(EM_tokPos, A_SimpleVar(EM_tokPos, yyvsp[0].sym));;
+ break;}
+case 122:
+#line 239 "pascal.y"
+{/*call function*/yyval.exp = A_CallExp(EM_tokPos, yyvsp[-3].sym, yyvsp[-1].explist);;
+ break;}
+case 123:
+#line 240 "pascal.y"
+{/*call system function without argument*/yyval.exp = A_CallExp(EM_tokPos, yyvsp[0].sym, NULL);;
+ break;}
+case 124:
+#line 241 "pascal.y"
+{/*call system function with arguments*/yyval.exp = A_CallExp(EM_tokPos, yyvsp[-3].sym, yyvsp[-1].explist);;
+ break;}
+case 125:
+#line 242 "pascal.y"
+{/*const expression*/ yyval.exp = yyvsp[0].exp;;
+ break;}
+case 126:
+#line 243 "pascal.y"
+{ /*expression*/ yyval.exp = yyvsp[-1].exp;;
+ break;}
+case 127:
+#line 244 "pascal.y"
+{ /*bool operation, not*/ yyval.exp = A_IfExp(EM_tokPos, yyvsp[0].exp, A_IntExp(EM_tokPos, 0), A_IntExp(EM_tokPos,1));;
+ break;}
+case 128:
+#line 245 "pascal.y"
+{/*expression with negative value*/ yyval.exp = A_OpExp(EM_tokPos, A_minusOp, A_IntExp(EM_tokPos, 0), yyvsp[0].exp);;
+ break;}
+case 129:
+#line 246 "pascal.y"
+{ /*subscript variable expression*/ yyval.exp = A_VarExp(EM_tokPos,A_SubscriptVar(EM_tokPos, A_SimpleVar(EM_tokPos, yyvsp[-3].sym), yyvsp[-1].exp));;
+ break;}
+case 130:
+#line 247 "pascal.y"
+{ /*field variable expression*/ yyval.exp = A_VarExp(EM_tokPos, A_FieldVar(EM_tokPos, A_SimpleVar(EM_tokPos, yyvsp[-2].sym), yyvsp[0].sym));;
+ break;}
+case 131:
+#line 248 "pascal.y"
+{yyval.explist = yyvsp[-2].explist; yyvsp[-2].explist->tail = A_ExpList(yyvsp[0].exp, NULL);;
+ break;}
+case 132:
+#line 249 "pascal.y"
+{yyval.explist = A_ExpList(yyvsp[0].exp, NULL);;
+ break;}
+case 133:
+#line 251 "pascal.y"
+{yyval.sym = S_Symbol(yyvsp[0].sval);;
+ break;}
+case 134:
+#line 252 "pascal.y"
+{yyval.sym = S_Symbol(yyvsp[0].sval);;
+ break;}
+case 135:
+#line 253 "pascal.y"
+{yyval.sym = S_Symbol(yyvsp[0].sval);;
+ break;}
+case 136:
+#line 254 "pascal.y"
+{yyval.sym = S_Symbol(yyvsp[0].sval);;
+ break;}
+case 137:
+#line 255 "pascal.y"
+{yyval.sym = S_Symbol(yyvsp[0].sval);;
+ break;}
+case 138:
+#line 257 "pascal.y"
+{/*jump to next semi after error */;
+ break;}
+}
+ /* the action file gets copied in in place of this dollarsign */
+#line 543 "/usr/local/share/bison.simple"
+
+ yyvsp -= yylen;
+ yyssp -= yylen;
+#ifdef YYLSP_NEEDED
+ yylsp -= yylen;
+#endif
+
+#if YYDEBUG != 0
+ if (yydebug)
+ {
+ short *ssp1 = yyss - 1;
+ fprintf (stderr, "state stack now");
+ while (ssp1 != yyssp)
+ fprintf (stderr, " %d", *++ssp1);
+ fprintf (stderr, "\n");
+ }
+#endif
+
+ *++yyvsp = yyval;
+
+#ifdef YYLSP_NEEDED
+ yylsp++;
+ if (yylen == 0)
+ {
+ yylsp->first_line = yylloc.first_line;
+ yylsp->first_column = yylloc.first_column;
+ yylsp->last_line = (yylsp-1)->last_line;
+ yylsp->last_column = (yylsp-1)->last_column;
+ yylsp->text = 0;
+ }
+ else
+ {
+ yylsp->last_line = (yylsp+yylen-1)->last_line;
+ yylsp->last_column = (yylsp+yylen-1)->last_column;
+ }
+#endif
+
+ /* Now "shift" the result of the reduction.
+ Determine what state that goes to,
+ based on the state we popped back to
+ and the rule number reduced by. */
+
+ yyn = yyr1[yyn];
+
+ yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
+ if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
+ yystate = yytable[yystate];
+ else
+ yystate = yydefgoto[yyn - YYNTBASE];
+
+ goto yynewstate;
+
+yyerrlab: /* here on detecting error */
+
+ if (! yyerrstatus)
+ /* If not already recovering from an error, report this error. */
+ {
+ ++yynerrs;
+
+#ifdef YYERROR_VERBOSE
+ yyn = yypact[yystate];
+
+ if (yyn > YYFLAG && yyn < YYLAST)
+ {
+ int size = 0;
+ char *msg;
+ int x, count;
+
+ count = 0;
+ /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
+ for (x = (yyn < 0 ? -yyn : 0);
+ x < (sizeof(yytname) / sizeof(char *)); x++)
+ if (yycheck[x + yyn] == x)
+ size += strlen(yytname[x]) + 15, count++;
+ msg = (char *) malloc(size + 15);
+ if (msg != 0)
+ {
+ strcpy(msg, "parse error");
+
+ if (count < 5)
+ {
+ count = 0;
+ for (x = (yyn < 0 ? -yyn : 0);
+ x < (sizeof(yytname) / sizeof(char *)); x++)
+ if (yycheck[x + yyn] == x)
+ {
+ strcat(msg, count == 0 ? ", expecting `" : " or `");
+ strcat(msg, yytname[x]);
+ strcat(msg, "'");
+ count++;
+ }
+ }
+ yyerror(msg);
+ free(msg);
+ }
+ else
+ yyerror ("parse error; also virtual memory exceeded");
+ }
+ else
+#endif /* YYERROR_VERBOSE */
+ yyerror("parse error");
+ }
+
+ goto yyerrlab1;
+yyerrlab1: /* here on error raised explicitly by an action */
+
+ if (yyerrstatus == 3)
+ {
+ /* if just tried and failed to reuse lookahead token after an error, discard it. */
+
+ /* return failure if at end of input */
+ if (yychar == YYEOF)
+ YYABORT;
+
+#if YYDEBUG != 0
+ if (yydebug)
+ fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
+#endif
+
+ yychar = YYEMPTY;
+ }
+
+ /* Else will try to reuse lookahead token
+ after shifting the error token. */
+
+ yyerrstatus = 3; /* Each real token shifted decrements this */
+
+ goto yyerrhandle;
+
+yyerrdefault: /* current state does not do anything special for the error token. */
+
+#if 0
+ /* This is wrong; only states that explicitly want error tokens
+ should shift them. */
+ yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
+ if (yyn) goto yydefault;
+#endif
+
+yyerrpop: /* pop the current state because it cannot handle the error token */
+
+ if (yyssp == yyss) YYABORT;
+ yyvsp--;
+ yystate = *--yyssp;
+#ifdef YYLSP_NEEDED
+ yylsp--;
+#endif
+
+#if YYDEBUG != 0
+ if (yydebug)
+ {
+ short *ssp1 = yyss - 1;
+ fprintf (stderr, "Error: state stack now");
+ while (ssp1 != yyssp)
+ fprintf (stderr, " %d", *++ssp1);
+ fprintf (stderr, "\n");
+ }
+#endif
+
+yyerrhandle:
+
+ yyn = yypact[yystate];
+ if (yyn == YYFLAG)
+ goto yyerrdefault;
+
+ yyn += YYTERROR;
+ if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
+ goto yyerrdefault;
+
+ yyn = yytable[yyn];
+ if (yyn < 0)
+ {
+ if (yyn == YYFLAG)
+ goto yyerrpop;
+ yyn = -yyn;
+ goto yyreduce;
+ }
+ else if (yyn == 0)
+ goto yyerrpop;
+
+ if (yyn == YYFINAL)
+ YYACCEPT;
+
+#if YYDEBUG != 0
+ if (yydebug)
+ fprintf(stderr, "Shifting error token, ");
+#endif
+
+ *++yyvsp = yylval;
+#ifdef YYLSP_NEEDED
+ *++yylsp = yylloc;
+#endif
+
+ yystate = yyn;
+ goto yynewstate;
+
+ yyacceptlab:
+ /* YYACCEPT comes here. */
+ if (yyfree_stacks)
+ {
+ free (yyss);
+ free (yyvs);
+#ifdef YYLSP_NEEDED
+ free (yyls);
+#endif
+ }
+ return 0;
+
+ yyabortlab:
+ /* YYABORT comes here. */
+ if (yyfree_stacks)
+ {
+ free (yyss);
+ free (yyvs);
+#ifdef YYLSP_NEEDED
+ free (yyls);
+#endif
+ }
+ return 1;
+}
+#line 259 "pascal.y"
+
+int yyerror(char* msg) {
+ EM_error(EM_tokPos, "%s", msg);
+ return 0;
+}
+
+// link two fieldlists
+A_fieldList A_linkFieldList(A_fieldList front, A_fieldList tail) {
+ if (!front)
+ return tail;
+ A_fieldList pos = front;
+ for (;pos->tail;pos = pos->tail);
+ pos->tail = tail;
+
+ return front;
+}
+
+// set fieldList's type to ty
+A_fieldList A_setFieldListType(A_fieldList fieldList, A_ty ty) {
+ A_fieldList front = fieldList;
+ for (;fieldList;fieldList = fieldList->tail) {
+ fieldList->head->typ = ty;
+ }
+
+ return front;
+}
+
+A_decList A_linkDecList(A_decList front, A_decList tail) {
+ if (!front)
+ return tail;
+ A_decList pos = front;
+ for (;pos->tail;pos = pos->tail);
+ pos->tail = tail;
+
+ return front;
+}
+
+A_decList A_setDecListType(A_decList decList, A_ty ty) {
+ A_decList front = decList;
+ for (;decList;decList = decList->tail) {
+ decList->head->u.var.typ = ty;
+ }
+
+ return front;
+}
+
+A_decList A_unDecList(A_fieldList fieldList) {
+ // null field list
+ if (!fieldList)
+ return NULL;
+
+ A_field field = fieldList->head;
+ A_decList decList = A_DecList(A_VarDec(field->pos, field->name, field->typ, NULL), NULL);
+ A_decList front = decList;
+
+ for(fieldList= fieldList->tail;fieldList;fieldList = fieldList->tail, decList = decList->tail) {
+ field = fieldList->head;
+ decList->tail = A_DecList(A_VarDec(field->pos, field->name, field->typ, NULL), NULL);
+ }
+
+ return front;
+}
diff --git a/CompilerPascal/pascal.tab.h b/CompilerPascal/pascal.tab.h
new file mode 100644
index 0000000..17659f7
--- /dev/null
+++ b/CompilerPascal/pascal.tab.h
@@ -0,0 +1,82 @@
+typedef union {
+ int pos;
+ int ival;
+ double rval;
+ char cval;
+ string sval;
+
+ A_var var;
+ A_exp exp;
+ S_symbol sym;
+ A_dec dec;
+ A_decList declist;
+ A_expList explist;
+ A_efieldList efieldlist;
+ A_ty ty;
+ A_fieldList fieldlist;
+ A_fundec fundec;
+ A_fundecList fundeclist;
+ A_namety namety;
+ A_nametyList nametylist;
+} YYSTYPE;
+#define LP 257
+#define RP 258
+#define LB 259
+#define RB 260
+#define DOT 261
+#define COMMA 262
+#define COLON 263
+#define SEMI 264
+#define PLUS 265
+#define MINUS 266
+#define MUL 267
+#define REALDIV 268
+#define INTDIV 269
+#define MOD 270
+#define AND 271
+#define OR 272
+#define NOT 273
+#define GE 274
+#define GT 275
+#define LE 276
+#define LT 277
+#define EQUAL 278
+#define UNEQUAL 279
+#define ASSIGN 280
+#define PROGRAM 281
+#define FUNCTION 282
+#define PROCEDURE 283
+#define BEGIN_T 284
+#define END 285
+#define TYPE 286
+#define ARRAY 287
+#define OF 288
+#define RECORD 289
+#define VAR 290
+#define IF 291
+#define THEN 292
+#define ELSE 293
+#define REPEAT 294
+#define TO 295
+#define DOWNTO 296
+#define UNTIL 297
+#define WHILE 298
+#define DO 299
+#define FOR 300
+#define CASE 301
+#define GOTO 302
+#define READ 303
+#define CONST 304
+#define DOTDOT 305
+#define INTEGER 306
+#define REAL 307
+#define CHAR 308
+#define ID 309
+#define STRING 310
+#define SYS_CON 311
+#define SYS_FUNCT 312
+#define SYS_PROC 313
+#define SYS_TYPE 314
+
+
+extern YYSTYPE yylval;
diff --git a/src/prabsyn.c b/CompilerPascal/prabsyn.c
similarity index 94%
rename from src/prabsyn.c
rename to CompilerPascal/prabsyn.c
index ef66917..69953b1 100644
--- a/src/prabsyn.c
+++ b/CompilerPascal/prabsyn.c
@@ -85,6 +85,9 @@ void pr_exp(FILE *out, A_exp v, int d) {
case A_intExp:
fprintf(out, "intExp(%d)", v->u.intt);
break;
+ case A_charExp:
+ fprintf(out, "charExp(%c)", v->u.charr);
+ break;
case A_stringExp:
chstr(v->u.stringg);
fprintf(out, "stringExp(%s)", res);
@@ -210,8 +213,10 @@ static void pr_dec(FILE *out, A_dec v, int d) {
case A_varDec:
fprintf(out, "varDec(%s,\n", S_name(v->u.var.var));
if (v->u.var.typ) {
- indent(out, d+1); fprintf(out, "%s,\n", S_name(v->u.var.typ));
+ // indent(out, d+1);
+ pr_ty(out, v->u.var.typ, d+1);
}
+ fprintf(out, ",\n");
pr_exp(out, v->u.var.init, d+1); fprintf(out, ",\n");
indent(out, d+1); fprintf(out, "%s", v->u.var.escape ? "TRUE)" : "FALSE)");
break;
@@ -235,8 +240,16 @@ static void pr_ty(FILE *out, A_ty v, int d) {
pr_fieldList(out, v->u.record, d+1); fprintf(out, ")");
break;
case A_arrayTy:
- fprintf(out, "arrayTy(%s)", S_name(v->u.arrayy.element));
+ fprintf(out, "arrayTy(%s)[", S_name(v->u.arrayy.element->u.name));
+ pr_ty(out, v->u.arrayy.range, 0);
+ fprintf(out, "]");
break;
+ case A_rangeTy:
+ fprintf(out, "rangeTy(");
+ pr_exp(out, v->u.rangee.lo, 0);
+ fprintf(out, "..");
+ pr_exp(out, v->u.rangee.hi, 0);
+ break;
default:
assert(0);
}
@@ -245,7 +258,7 @@ static void pr_ty(FILE *out, A_ty v, int d) {
static void pr_field(FILE *out, A_field v, int d) {
indent(out, d);
fprintf(out, "field(%s,\n", S_name(v->name));
- indent(out, d+1); fprintf(out, "%s,\n", S_name(v->typ));
+ indent(out, d+1); fprintf(out, "%s,\n", S_name(v->typ->u.name));
indent(out, d+1); fprintf(out, "%s", v->escape ? "TRUE)" : "FALSE)");
}
diff --git a/src/prabsyn.h b/CompilerPascal/prabsyn.h
similarity index 100%
rename from src/prabsyn.h
rename to CompilerPascal/prabsyn.h
diff --git a/src/printtree.c b/CompilerPascal/printtree.c
similarity index 89%
rename from src/printtree.c
rename to CompilerPascal/printtree.c
index 748cd35..bb703d6 100644
--- a/src/printtree.c
+++ b/CompilerPascal/printtree.c
@@ -26,6 +26,8 @@ static char rel_oper[][12] = {
static void pr_stm(FILE *out, T_stm stm, int d)
{
+ if (!stm)
+ return;
switch (stm->kind) {
case T_SEQ:
indent(out,d);
@@ -60,6 +62,8 @@ static void pr_stm(FILE *out, T_stm stm, int d)
static void pr_tree_exp(FILE *out, T_exp exp, int d)
{
+ if (!exp)
+ return;
switch (exp->kind) {
case T_BINOP:
indent(out,d); fprintf(out, "BINOP(%s,\n", bin_oper[exp->u.BINOP.op]);
@@ -68,7 +72,7 @@ static void pr_tree_exp(FILE *out, T_exp exp, int d)
break;
case T_MEM:
indent(out,d); fprintf(out, "MEM");
- fprintf(out, "(\n"); pr_tree_exp(out, exp->u.MEM,d+1); fprintf(out, ")");
+ fprintf(out, "(\n"); pr_tree_exp(out, exp->u.MEM.exp,d+1); fprintf(out, "):%d", exp->u.MEM.size);
break;
case T_TEMP:
indent(out,d); fprintf(out, "TEMP t%s",
@@ -85,6 +89,12 @@ static void pr_tree_exp(FILE *out, T_exp exp, int d)
case T_CONST:
indent(out,d); fprintf(out, "CONST %d", exp->u.CONST);
break;
+ case T_DOUBLE:
+ indent(out,d); fprintf(out, "DOUBLE %lf", exp->u.DOUBLE);
+ break;
+ case T_CHAR:
+ indent(out, d); fprintf(out, "CONST %c", exp->u.CHAR);
+ break;
case T_CALL:
{T_expList args = exp->u.CALL.args;
indent(out,d); fprintf(out, "CALL(\n"); pr_tree_exp(out, exp->u.CALL.fun,d+1);
@@ -101,5 +111,6 @@ void printStmList (FILE *out, T_stmList stmList)
{
for (; stmList; stmList=stmList->tail) {
pr_stm(out, stmList->head,0); fprintf(out, "\n");
+ fprintf(out, "\n------\n");
}
-}
+}
\ No newline at end of file
diff --git a/src/printtree.h b/CompilerPascal/printtree.h
similarity index 91%
rename from src/printtree.h
rename to CompilerPascal/printtree.h
index 85759ff..ba8bdf5 100644
--- a/src/printtree.h
+++ b/CompilerPascal/printtree.h
@@ -2,6 +2,7 @@
#define PRINT_TREE_H
#include
#include
+#include "tree.h"
/* function prototype from printtree.c */
void printStmList (FILE *out, T_stmList stmList) ;
#endif
diff --git a/CompilerPascal/semant.c b/CompilerPascal/semant.c
new file mode 100644
index 0000000..8956e26
--- /dev/null
+++ b/CompilerPascal/semant.c
@@ -0,0 +1,969 @@
+#include
+#include
+#include
+#include "util.h"
+#include "errormsg.h"
+#include "symbol.h"
+#include "absyn.h"
+#include "types.h"
+#include "temp.h"
+#include "tree.h"
+#include "frame.h"
+#include "env.h"
+#include "semant.h"
+#include "printtree.h"
+
+extern bool anyErrors;
+static A_fundec nowCheckFun = NULL;
+
+F_fragList transProg(A_exp exp)
+{
+ struct expty exptype;
+ S_table basefunenv=Base_funenv();
+ S_table basevarenv=Base_varenv();
+ exptype=transExp(Tr_outermost(),NULL,basefunenv,basevarenv,exp);
+ printf("Expression with return type: %d\n",exptype.ty->flag);
+ Tr_procEntryExit(Tr_outermost(), exptype.exp, NULL);
+ F_fragList ret=Tr_getResult();
+
+ return ret;
+}
+
+struct expty Newexpty(Tr_exp e, Type t)
+{
+ struct expty et;
+ et.exp = e;
+ et.ty = t;
+ return et;
+}
+static U_boolList makeFormals(A_fieldList params)
+{
+ U_boolList head = NULL, tail = NULL;
+ A_fieldList p = params;
+ for (; p; p = p->tail) {
+ if (head) {
+ tail->tail = U_BoolList(p->head->escape, NULL);
+ tail = tail->tail;
+ }
+ else {
+ tail = head = U_BoolList(p->head->escape, NULL);
+ }
+ /*if (head) {
+ tail->tail = U_BoolList(TRUE, NULL);
+ tail = tail->tail;
+ } else {
+ head = U_BoolList(TRUE, NULL);
+ tail = head;
+ }*/
+ }
+ return head;
+}
+static Typelist gettypelist(S_table varenv,A_fieldList list)
+{
+ Typelist head=NULL;
+ Typelist tail=NULL;
+ A_fieldList ptr=list;
+ Type tmpty;
+
+ while(ptr)
+ {
+ tmpty=S_look(varenv,ptr->head->typ->u.name);
+ if(!tmpty)
+ {
+ EM_error(ptr->head->pos,"Type %s undefined\n",S_name(ptr->head->typ->u.name));
+ tmpty=INT_type();
+ }
+ if(!head)//head==NULL
+ head=tail=Newtypelist(tmpty,NULL);
+ else
+ {
+ tail->next=Newtypelist(tmpty,NULL);
+ tail=tail->next;
+ }
+ ptr=ptr->tail;
+ }
+ return head;
+}
+
+Type gettype(Type ty)
+{
+ if(!ty)
+ return NULL;
+ else if(ty->flag==NAME)
+ gettype(ty->u.name.ty);
+ else
+ return ty;
+}
+
+static Fieldlist getfieldlist(S_table varenv,A_fieldList list)
+{
+ Fieldlist head=NULL;
+ Fieldlist tail=NULL;
+ A_fieldList ptr=list;
+ Type tmpty;
+ Field tmpfd;
+
+ while(ptr)
+ {
+ tmpty=S_look(varenv,ptr->head->typ->u.name);
+ if(!tmpty)
+ EM_error(ptr->head->pos,"Type %s undefined\n",S_name(ptr->head->typ->u.name));
+ else
+ {
+ tmpfd=Newfield(ptr->head->name,tmpty);
+ if(!head)
+ head=tail=Newfieldlist(tmpfd,NULL);
+ else
+ {
+ tail->next=Newfieldlist(tmpfd,NULL);
+ tail=tail->next;
+ }
+ }
+ ptr = ptr->tail;
+ }
+ return head;
+}
+
+int totalLen = 0;
+static int getSize(Type ty)
+{
+
+ ty = gettype(ty);
+ switch(ty->flag){
+ case VOID: {return 0;}
+ case BOOLEAN: return 1;
+ case CHAR: return 1;
+ case INT: return 4;
+ case REAL: return 8;
+ case STRING: return 255;
+ case ARRAY: {
+ int num;
+ Type arrayTy = gettype(ty->u.arrayInfo->ty);
+ if(arrayTy->flag == INT)
+ num = ty->u.arrayInfo->u.intt.end-ty->u.arrayInfo->u.intt.start+1;
+ else if(arrayTy->flag == CHAR)
+ num = ty->u.arrayInfo->u.charr.end-ty->u.arrayInfo->u.charr.start+1;
+ totalLen = num;
+ return num*getSize(ty->u.arrayInfo->tyEle);
+ }
+ case RECORD:{
+ Fieldlist re = ty->u.record;
+ Field nowF;
+ int num = 0;
+ for(re; re!=NULL; re = re->next)
+ {
+ nowF = re->head;
+ num+=getSize(nowF->ty);
+ }
+ return num;
+ }
+ }
+}
+
+static struct expty transVar(Tr_level l,Tr_exp e,S_table funenv,S_table varenv,A_var var)
+{
+ if(!var)
+ return Newexpty(Tr_NoExp(), VOID_type());
+ Environments env;
+ struct expty pt1,pt2;
+ Fieldlist tmpfl;
+ Tr_exp trans;
+
+ if(var->kind==A_simpleVar)
+ {
+ env= (Environments)S_look(funenv,var->u.simple);
+ trans=Tr_NoExp();
+ //µ±Ç°ÊǼì²éº¯ÊýµÄʱºò,º¯ÊýÃû¶ÔÓ¦ÄÚÈÝÒ²Òª·µ»Ø
+ if(env && (env->flag==VAR||env->flag == CONST))
+ {
+ trans=Tr_SimpleVar(env->u.var.acc,l);
+ struct expty temExp = Newexpty(trans,gettype(env->u.var.ty));
+ if(env->flag == CONST)
+ temExp.isConst = 1;
+ else temExp.isConst = 0;
+ return temExp;
+ }
+ //½öÓÃÓÚº¯Êý·µ»ØÖµÀàÐͼì²é
+ else if(env&&env->flag == FUN&&nowCheckFun&&checkEqSymbol(nowCheckFun->name, var->u.simple))
+ {
+ return Newexpty(NULL, gettype(env->u.fun.output));
+ }
+ else
+ {
+ EM_error(var->pos,"Variable %s undefined\n",S_name(var->u.simple));
+ return Newexpty(trans,INT_type());
+ }
+ }
+ else if(var->kind==A_fieldVar)
+ {
+ //½«x.yÖеÄx°üװһϣ¬x±»¶¨ÒåΪsimpleVar£¬¿ÉÒÔ´Ó·ûºÅ±íÖвéÕÒ³öfieldlist¡£
+ pt1=transVar(l,e,funenv,varenv,var->u.field.var);
+ trans=Tr_NoExp();
+ if(pt1.ty->flag!=RECORD)
+ {
+ EM_error(var->pos,"Expected a record type\n");
+ return Newexpty(trans,INT_type());
+ }
+ else
+ {
+ int i=0;
+ for(tmpfl=pt1.ty->u.record;tmpfl;tmpfl=tmpfl->next,i++)
+ if(tmpfl->head->name==var->u.field.sym)
+ {
+ int size = getSize(tmpfl->head->ty);
+
+ trans=Tr_FieldVar(pt1.exp,i,size);
+ return Newexpty(trans,gettype(tmpfl->head->ty));
+ }
+ EM_error(var->pos,"Field %s not found\n",S_name(var->u.field.sym)); //not fount in record
+ return Newexpty(trans,INT_type());
+ }
+ }
+ else if(var->kind==A_subscriptVar)
+ {
+ pt1=transVar(l,e,funenv,varenv,var->u.subscript.var);
+ trans=Tr_NoExp();
+ if(pt1.ty->flag!=ARRAY)
+ {
+ EM_error(var->pos,"Expected an array type\n");
+ return Newexpty(trans,INT_type());
+ }
+ else
+ {
+ pt2=transExp(l,e,funenv,varenv,var->u.subscript.exp);
+
+ if(pt2.ty->flag==INT||pt2.ty->flag == CHAR)
+ {
+ int size = getSize(pt1.ty);
+ size /= totalLen;
+ totalLen = 0;
+ trans=Tr_SubscriptVar(pt1.exp,pt2.exp,size);
+ return Newexpty(trans,gettype(pt1.ty->u.arrayInfo->ty));
+ }
+ else if(pt2.ty->flag == ENUM)
+ {
+ //´¦ÀítransExpºóÔÙд£¨ÐèÒª»ñÈ¡EnumµÄÀàÐÍ£¬»¹Óе±Ç°Êǵڼ¸¸ö£©
+ }
+ else
+ {
+ EM_error(var->pos,"Index must be an interger\n");
+ return Newexpty(trans,INT_type());
+ }
+ }
+ }
+
+ printf("Transvar inner error!\n");
+ exit(1);
+}
+
+static struct expty transExp(Tr_level l,Tr_exp e,S_table funenv,S_table varenv,A_exp exp)
+{
+ if(!exp)
+ return Newexpty(Tr_NoExp(), VOID_type());
+ if(exp->kind==A_varExp)
+ return transVar(l,e,funenv,varenv,exp->u.var);
+ else if(exp->kind==A_stringExp)
+ return Newexpty(Tr_StringExp(255 ,exp->u.stringg),STRING_type());
+ else if(exp->kind==A_intExp)
+ return Newexpty(Tr_IntExp(exp->u.intt),INT_type());
+ else if(exp->kind==A_realExp)
+ return Newexpty(Tr_RealExp(exp->u.real),REAL_type());
+ else if(exp->kind==A_charExp)
+ return Newexpty(Tr_CharExp(exp->u.charr),CHAR_type());
+ else if(exp->kind==A_recordExp)
+ {
+ A_efieldList itemList =exp->u.record.fields;
+ int n = 0;
+ Tr_expList fields = NULL;
+ Type recordTy;
+ recordTy = gettype(S_look(varenv, exp->u.record.typ));
+ if(!recordTy)
+ EM_error(exp->pos,"Type %s undefined\n",S_name(exp->u.record.typ));
+ else{
+ if(recordTy->flag!=RECORD)
+ {
+ EM_error(exp->pos,"Record type expected, get %s\n",S_name(exp->u.record.typ));
+ return Newexpty(Tr_NoExp(),RECORD_type(NULL));
+ }
+ Fieldlist fieldTyList = recordTy->u.record;
+ U_intList itemSizeList = NULL;
+ for(itemList; itemList; itemList = itemList->tail, fieldTyList = fieldTyList->next, n++){
+ struct expty et = transExp(l, e, funenv, varenv, itemList->head->exp);
+ if (itemList->head->name != fieldTyList->head->name)
+ EM_error(exp->pos, "%s not a valid field name", itemList->head->name);
+ if (!type_match(fieldTyList->head->ty, et.ty))
+ EM_error(itemList->head->exp->pos, "Type mismatch");
+ itemSizeList = U_IntList(getSize(et.ty), itemSizeList);
+ //½«Tr_expÁ¬½ÓÆðÀ´
+ // Tr_explistnewhead(et.exp, &fields);
+ fields = Tr_ExpList(et.exp, fields);
+
+ }
+ return Newexpty(Tr_RecordExp(itemSizeList, fields), recordTy);
+ }
+ return Newexpty(Tr_NoExp(),RECORD_type(NULL));
+ }
+ else if(exp->kind==A_boolExp)
+ return Newexpty(Tr_BoolExp(exp->u.booll),BOOLEAN_type());
+ else if(exp->kind==A_breakExp)
+ {
+ if(!e)
+ return Newexpty(Tr_NoExp(),VOID_type());
+ return Newexpty(Tr_BreakExp(e),VOID_type());
+ }
+ else if(exp->kind==A_callExp)
+ {
+ Environments callinfo;
+ A_expList params=NULL;
+ Tr_expList paramlist=NULL;
+ Typelist fmls;
+ callinfo=S_look(funenv,exp->u.call.func);
+ Tr_exp trans=Tr_NoExp();
+ if(callinfo && callinfo->flag==FUN)
+ {
+ fmls=callinfo->u.fun.param;
+ //½«²ÎÊý´¦ÀíºÃºó·ÅÈëµ½Tr_explistÖÐ
+ for(params=exp->u.call.args;params&&fmls;params=params->tail,fmls=fmls->next)
+ {
+ struct expty arg=transExp(l,e,funenv,varenv,params->head);
+ if(!type_match(arg.ty,fmls->head))
+ EM_error(params->head->pos,"Function %s type mismatch\n",S_name(exp->u.call.func));
+ paramlist = Tr_ExpList(arg.exp,paramlist);
+ }
+
+ if(!params&&fmls)
+ EM_error(exp->pos,"Too few parameters");
+ if(params&&!fmls)
+ EM_error(exp->pos,"Too many parameters");
+
+ //°ü×°³ÉT_expµÄÐÎʽ
+ trans=Tr_CallExp(callinfo->u.fun.label,callinfo->u.fun.lev,l,paramlist);
+ return Newexpty(trans,gettype(callinfo->u.fun.output));
+ }
+ else
+ {
+ EM_error(exp->pos, "Function name %s undefined\n");
+ return Newexpty(trans, INT_type());
+ }
+ }
+ /* ²»ÐèÒªÕâÖÖÓï¾ä
+ else if(exp->kind==A_recordExp)
+ {
+ Type rectp;
+ rectp=gettype(S_look(varenv,exp->u.record.typ));
+ if(!rectp)
+ EM_error(exp->pos,"Type %s undefined\n",S_name(exp->u.record.typ));
+ else
+ {
+ if(rectp->flag!=RECORD)
+ {
+ EM_error(exp->pos,"Record type expected, get %s\n",S_name(exp->u.record.typ));
+ return Newexpty(Tr_NoExp(),RECORD_type(NULL));
+ }
+ Fieldlist fieldTys = rectp->u.record;
+ A_efieldList recList;
+ Tr_explist list = NULL;
+ int n = 0;
+ //±éÀúrecordÖеÄÿһ¸öÔªËØ£¬recListÖаüº¬Ã¿Ò»¸ö±äÁ¿Ãû¼°¸³Öµexp
+ for (recList = exp->u.record.fields; recList; recList = recList->tail, fieldTys = fieldTys->next, n++)
+ {
+ struct expty et = transExp(l,e,funenv,varenv, recList->head->exp);
+ if (recList->head->name != fieldTys->head->name)
+ EM_error(exp->pos, "%s not a valid field name", recList->head->name);
+ if (!type_match(fieldTys->head->ty, et.ty))
+ EM_error(recList->head->exp->pos, "Type mismatch");
+
+ //½«Tr_expÁ¬½ÓÆðÀ´
+ Tr_explistnewhead(et.exp, &list);
+ }
+ return Newexpty(recordExp(n, list), rectp);
+ }
+ return Newexpty(Tr_NoExp(),RECORD_type(NULL));
+ }
+ */
+ //ÐèÒªÐ޸쬵ÈabsynÐ޸ĺÃÖ®ºó£¬ÔÙ´¦Àí
+ /*不需要了
+ else if(exp->kind==A_arrayExp)
+ {
+ Type artp;
+ Type finaltp;
+ artp = S_look(varenv, exp->u.array.typ);
+ printf("\n");
+ if (artp->flag == NAME)
+ finaltp=artp->u.name.ty;
+ else
+ finaltp= artp;
+ //finaltp = gettype(artp);
+ if(!finaltp)
+ {
+ EM_error(exp->pos,"Array type %s undefined\n",S_name(exp->u.array.typ));
+ return Newexpty(Tr_NoExp(),INT_type());
+ }
+ else if(finaltp->flag!=ARRAY)
+ {
+ EM_error(exp->pos,"Array type expected, get %s\n",S_name(exp->u.array.typ));
+ return Newexpty(Tr_NoExp(),INT_type());
+ }
+
+ struct expty size, init;
+ size = transExp(l,e, funenv, varenv, exp->u.array.size);
+ init = transExp(l,e, funenv, varenv, exp->u.array.init);
+ if(exp->u.array.size->kind == A_varExp&&size.isConst != 1)
+ EM_error(exp->pos,"Array %s size cannot be simple var\n",exp->u.array.typ);
+ else if(size.ty->flag!=INT && size.ty->flag!=CHAR)
+ EM_error(exp->pos,"Array %s size must be an interger or char.\n",exp->u.array.typ);
+ else if(size->flag!=init->flag)
+ EM_error(exp->pos,"Array initation and final number's type are different\n");
+ else if(!type_match(init.ty, finaltp))
+ EM_error(exp->pos,"Array %s type mismatch\n",exp->u.array.typ);
+ else
+ {
+ int sizeEvery = getSize(exp);
+
+ Tr_expList expList = Tr_ExpList(size.exp, NULL);
+ expList = Tr_expList(init.exp, expList);
+
+ return Newexpty(Tr_ArrayExp(sizeEvery, totalLen, expList),artp);
+ }
+ return Newexpty(Tr_NoExp(),INT_type());
+ }
+ */
+ else if(exp->kind==A_seqExp)
+ {
+ Tr_expList lis=NULL;
+ A_expList explist;
+ struct expty seq;
+ explist=exp->u.seq;
+ if(!explist)
+ return Newexpty(Tr_NoExp(),VOID_type());
+ while(explist->head)
+ {
+ seq=transExp(l,e,funenv,varenv,explist->head);
+ printf("\n");
+ lis = Tr_ExpList(seq.exp,lis);
+ if (explist->tail == NULL)
+ break;
+ explist=explist->tail;
+ }
+ return Newexpty(Tr_SeqExp(lis),seq.ty);
+ }
+ else if(exp->kind==A_whileExp)
+ {
+ struct expty cond;
+ cond=transExp(l,e,funenv,varenv,exp->u.whilee.test);
+ if(cond.ty->flag!=BOOLEAN)
+ {
+ EM_error(exp->pos,"Integer expected in while\n");
+ return Newexpty(Tr_NoExp(),INT_type());
+ }
+// Tr_exp done=doneExp();
+ struct expty body=transExp(l,e,funenv,varenv,exp->u.whilee.body);
+ return Newexpty(Tr_WhileExp(cond.exp, body.exp),VOID_type());
+ }
+ else if(exp->kind==A_assignExp)
+ {
+ struct expty left,right;
+ left=transVar(l,e,funenv,varenv,exp->u.assign.var);
+ right=transExp(l,e,funenv,varenv,exp->u.assign.exp);
+ if(right.ty->flag == CONST)
+ {
+ EM_error(exp->pos, "Cannot assign to the const\n");
+ }
+ else if(!type_match(left.ty,right.ty))
+ {
+ if(left.exp == NULL){//ÓÃÓÚº¯Êý·µ»ØÖµÀàÐͼì²é
+ EM_error(nowCheckFun->pos, "incorrect return type in function '%s'", S_name(nowCheckFun->name));
+ }
+ else if(left.isConst)
+ {
+ EM_error(exp->pos, "Don't assign to the const\n");
+ }
+ else
+ EM_error(exp->pos,"Assign type mismatch\n");
+ return Newexpty(Tr_NoExp(),INT_type());
+ }
+ if (nowCheckFun&&checkEqSymbol(nowCheckFun->name, exp->u.assign.var->u.simple))
+ {
+ return Newexpty(Tr_RetExp(right.exp), right.ty);
+ }
+ else
+ return Newexpty(Tr_AssignExp(left.exp, right.exp),VOID_type());
+ }
+ //Óï·¨·ÖÎö½«forת»¯Îªwhile£¬´Ë´¦²»ÐèÒª´¦Àí
+ else if(exp->kind==A_forExp)
+ {
+ /*
+ struct expty start,end,stm;
+ start=transExp(l,e,funenv,varenv,exp->u.forr.lo);
+ end=transExp(l,e,funenv,varenv,exp->u.forr.hi);
+ if(start.ty!=INT||end.ty!=INT)
+ EM_error(exp->pos,"Expected integer range type");
+ Typeprint(start.ty);
+ Typeprint(end.ty);
+ S_beginScope(funenv);
+ transDec(l,e,funenv,varenv,A_VarDec(exp->pos,exp->u.forr.var, S_Symbol("int"),exp->u.forr.lo));
+ stm=transExp(l,e,funenv,varenv,exp->u.forr.body);
+ S_endScope(funenv);
+ */
+ return Newexpty(Tr_NoExp(),VOID_type());
+ }
+ else if(exp->kind==A_letExp)
+ {
+ A_decList declist;
+ Tr_expList list = NULL;
+ struct expty body;
+ S_beginScope(funenv);
+ S_beginScope(varenv);
+ /* for(declist=exp->u.let.decs;declist;declist=declist->tail)
+ list = Tr_ExpList(transDec(l,e,funenv,varenv,declist->head),list);*/
+ int count = 0;
+ for (declist = exp->u.let.decs; declist; declist = declist->tail) {
+ //printf("%d", count++);
+ transDec(l, e, funenv, varenv, declist->head);
+
+ }
+
+ body=transExp(l,e,funenv,varenv,exp->u.let.body);
+ list = Tr_ExpList(body.exp, list);
+ // Tr_explistnewhead(body.exp,&list);
+ S_endScope(varenv, 0);
+ S_endScope(funenv, 1);
+ return Newexpty(Tr_SeqExp(list),body.ty);
+ }
+
+ else if(exp->kind==A_opExp)
+ {
+ struct expty left,right;
+ A_oper oper;
+ oper=exp->u.op.oper;
+ left=transExp(l,e,funenv,varenv,exp->u.op.left);
+ right=transExp(l,e,funenv,varenv,exp->u.op.right);
+ //¼Ó¼õ³Ë³ý
+ if(oper>=A_plusOp&&oper<= A_realDivideOp)
+ {
+ if(left.ty->flag!=INT&&left.ty->flag!=REAL)
+ EM_error(exp->u.op.left->pos,"Expected Integer or double left operand\n");
+ if(right.ty->flag!=INT&&right.ty->flag!=REAL)
+ EM_error(exp->u.op.right->pos,"Expected Integer or double right operand\n");
+
+ //³ý·¨È«²¿±äΪdoubleÀàÐÍ
+ if(left.ty->flag==INT&&right.ty->flag==INT&&oper!= A_realDivideOp)
+ return Newexpty(Tr_OpExp(oper, left.exp, right.exp),INT_type());
+ else
+ return Newexpty(Tr_OpExp(oper, left.exp, right.exp),REAL_type());
+ }
+ else if (oper == A_divideOp||oper == A_modOp) {
+ if (left.ty->flag != INT || right.ty->flag != INT)
+ {
+ EM_error(exp->u.op.right->pos, "Expected Integer or double right operand\n");
+ }
+ else
+ return Newexpty(Tr_OpExp(oper, left.exp, right.exp), INT_type());
+ }
+ //µÈÓÚ²»µÈÓÚ£¬Ð¡ÓÚ£¬Ð¡ÓÚµÈÓÚ£¬´óÓÚ£¬´óÓÚµÈÓÚ
+ else if(oper>=A_eqOp&&oper<=A_geOp)
+ {
+ Tr_exp trans=Tr_NoExp();
+ if(oper==A_eqOp||oper==A_neqOp)
+ {
+ if(left.ty->flag==INT||left.ty->flag==REAL)
+ {
+ if(right.ty->flag == INT || right.ty->flag == REAL)
+ trans = Tr_RelExp(oper, left.exp, right.exp);
+ else
+ EM_error(exp->u.op.right->pos, "unexpected type in comparsion\n");
+ }
+ else if(left.ty->flag == CHAR)
+ {
+ if(type_match(right.ty, left.ty))
+ trans = Tr_RelExp(oper, left.exp, right.exp);
+ else
+ EM_error(exp->u.op.right->pos, "unexpected type in comparsion\n");
+ }
+ else if(left.ty->flag == BOOLEAN)
+ {
+ if(type_match(right.ty, left.ty))
+ trans = Tr_RelExp(oper, left.exp, right.exp);
+ else
+ EM_error(exp->u.op.right->pos, "unexpected type in comparsion\n");
+ }
+ else if(left.ty->flag==STRING)
+ {
+ if(type_match(right.ty, left.ty))
+ trans = Tr_StringRelExp(oper, left.exp, right.exp);
+ else
+ EM_error(exp->u.op.right->pos, "unexpected type in comparsion\n");
+ }
+ /*
+ else if (left.ty->flag == ARRAY)
+ {
+ if(type_match(right.ty, left.ty))
+ trans = eqRef(oper, left.exp, right.exp);
+ else
+ EM_error(exp->u.op.right->pos, "unexpected type in comparsion\n");
+ }
+ else if(left.ty->flag==RECORD)
+ {
+ if(type_match(right.ty, left.ty) || right.ty->flag == NIL)
+ trans = eqRef(oper, left.exp, right.exp);
+ else
+ EM_error(exp->u.op.right->pos, "unexpected type in comparsion\n");
+ }
+ */
+ else
+ EM_error(exp->u.op.right->pos, "unexpected expression in comparsion\n");
+ return Newexpty(trans,BOOLEAN_type());
+ }
+ else
+ {
+ if(left.ty->flag==INT||left.ty->flag==REAL)
+ {
+ if(right.ty->flag == INT || right.ty->flag == REAL)
+ trans = Tr_RelExp(oper, left.exp, right.exp);
+ else
+ EM_error(exp->u.op.right->pos, "unexpected type in comparsion\n");
+ }
+ else if(left.ty->flag==CHAR)
+ {
+ if(right.ty->flag == CHAR)
+ trans = Tr_RelExp(oper, left.exp, right.exp);
+ else
+ EM_error(exp->u.op.right->pos, "unexpected type in comparsion\n");
+ }
+ else if(left.ty->flag==BOOLEAN)
+ {
+ if(right.ty->flag == BOOLEAN)
+ trans = Tr_RelExp(oper, left.exp, right.exp);
+ else
+ EM_error(exp->u.op.right->pos, "unexpected type in comparsion\n");
+ }
+ else if(left.ty->flag==STRING)
+ {
+ if(right.ty->flag == STRING)
+ trans = Tr_StringRelExp(oper, left.exp, right.exp);
+ else
+ EM_error(exp->u.op.right->pos, "unexpected type in comparsion\n");
+ }
+ else
+ EM_error(exp->u.op.right->pos, "unexpected expression in comparsion\n");
+ return Newexpty(trans,BOOLEAN_type());
+ }
+ }
+ else
+ {
+ printf("TransExp inner error!\n");
+ exit(3);
+ }
+ }
+ /*
+ ifÓï¾ä¿ÉÄÜ»áÓзµ»ØÖµ£¬Ò²¿ÉÄÜûÓÐ
+ */
+ else if(exp->kind==A_ifExp)
+ {
+ struct expty condi,ybran,nbran;
+ condi=transExp(l,e,funenv,varenv,exp->u.iff.test);
+ ybran=transExp(l,e,funenv,varenv,exp->u.iff.then);
+ nbran.ty=NULL;
+ nbran.exp=NULL;
+ if(exp->u.iff.elsee)
+ {
+ nbran=transExp(l,e,funenv,varenv,exp->u.iff.elsee);
+ if(condi.ty->flag!=INT&&condi.ty->flag!=BOOLEAN)
+ EM_error(exp->u.iff.test->pos,"Expected integer condition control\n");
+ if(!type_match(ybran.ty,nbran.ty))
+ EM_error(exp->pos,"Branches return type must correspond\n");
+ }
+ return Newexpty(Tr_IfExp(condi.exp, ybran.exp, nbran.exp),ybran.ty);
+ }
+ else if(exp->kind == A_gotoExp)
+ {
+ if(!e)
+ return Newexpty(Tr_NoExp(),VOID_type());
+ return Newexpty(Tr_GotoExp(e),VOID_type());
+ }
+ else if(exp->kind == A_repeatExp)
+ {
+ struct expty num;
+ num = transExp(l, e, funenv, varenv, exp->u.repeatt.test);
+ if(num.ty->flag != BOOLEAN)
+ EM_error(exp->pos,"Integer expected in repeat\n");
+// Tr_exp done=doneExp();
+ struct expty body = transExp(l, e, funenv, varenv, exp->u.repeatt.body);
+ return Newexpty(Tr_RepeatExp(body.exp, num.exp), VOID_type());
+ }
+ /*
+ caseÓï¾äûÓзµ»ØÖµ
+ */
+ else if(exp->kind == A_caseExp)
+ {
+
+ A_expList items = exp->u.casee.valList;
+ struct expty test = transExp(l, e, funenv, varenv, exp->u.casee.exp);
+ if(test.ty->flag!=INT && test.ty->flag!=CHAR&&
+ test.ty->flag!=STRING&&test.ty->flag!=BOOLEAN)
+ EM_error(exp->pos,"Integer, char, string or boolean expected in case\n");
+ Tr_exp elsee = NULL;
+ for(items; items; items = items->tail)
+ {
+ A_exp val = items->head->u.caseval.val;
+ A_exp action = items->head->u.caseval.action;
+ struct expty valItem = transExp(l, e, funenv, varenv, val);
+ struct expty actionItem = transExp(l, e, funenv, varenv, action);
+ elsee = Tr_IfExp(Tr_RelExp(A_eqOp, test.exp, valItem.exp), actionItem.exp, elsee);
+ }
+ return Newexpty(elsee, VOID_type());
+ }
+ else
+ {
+ printf("TransExp inner error!\n");
+ exit(2);
+ }
+}
+static Tr_exp transDec(Tr_level l,Tr_exp e,S_table funenv,S_table varenv,A_dec dec)
+{
+ if(dec->kind==A_varDec)
+ {
+ struct expty tmp;
+ Type tmptp;
+ Tr_access acc;
+ tmp=transExp(l,e,funenv,varenv,NULL);
+ if(dec->u.var.typ)
+ {
+ tmptp=transType(l, e, funenv, varenv, dec->u.var.typ);
+ int size = getSize(tmptp);
+ totalLen = 0;
+ acc = Tr_allocLocal(l, dec->u.var.escape, size);
+ if(tmptp)
+ {
+ if(!dec->u.var.init)
+ {
+ Environments temEnv = S_look(funenv, dec->u.var.var);
+ if(!temEnv||temEnv->u.var.acc->level!=l)
+ S_enter(funenv,dec->u.var.var,Newvarenv(acc,tmptp, 0));
+ else EM_error(dec->pos, "The var has been defined\n");
+ }
+// else if(type_match(tmptp,tmp.ty))
+// S_enter(funenv,dec->u.var.var,Newvarenv(acc,tmptp, 0));
+ else
+ {
+ EM_error(dec->pos,"Type %s mismatch\n",S_name(dec->u.var.typ->u.name));
+ //S_enter(funenv,dec->u.var.var,Newvarenv(acc,tmptp));
+ }
+ }
+ else
+ EM_error(dec->pos,"Type %s undefined\n",S_name(dec->u.var.typ->u.name));
+ }
+ else
+ {
+ /*
+ if(tmp.ty->flag==NIL||tmp.ty->flag==VOID)
+ {
+ EM_error(dec->pos,"Type %s initial must have a type\n",S_name(dec->u.var.var));
+ //S_enter(funenv,dec->u.var.var,Newvarenv(acc,INT_type()));
+ }
+ else
+ S_enter(funenv,dec->u.var.var,Newvarenv(acc,tmp.ty));
+ */
+ EM_error(dec->pos,"Type %s must be inited\n",S_name(dec->u.var.var));
+ }
+ return Tr_NoExp();
+ // return Tr_AssignExp(Tr_SimpleVar(acc, l), tmp.exp);
+ }
+ else if(dec->kind == A_constDec)
+ {
+ struct expty getExp;
+ Type tmpty;
+ Tr_access acc;
+ getExp = transExp(l,e,funenv, varenv, dec->u.constt.init);
+ acc = Tr_allocLocal(l, dec->u.constt.escape, getSize(getExp.ty));
+ if(!dec->u.var.init)
+ {
+ EM_error(dec->pos,"Const is not inited\n");
+ }
+ else if(dec->u.constt.init->kind!=A_intExp
+ && dec->u.constt.init->kind!=A_charExp
+ && dec->u.constt.init->kind!=A_realExp
+ && dec->u.constt.init->kind!=A_stringExp
+ && dec->u.constt.init->kind!=A_boolExp)
+ {
+ EM_error(dec->pos,"Const initialization error\n");
+ }
+ else
+ {
+ Environments temEnv = S_look(funenv,dec->u.constt.constt);
+ if (!temEnv||temEnv->u.var.acc->level != l) {
+ initVar = dec->u.constt.init;
+ S_enter(funenv, dec->u.constt.constt, Newvarenv(acc, getExp.ty, 1));
+ initVar = NULL;
+ }
+ else EM_error(dec->pos, "The var has been defined\n");
+ }
+ return Tr_AssignExp(Tr_SimpleVar(acc, l), getExp.exp);
+ }
+ else if(dec->kind==A_functionDec)
+ {
+ struct expty final;
+ A_fundecList fcl;
+ A_fieldList list;
+ Type resTy;
+ Typelist formalTys;
+ A_fundec f;
+ Environments fun;
+ Typelist s;
+ for (fcl = dec->u.function; fcl; fcl = fcl->tail)
+ {
+ if (fcl->head->result)
+ {
+ resTy = S_look(varenv, fcl->head->result);
+ if (!resTy)
+ {
+ EM_error(fcl->head->pos, "undefined type for return type");
+ resTy = VOID_type();
+ }
+ }
+ else
+ resTy = VOID_type();
+ formalTys = gettypelist(varenv, fcl->head->params);
+ Temp_label funLabel = Temp_newlabel();
+ U_intList paramSizeList = NULL;
+ for (Typelist ty = formalTys; ty; ty = ty->next)
+ {
+ paramSizeList = U_IntList(getSize(ty->head), paramSizeList);
+ }
+ Tr_level lev = Tr_newLevel(l, funLabel, makeFormals(fcl->head->params), paramSizeList);/* create a new level */
+ Environments value = Newfunenv(lev, funLabel, formalTys, resTy);
+ S_enter(funenv, fcl->head->name, value);
+ }
+ //»ñÈ¡·ûºÅ£¬½«·ûºÅ£¬¼ÓÈëµ½»·¾³ÖÐ
+ for (fcl = dec->u.function; fcl; fcl = fcl->tail)
+ {
+ f = fcl->head;
+ Environments funEntry = (Environments)S_look(funenv, f->name); /*get fun-info*/
+ S_beginScope(funenv); //ʵÏÖÄڲ㺯Êý·ÃÎÊÍâ²ã±äÁ¿
+ formalTys = funEntry->u.fun.param;
+ Tr_accessList acls = Tr_formals(funEntry->u.fun.lev);
+ for (list = f->params, s = formalTys; list && s && acls; list = list->tail, s = s->next, acls = acls->tail)
+ S_enter(funenv, list->head->name, Newvarenv(acls->head, s->head, 0));
+ nowCheckFun = f;
+ final = transExp(funEntry->u.fun.lev, e, funenv, varenv, f->body);
+ nowCheckFun = NULL;
+ Tr_procEntryExit(funEntry->u.fun.lev, final.exp, acls);
+ S_endScope(funenv, 1);
+ }
+ return Tr_NoExp();
+ }
+ else if(dec->kind==A_typeDec)
+ {
+ A_nametyList nl;
+ Type resTy;
+ Type namety;
+ bool iscyl;
+ for (nl = dec->u.type; nl; nl = nl->tail)
+ S_enter(varenv, nl->head->name, NAME_type(nl->head->name, nl->head->ty));
+ iscyl = TRUE;
+ for (nl = dec->u.type; nl; nl = nl->tail) {//ËùÓеͼÏòÉϲéÕÒÒ»¸ö£¬×îºóÒ»¸ö»á²éÕÒµ½Êµ¼ÊÀàÐÍ
+ resTy = transType(l, e, funenv, varenv, nl->head->ty);
+ if (iscyl)
+ if (resTy->flag != NAME)
+ iscyl = FALSE;
+ namety = S_look(varenv, nl->head->name);
+ namety->u.name.ty = resTy;
+ }
+ if (iscyl) EM_error(dec->pos,"illegal type cycle: cycle must contain record, array");
+ return Tr_NoExp();
+ }
+ else
+ {
+ printf("TransDec inner error!\n");
+ exit(4);
+ }
+}
+static Type transType(Tr_level l,Tr_exp e,S_table funenv,S_table varenv,A_ty ty)
+{
+ Type tmptp=NULL;
+ Fieldlist list=NULL;
+
+ if(ty->kind==A_nameTy)
+ {
+ tmptp=S_look(varenv,ty->u.name);
+ if(tmptp)
+ return tmptp;
+ else
+ {
+ EM_error(ty->pos,"Type %s undefined\n",S_name(ty->u.name));
+ return INT_type();
+ }
+ }
+ else if(ty->kind==A_recordTy)
+ {
+ list=getfieldlist(varenv,ty->u.record);
+ return RECORD_type(list);
+ }
+ else if(ty->kind==A_arrayTy)
+ {
+ tmptp=transType(l, e, funenv, varenv, ty->u.arrayy.element);//S_look(varenv,ty->u.arrayy.element);
+ if(!tmptp)
+ EM_error(ty->pos,"Type %s undefined\n",S_name(ty->u.arrayy.element->u.name));
+ struct array *temArrayInfo = checked_malloc(sizeof(*temArrayInfo));
+ temArrayInfo->tyEle = tmptp;
+ struct expty low, high;
+ low = transExp(l, e, funenv, varenv, ty->u.arrayy.range->u.rangee.lo);
+ high = transExp(l,e,funenv, varenv, ty->u.arrayy.range->u.rangee.hi);
+
+ if(!(low.ty->flag == INT || low.ty->flag == CHAR)
+ ||!(high.ty->flag == INT || high.ty->flag == CHAR))
+ EM_error(ty->pos,"Array index type should be integer, char or const char, const integer.\n");
+ else
+ if(low.ty->flag!=high.ty->flag)
+ EM_error(ty->pos,"Array index type is inconsistent.\n");
+ else if(ty->u.arrayy.range->u.rangee.lo->kind == A_intExp){
+ temArrayInfo->ty = low.ty;
+ temArrayInfo->u.intt.start = ty->u.arrayy.range->u.rangee.lo->u.intt;
+ temArrayInfo->u.intt.end = ty->u.arrayy.range->u.rangee.hi->u.intt;
+ }
+ else if(ty->u.arrayy.range->u.rangee.lo->kind == A_charExp){
+ temArrayInfo->ty = low.ty;
+ temArrayInfo->u.charr.start = ty->u.arrayy.range->u.rangee.lo->u.charr;
+ temArrayInfo->u.charr.end = ty->u.arrayy.range->u.rangee.hi->u.charr;
+ }
+ else if(ty->u.rangee.lo->kind == A_varExp){
+ Environments getLoEnv = S_look(funenv, ty->u.arrayy.range->u.rangee.lo->u.var->u.simple);
+ Environments getHiEnv = S_look(funenv, ty->u.arrayy.range->u.rangee.hi->u.var->u.simple);
+ if(getLoEnv&&getHiEnv)
+ {
+ if(getLoEnv->flag == CONST&&getHiEnv->flag == CONST)
+ {
+ if(low.ty->flag == INT){
+ temArrayInfo->ty = INT_type();;
+ temArrayInfo->u.intt.start = getLoEnv->u.var.init->u.intt;
+ temArrayInfo->u.intt.end = getHiEnv->u.var.init->u.intt;
+ }
+ else if(low.ty->flag == CHAR){
+ temArrayInfo->ty = CHAR_type();
+ temArrayInfo->u.charr.start = getLoEnv->u.var.init->u.charr;
+ temArrayInfo->u.charr.end = getHiEnv->u.var.init->u.charr;
+ }
+ }
+ else EM_error(ty->pos,"The var at the array index should be const.\n");
+ }
+ else
+ EM_error(ty->pos,"The var at the array index are not defined.\n");
+ }
+ return ARRAY_type(temArrayInfo);
+ }
+
+ else
+ {
+ printf("TransType inner error!\n");
+ exit(5);
+ }
+}
+static bool type_match(Type ty1,Type ty2)
+{
+ Type t1=gettype(ty1);
+ Type t2=gettype(ty2);
+ return (((t1->flag == RECORD || t1->flag == ARRAY) && t1 == t2) ||
+ (t1->flag == RECORD && t2->flag == NIL) ||
+ (t2->flag == RECORD && t1->flag == NIL) ||
+ (t1->flag != RECORD && t1->flag != ARRAY && t1->flag == t2->flag));
+}
\ No newline at end of file
diff --git a/src/semant.h b/CompilerPascal/semant.h
similarity index 87%
rename from src/semant.h
rename to CompilerPascal/semant.h
index 7a93034..642f671 100644
--- a/src/semant.h
+++ b/CompilerPascal/semant.h
@@ -1,6 +1,7 @@
#ifndef SEMANT_H
#define SEMANT_H
#include "translate.h"
+#include "types.h"
//typedef void *Tr_exp;
struct expty
@@ -15,7 +16,7 @@ static U_boolList makeFormals(A_fieldList params);
static struct expty transVar(Tr_level l,Tr_exp e,S_table funenv,S_table varenv,A_var var);
static struct expty transExp(Tr_level l,Tr_exp e,S_table funenv,S_table varenv,A_exp exp);
static Tr_exp transDec(Tr_level l,Tr_exp exp,S_table funenv,S_table varenv,A_dec dec);
-static Type transType(S_table varenv,A_ty ty);
+static Type transType(Tr_level l,Tr_exp e,S_table funenv,S_table varenv,A_ty ty);
static Typelist gettypelist(S_table varenv,A_fieldList list);
static Type gettype(Type ty);
static Fieldlist getfieldlist(S_table varenv,A_fieldList list);
diff --git a/src/symbol.c b/CompilerPascal/symbol.c
similarity index 89%
rename from src/symbol.c
rename to CompilerPascal/symbol.c
index e6c2f03..884c4db 100644
--- a/src/symbol.c
+++ b/CompilerPascal/symbol.c
@@ -16,6 +16,11 @@ static S_symbol mksymbol(string name, S_symbol next)
return s;
}
+int checkEqSymbol(S_symbol a, S_symbol b)
+{
+ return !(strcmp(a->name, b->name));
+}
+
#define SIZE 109 /* should be prime */
static S_symbol hashtable[SIZE];
@@ -90,10 +95,15 @@ void S_beginScope(S_table t)
S_enter(t,&marksym,NULL);
}
-void S_endScope(S_table t)
+void S_endScope(S_table t, int type)
{
S_symbol s;
- do s=TAB_pop(t);
+ static int count = 0;
+ if (type != 3) {
+// count++;
+ }
+ do
+ s = TAB_pop(t, type, count);
while (s != &marksym);
}
diff --git a/src/symbol.h b/CompilerPascal/symbol.h
similarity index 90%
rename from src/symbol.h
rename to CompilerPascal/symbol.h
index aa11543..ce3a84e 100644
--- a/src/symbol.h
+++ b/CompilerPascal/symbol.h
@@ -17,6 +17,9 @@ S_symbol S_Symbol(string);
/* Extract the underlying string from a symbol */
string S_name(S_symbol);
+/*ȽS_symbolǷ*/
+int checkEqSymbol(S_symbol a, S_symbol b);
+
/* S_table is a mapping from S_symbol->any, where "any" is represented
* here by void* */
typedef struct TAB_table_ * S_table;
@@ -37,5 +40,5 @@ void S_beginScope(S_table t);
/* Remove any bindings entered since the current scope began,
and end the current scope. */
-void S_endScope(S_table t);
+void S_endScope(S_table t, int type);
#endif
diff --git a/CompilerPascal/symbol0.txt b/CompilerPascal/symbol0.txt
new file mode 100644
index 0000000..7ec8191
--- /dev/null
+++ b/CompilerPascal/symbol0.txt
@@ -0,0 +1,248 @@
+layer2 VAR INT
+x VAR INT
+linktest FUN INT INT
+layer1 VAR INT
+y VAR INT
+x VAR INT
+y VAR INT
+x VAR INT
+max FUN INT INT INT
+link FUN INT INT VOID
+y VAR INT
+x VAR INT
+layer0 VAR INT
+y VAR INT
+x VAR INT
+max FUN INT INT INT
+rec VAR RECORD
+s VAR STRING
+outer VAR INT
+c VAR CHAR
+x NAME
+y VAR INT
+x VAR INT
+x NAME
+y VAR INT
+x VAR INT
+mc VAR CHAR
+x VAR INT
+linktest FUN INT CHAR
+m VAR CHAR
+t VAR INT
+y VAR INT
+x VAR INT
+y VAR INT
+x VAR INT
+max FUN INT INT INT
+swap FUN INT INT VOID
+a VAR ARRAY
+sum VAR INT
+i VAR INT
+y VAR INT
+x VAR INT
+n VAR REAL
+m VAR REAL
+c VAR CHAR
+mc VAR CHAR
+x VAR INT
+linktest FUN INT CHAR
+m VAR CHAR
+t VAR INT
+y VAR INT
+x VAR INT
+y VAR INT
+x VAR INT
+max FUN INT INT INT
+swap FUN INT INT VOID
+a VAR ARRAY
+sum VAR INT
+i VAR INT
+y VAR INT
+x VAR INT
+n VAR REAL
+m VAR REAL
+c VAR CHAR
+mc VAR CHAR
+x VAR INT
+linktest FUN INT CHAR
+m VAR CHAR
+t VAR INT
+y VAR INT
+x VAR INT
+y VAR INT
+x VAR INT
+max FUN INT INT INT
+swap FUN INT INT VOID
+a VAR ARRAY
+sum VAR INT
+i VAR INT
+y VAR INT
+x VAR INT
+n VAR REAL
+m VAR REAL
+c VAR CHAR
+mc VAR CHAR
+x VAR INT
+linktest FUN INT CHAR
+m VAR CHAR
+t VAR INT
+y VAR INT
+x VAR INT
+y VAR INT
+x VAR INT
+max FUN INT INT INT
+swap FUN INT INT VOID
+a VAR ARRAY
+sum VAR INT
+i VAR INT
+y VAR INT
+x VAR INT
+n VAR REAL
+m VAR REAL
+c VAR CHAR
+mc VAR CHAR
+x VAR INT
+linktest FUN INT CHAR
+m VAR CHAR
+t VAR INT
+y VAR INT
+x VAR INT
+y VAR INT
+x VAR INT
+max FUN INT INT INT
+swap FUN INT INT VOID
+a VAR ARRAY
+sum VAR INT
+i VAR INT
+y VAR INT
+x VAR INT
+n VAR REAL
+m VAR REAL
+c VAR CHAR
+x NAME
+y VAR INT
+x VAR INT
+y VAR INT
+x VAR INT
+max FUN INT INT INT
+outer VAR INT
+c VAR CHAR
+y VAR INT
+x VAR INT
+max FUN INT INT INT
+outer VAR INT
+c VAR CHAR
+y VAR INT
+x VAR INT
+max FUN INT INT INT
+outer VAR INT
+c VAR CHAR
+y VAR INT
+x VAR INT
+max FUN INT INT INT
+outer VAR INT
+c VAR CHAR
+mc VAR CHAR
+x VAR INT
+linktest FUN INT CHAR
+m VAR CHAR
+t VAR INT
+y VAR INT
+x VAR INT
+y VAR INT
+x VAR INT
+max FUN INT INT INT
+swap FUN INT INT VOID
+a VAR ARRAY
+sum VAR INT
+i VAR INT
+y VAR INT
+x VAR INT
+n VAR REAL
+m VAR REAL
+c VAR CHAR
+mc VAR CHAR
+x VAR INT
+linktest FUN INT CHAR
+m VAR CHAR
+t VAR INT
+y VAR INT
+x VAR INT
+y VAR INT
+x VAR INT
+max FUN INT INT INT
+swap FUN INT INT VOID
+a VAR ARRAY
+sum VAR INT
+i VAR INT
+y VAR INT
+x VAR INT
+n VAR REAL
+m VAR REAL
+c VAR CHAR
+mc VAR CHAR
+x VAR INT
+linktest FUN INT CHAR
+m VAR CHAR
+t VAR INT
+y VAR INT
+x VAR INT
+y VAR INT
+x VAR INT
+max FUN INT INT INT
+swap FUN INT INT VOID
+a VAR ARRAY
+sum VAR INT
+i VAR INT
+y VAR INT
+x VAR INT
+n VAR REAL
+m VAR REAL
+c VAR CHAR
+y VAR INT
+x VAR INT
+max FUN INT INT INT
+outer VAR INT
+c VAR CHAR
+y VAR INT
+x VAR INT
+max FUN INT INT INT
+outer VAR INT
+y VAR INT
+x VAR INT
+max FUN INT INT INT
+outer VAR INT
+outer VAR INT
+outer VAR INT
+outer VAR INT
+outer VAR INT
+outer VAR INT
+outer VAR INT
+outer VAR INT
+outer VAR INT
+outer VAR INT
+outer VAR INT
+outer VAR INT
+outer VAR INT
+outer VAR INT
+outer VAR INT
+outer VAR INT
+outer VAR INT
+outer VAR INT
+outer VAR INT
+outer VAR INT
+outer VAR INT
+outer VAR INT
+outer VAR INT
+outer VAR INT
+outer VAR INT
+outer VAR INT
+outer VAR INT
+outer VAR INT
+outer VAR INT
+outer VAR INT
+outer VAR INT
+outer VAR INT
+outer VAR INT
+outer VAR INT
+outer VAR INT
diff --git a/src/table.c b/CompilerPascal/table.c
similarity index 55%
rename from src/table.c
rename to CompilerPascal/table.c
index bb06774..9d28a2b 100644
--- a/src/table.c
+++ b/CompilerPascal/table.c
@@ -6,6 +6,7 @@
#include
#include "util.h"
#include "table.h"
+#include "env.h"
#define TABSIZE 127
@@ -59,8 +60,36 @@ void *TAB_look(TAB_table t, void *key)
if (b->key==key) return b->value;
return NULL;
}
-
-void *TAB_pop(TAB_table t) {
+char * printType(Type ty) {
+ char *nameTy;
+ switch (ty->flag) {
+ case RECORD: nameTy = "RECORD"; break;
+ case NIL: nameTy = "NIL"; break;
+ case BOOLEAN: nameTy = "BOOLEAN"; break;
+ case INT: nameTy = "INT"; break;
+ case CHAR: nameTy = "CHAR"; break;
+ case STRING: nameTy = "STRING"; break;
+ case ARRAY: nameTy = "ARRAY"; break;
+ case REAL: nameTy = "REAL"; break;
+ case NAME: nameTy = "NAME"; break;
+ case VOID: nameTy = "VOID"; break;
+ case ENUM: nameTy = "ENUM"; break;
+ }
+ return nameTy;
+}
+char * printVar(Environments en) {
+ char * nameEn;
+ switch (en->flag)
+ {
+ case VAR: nameEn = "VAR"; break;
+ case FUN: nameEn = "FUN"; break;
+ case CONST: nameEn = "CONST"; break;
+ default:
+ break;
+ }
+ return nameEn;
+}
+void *TAB_pop(TAB_table t, int type, int cont) {
void *k; binder b; int index;
assert (t);
k = t->top;
@@ -70,6 +99,43 @@ void *TAB_pop(TAB_table t) {
assert(b);
t->table[index] = b->next;
t->top=b->prevtop;
+
+ if (type != 3&&b->value) {
+ char tem[80];
+ sprintf(tem, "%s%d%s", "symbol", cont, ".txt");
+ FILE* fwrite = fopen(tem, "ab");
+
+ fprintf(fwrite, "%s\t", S_name(b->key));
+ //ӡ
+ char * nameTy;
+ if (type == 0)
+ {
+ nameTy = printType((Type)(b->value));
+ fprintf(fwrite, "%s\n", nameTy);
+ }
+ else {
+ char * nameEn = printVar((Environments)b->value);
+ fprintf(fwrite, "%s\t", nameEn);
+ if (((Environments)b->value)->flag == FUN)
+ {
+ Typelist list = ((Environments)b->value)->u.fun.param;
+ while (list)
+ {
+ nameTy = printType(list->head);
+ fprintf(fwrite, "%s\t", nameTy);
+ list = list->next;
+ }
+ nameTy = printType(((Environments)b->value)->u.fun.output);
+ fprintf(fwrite, "%s\n", nameTy);
+ }
+ else
+ {
+ nameTy = printType(((Environments)b->value)->u.var.ty);
+ fprintf(fwrite, "%s\n", nameTy);
+ }
+ }
+ fclose(fwrite);
+ }
return b->key;
}
diff --git a/src/table.h b/CompilerPascal/table.h
similarity index 95%
rename from src/table.h
rename to CompilerPascal/table.h
index a6eae83..05609a4 100644
--- a/src/table.h
+++ b/CompilerPascal/table.h
@@ -23,7 +23,7 @@ void *TAB_look(TAB_table t, void *key);
/* Pop the most recent binding and return its key.
* This may expose another binding for the same key, if there was one. */
-void *TAB_pop(TAB_table t);
+void *TAB_pop(TAB_table t, int type, int cont);
/* Call "show" on every "key"->"value" pair in the table,
diff --git a/src/temp.c b/CompilerPascal/temp.c
similarity index 100%
rename from src/temp.c
rename to CompilerPascal/temp.c
diff --git a/src/temp.h b/CompilerPascal/temp.h
similarity index 100%
rename from src/temp.h
rename to CompilerPascal/temp.h
diff --git a/CompilerPascal/test/1.pas b/CompilerPascal/test/1.pas
new file mode 100644
index 0000000..98af0c7
--- /dev/null
+++ b/CompilerPascal/test/1.pas
@@ -0,0 +1,6 @@
+Program ex11;
+ var outer:integer;
+ Begin
+ outer := 0;
+ outer := outer+1;
+ End.
\ No newline at end of file
diff --git a/CompilerPascal/test/2.pas b/CompilerPascal/test/2.pas
new file mode 100644
index 0000000..da61f45
--- /dev/null
+++ b/CompilerPascal/test/2.pas
@@ -0,0 +1,10 @@
+Program ex11;
+ type x=interger;
+ var x, y:integer;
+ Begin
+ x := 1;
+ if x > y then
+ x := x
+ else x := y;
+ End.
+
diff --git a/CompilerPascal/test/3.pas b/CompilerPascal/test/3.pas
new file mode 100644
index 0000000..359c6ef
--- /dev/null
+++ b/CompilerPascal/test/3.pas
@@ -0,0 +1,58 @@
+Program ex11;
+ var c:char;
+ m, n:real;
+ x, y, i, sum:integer;
+ a:array [1..24] of integer;
+ Procedure swap (x,y: integer);
+ Var t : integer;
+ m : char;
+ function linktest(x:integer):char;
+ var mc: char;
+ Begin
+ mc := c;
+ End;
+ Begin
+ m := c;
+ t := x;
+ x := y;
+ y := t;
+ End;
+ Function max(x, y : integer) : integer;
+ Begin
+ if x > y then
+ x := x
+ else x := y;
+ End;
+ Begin
+ x := max(x, y);
+ swap(x, y);
+ if y < 0 then
+ Begin
+ x := 1;
+ End
+ else x := 2;
+
+
+ For i := 1 to 100 do
+ Begin
+ y := (y+i) * 2;
+ End;
+
+ while i < 100 do
+ Begin
+ y := y+i;
+ End;
+
+
+ repeat
+ Begin
+ x := x+1;
+ End
+ until x > 1;
+
+ case x of
+ 1: y:=0;
+ 2: y:=1;
+ end;
+
+ End.
\ No newline at end of file
diff --git a/CompilerPascal/test/4.pas b/CompilerPascal/test/4.pas
new file mode 100644
index 0000000..2245cb8
--- /dev/null
+++ b/CompilerPascal/test/4.pas
@@ -0,0 +1,54 @@
+ Program ex11;
+ const a = 1;
+ b = 2;
+ c = 1.0;
+ var
+ //a, b, c: real; //ض
+ x, y, i:integer;
+ z:char;
+ outer:integer;
+ k:boolean;
+ rec: record //record
+ Month: INTeger;
+ Day: integer;
+ Year: Integer;
+ end;
+ ar:array [1..24] of integer; //array
+ tem:1...10; //ӽͲ
+ Function max(x: integer;y:integer) : integer; //function
+ Begin
+ x := outer;
+ y := 1;
+ max := 1;
+ End;
+ Begin
+ z := 'a';
+ x := abs(1); //ú
+ x := max(1,1); //ûԶ庯
+ rec.Month := 1; //record
+ ar[0] := 1; //
+ x := 1;
+ a := 1;
+ if(x*x = a) k:=odd(11); //if
+
+ For i := 1 to 100 do //forѭ
+ Begin
+ y := (y+i) * 2;
+ End;
+
+ while i < 100 do //whileѭ
+ Begin
+ y := y+i;
+ End;
+ repeat //repeat
+ Begin
+ x := x+1;
+ End
+ until x > 1;
+ {11 //עͲ
+ 111}
+ case x of //case
+ 1: y:=0;
+ 2: y:=1;
+ end;
+ End.
\ No newline at end of file
diff --git a/CompilerPascal/test/5.pas b/CompilerPascal/test/5.pas
new file mode 100644
index 0000000..c0295a6
--- /dev/null
+++ b/CompilerPascal/test/5.pas
@@ -0,0 +1,14 @@
+Program ex11;
+ var c:char;
+ outer:integer;
+ s:string;
+ rec: record
+ Month: Integer;
+ Day: Integer;
+ Year: Integer;
+ end;
+ Begin
+ c := 'a';
+ outer := 0;
+ if(true and false) 1+1;
+ End.
\ No newline at end of file
diff --git a/CompilerPascal/test/test2.pas b/CompilerPascal/test/test2.pas
new file mode 100644
index 0000000..4ff6535
--- /dev/null
+++ b/CompilerPascal/test/test2.pas
@@ -0,0 +1,9 @@
+Program ex11;
+ var x, y:integer;
+ Begin
+ x := 1;
+ if x > y then
+ x := x
+ else x := y;
+ End.
+
diff --git a/CompilerPascal/test/test3.pas b/CompilerPascal/test/test3.pas
new file mode 100644
index 0000000..1b757bb
--- /dev/null
+++ b/CompilerPascal/test/test3.pas
@@ -0,0 +1,24 @@
+Program ex11;
+ var layer0:integer;
+ x, y:integer;
+ Procedure link(x,y: integer);
+ Var layer1 : integer;
+ function linktest(x:integer):integer;
+ var layer2: integer;
+ Begin
+ layer2 := layer0;
+ layer2 := layer1;
+ End;
+ Begin
+ layer1 := layer0;
+ End;
+ Function max(x, y : integer) : integer;
+ Begin
+ if x > y then
+ x := x
+ else x := y;
+ End;
+ Begin
+ x := max(x, y);
+ link(x, y);
+ End.
\ No newline at end of file
diff --git a/CompilerPascal/test2pas.txt b/CompilerPascal/test2pas.txt
new file mode 100644
index 0000000..c29d950
--- /dev/null
+++ b/CompilerPascal/test2pas.txt
@@ -0,0 +1,2 @@
+y VAR INT
+x VAR INT
diff --git a/CompilerPascal/test3pas.txt b/CompilerPascal/test3pas.txt
new file mode 100644
index 0000000..e3560a8
--- /dev/null
+++ b/CompilerPascal/test3pas.txt
@@ -0,0 +1,13 @@
+layer2 VAR INT
+x VAR INT
+linktest FUN INT INT
+layer1 VAR INT
+y VAR INT
+x VAR INT
+y VAR INT
+x VAR INT
+max FUN INT INT INT
+link FUN INT INT VOID
+y VAR INT
+x VAR INT
+layer0 VAR INT
diff --git a/src/translate.c b/CompilerPascal/translate.c
similarity index 91%
rename from src/translate.c
rename to CompilerPascal/translate.c
index 1065eaf..17d2788 100644
--- a/src/translate.c
+++ b/CompilerPascal/translate.c
@@ -7,22 +7,12 @@ static Tr_level outermost = NULL;
static F_fragList procFragList = NULL;
struct Tr_level_ {
- // parent of current level
Tr_level parent;
// name of current level
Temp_label name;
+ // frame of current level
F_frame frame;
};
-
-struct Tr_access_ {
- Tr_level level;
- F_access access;
-};
-
-struct Tr_accessList_ {
- Tr_access head;
- Tr_accessList tail;
-};
struct patchList_ {
Temp_label* head;
@@ -107,19 +97,19 @@ Tr_level Tr_outermost(void) {
// need to create outermost layer
if (!outermost) {
// parent should be null
- outermost = Tr_newLevel(NULL, Temp_newlabel(), NULL);
+ outermost = Tr_newLevel(NULL, Temp_newlabel(), NULL, NULL);
}
return outermost;
}
// create a new level
-Tr_level Tr_newLevel(Tr_level parent, Temp_label name, U_boolList formals) {
+Tr_level Tr_newLevel(Tr_level parent, Temp_label name, U_boolList formals, U_intList formalsSizes) {
Tr_level level = checked_malloc(sizeof(*level));
level->parent = parent;
level->name = name;
// add static link
- level->frame = F_newFrame(name, U_BoolList(TRUE, formals));
+ level->frame = F_newFrame(name, U_BoolList(TRUE, formals), U_IntList(4, formalsSizes));
return level;
}
@@ -151,13 +141,13 @@ Tr_accessList Tr_formals(Tr_level level) {
return head;
}
-Tr_access Tr_allocLocal(Tr_level level, bool escape) {
- Tr_access access = Tr_Access(level, F_allocLocal(level->frame, escape));
+Tr_access Tr_allocLocal(Tr_level level, bool escape, int size) {
+ Tr_access access = Tr_Access(level, F_allocLocal(level->frame, escape, size));
return access;
}
-// function have to do with pathclist
+// do patch for pathclist
void doPatch(patchList tList, Temp_label label) {
for (;tList;tList = tList->tail) {
*(tList->head) = label;
@@ -304,12 +294,12 @@ Tr_exp Tr_FieldVar(Tr_exp addr, int offset, int size) {
}
Tr_exp Tr_SubscriptVar(Tr_exp addr, Tr_exp index, int size) {
- return Tr_Ex(T_Mem(T_Binop(T_plus, unEx(addr), T_Binop(T_mul, unEx(index), T_Const(F_wordSize))), size));
+ return Tr_Ex(T_Mem(T_Binop(T_plus, unEx(addr), T_Binop(T_mul, unEx(index), T_Const(size))), size));
}
// expressions
-Tr_exp Tr_NpExp() {
+Tr_exp Tr_NoExp() {
return Tr_Ex(T_Const(0));
}
@@ -356,35 +346,38 @@ Tr_exp Tr_CallExp(Temp_label label, Tr_level call, Tr_level dec, Tr_expList args
Tr_exp Tr_OpExp(A_oper op, Tr_exp left, Tr_exp right) {
T_binOp tOp;
- if (op == A_plusOp)
+ if (op == A_plusOp)
tOp = T_plus;
- else if (op = A_minusOp)
+ else if (op == A_minusOp)
tOp = T_minus;
else if (op == A_timesOp)
tOp = T_mul;
else if (op == A_divideOp)
tOp = T_div;
+ else if (op == A_minusOp)
+ tOp = T_div;
return Tr_Ex(T_Binop(tOp, unEx(left), unEx(right)));
}
-Tr_exp Tr_RecordExp(int* sizes, Tr_expList fields) {
+Tr_exp Tr_RecordExp(U_intList fieldsSizes, Tr_expList fields) {
+ if (!fieldsSizes||!fields)
+ return NULL;
// start address of record
Temp_temp addrTemp = Temp_newtemp();
int offset = 0;
- T_stm seq = T_Seq(T_Move(T_Mem(T_Binop(T_plus, T_Temp(addrTemp), T_Const(0)), sizes[0]), unEx(fields->head)), NULL);
- offset += sizes[0];
+ T_stm seq = T_Seq(T_Move(T_Mem(T_Binop(T_plus, T_Temp(addrTemp), T_Const(0)), fieldsSizes->head), unEx(fields->head)), NULL);
+ offset += fieldsSizes->head;
T_stm tail = seq;
-
- int i = 1;
- for (fields = fields->tail;fields;fields = fields->tail,i++) {
- tail->u.SEQ.right = T_Seq(T_Move(T_Mem(T_Binop(T_plus, T_Temp(addrTemp), T_Const(offset)), sizes[i]), unEx(fields->head)), NULL);
+ for (fields = fields->tail, fieldsSizes = fieldsSizes->tail;fields&&fieldsSizes;fields = fields->tail,fieldsSizes = fieldsSizes->tail) {
+ tail->u.SEQ.right = T_Seq(T_Move(T_Mem(T_Binop(T_plus, T_Temp(addrTemp), T_Const(-offset)), fieldsSizes->head), unEx(fields->head)), NULL);
tail = tail->u.SEQ.right;
- offset += sizes[i];
+ offset += fieldsSizes->head;
}
+ // allocate memory at first
T_stm alloc = T_Move(T_Temp(addrTemp), T_Call(T_Name(Temp_namedlabel("malloc")),
T_ExpList(T_Const(offset), NULL)));
@@ -418,12 +411,16 @@ Tr_exp Tr_SeqExp(Tr_expList list) {
if (!list)
return NULL;
- T_stm seq, tail;
- seq = tail = unNx(list->head);
+ /*T_stm seq, tail;
+ seq = tail = T_Seq (unNx(list->head), NULL);
for (list = list->tail;list;list = list->tail) {
tail->u.SEQ.right = unNx(list->head);
tail = tail->u.SEQ.right;
+ }*/
+ T_stm seq = unNx(list->head);
+ for (list = list->tail; list; list = list->tail) {
+ seq = T_Seq(unNx(list->head), seq);
}
return Tr_Nx(seq);
@@ -554,6 +551,10 @@ Tr_exp Tr_BreakExp(Tr_exp pos) {
return Tr_Nx(T_Jump(T_Name(name), Temp_LabelList(name, NULL)));
}
+Tr_exp Tr_RetExp(Tr_exp val) {
+ return Tr_NoExp();
+}
+
Tr_expList Tr_ExpList(Tr_exp head, Tr_expList tail) {
Tr_expList list = checked_malloc(sizeof(*list));
list->head = head;
diff --git a/src/translate.h b/CompilerPascal/translate.h
similarity index 86%
rename from src/translate.h
rename to CompilerPascal/translate.h
index a54bfa2..e917e02 100644
--- a/src/translate.h
+++ b/CompilerPascal/translate.h
@@ -3,6 +3,7 @@
#include "temp.h"
#include "frame.h"
#include "absyn.h"
+#include "util.h"
typedef struct Tr_access_ *Tr_access;
typedef struct Tr_accessList_ *Tr_accessList;
@@ -19,6 +20,16 @@ Tr_accessList Tr_AccessList(Tr_access head, Tr_accessList tail);
Tr_expList Tr_ExpList(Tr_exp head, Tr_expList tail);
+struct Tr_access_ {
+ Tr_level level;
+ F_access access;
+};
+
+struct Tr_accessList_ {
+ Tr_access head;
+ Tr_accessList tail;
+};
+
// level dependent
@@ -26,10 +37,10 @@ Tr_expList Tr_ExpList(Tr_exp head, Tr_expList tail);
// parent of main function
Tr_level Tr_outermost(void);
// create a new level for given function
-Tr_level Tr_newLevel(Tr_level parent, Temp_label name, U_boolList formals);
+Tr_level Tr_newLevel(Tr_level parent, Temp_label name, U_boolList formals, U_intList formalsSizes);
Tr_accessList Tr_formals(Tr_level level);
-Tr_access Tr_allocLocal(Tr_level level, bool escape);
+Tr_access Tr_allocLocal(Tr_level level, bool escape, int size);
T_exp Tr_getStaticLink(Tr_level call, Tr_level def);
@@ -46,7 +57,7 @@ Tr_exp Tr_RealExp(double r);
Tr_exp Tr_CharExp(char c);
Tr_exp Tr_StringExp(int size, string str);
// sizes: size of each field in record
-Tr_exp Tr_RecordExp(int* sizes, Tr_expList fields);
+Tr_exp Tr_RecordExp(U_intList sizes, Tr_expList fields);
// size: size of element in array
Tr_exp Tr_ArrayExp(int size, int totalLen, Tr_expList initList);
@@ -63,6 +74,7 @@ Tr_exp Tr_GotoExp(Tr_exp pos);
// for should be converted into while from abstract syntax
// Tr_exp Tr_ForExp(A_pos pos, S_symbol var, A_exp lo, A_exp hi, A_exp body);
Tr_exp Tr_BreakExp(Tr_exp pos);
+Tr_exp Tr_RetExp(Tr_exp val);
void Tr_procEntryExit(Tr_level level, Tr_exp body, Tr_accessList formals);
F_fragList Tr_getResult();
diff --git a/src/tree.c b/CompilerPascal/tree.c
similarity index 100%
rename from src/tree.c
rename to CompilerPascal/tree.c
diff --git a/src/tree.h b/CompilerPascal/tree.h
similarity index 97%
rename from src/tree.h
rename to CompilerPascal/tree.h
index 94d4cad..1b13762 100644
--- a/src/tree.h
+++ b/CompilerPascal/tree.h
@@ -14,7 +14,7 @@ struct T_expList_ {T_exp head; T_expList tail;};
typedef struct T_stmList_ *T_stmList;
struct T_stmList_ {T_stm head; T_stmList tail;};
-typedef enum {T_plus, T_minus, T_mul, T_div,
+typedef enum {T_plus, T_minus, T_mul, T_div, T_mod,
T_and, T_or, T_lshift, T_rshift, T_arshift, T_xor} T_binOp ;
typedef enum {T_eq, T_ne, T_lt, T_gt, T_le, T_ge,
diff --git a/src/types.c b/CompilerPascal/types.c
similarity index 92%
rename from src/types.c
rename to CompilerPascal/types.c
index 54de168..7067e7a 100644
--- a/src/types.c
+++ b/CompilerPascal/types.c
@@ -2,6 +2,7 @@
#include "util.h"
#include "symbol.h"
#include "types.h"
+#include "absyn.h"
static struct type st_NIL ={NIL};
static struct type st_INT ={INT};
@@ -40,7 +41,11 @@ Type ARRAY_type(Array arrayInfo)
{
Type tmp=checked_malloc(sizeof(*tmp));
tmp->flag=ARRAY;
- tmp->u.arrayInfo=arrayInfo;
+ Array array = checked_malloc(sizeof(*array));
+ array->ty = arrayInfo->ty;
+ array->u = arrayInfo->u;
+ array->tyEle = arrayInfo->tyEle;
+ tmp->u.arrayInfo=array;
return tmp;
}
diff --git a/src/types.h b/CompilerPascal/types.h
similarity index 80%
rename from src/types.h
rename to CompilerPascal/types.h
index 0c0900f..9b861d7 100644
--- a/src/types.h
+++ b/CompilerPascal/types.h
@@ -26,10 +26,25 @@ struct type
};
struct array{
- Type ty; //ö±
- S_symbol enumName; //һά±Ϊöͣö͵
- S_symbol start;
- S_symbol end; //±ʼսλãʹΪֵȣͳһתΪS_symbol
+ Type ty; //±
+ Type tyEle; //ÿԪص
+ union{
+ struct{
+ int start;
+ int end;
+ }intt;
+ struct{
+ char start;
+ char end;
+ }charr;
+ struct{
+ S_symbol start;
+ S_symbol end;
+ S_symbol enumName;
+ }enumm;
+ }u;
+// A_ty type; //洢±
+// A_exp arrayExp; //洢֮ݣݹ
};
struct typelist {Type head; Typelist next;};
diff --git a/src/util.c b/CompilerPascal/util.c
similarity index 75%
rename from src/util.c
rename to CompilerPascal/util.c
index e170580..aad570b 100644
--- a/src/util.c
+++ b/CompilerPascal/util.c
@@ -27,3 +27,10 @@ U_boolList U_BoolList(bool head, U_boolList tail)
list->tail = tail;
return list;
}
+
+U_intList U_IntList(int head, U_intList tail) {
+ U_intList list = checked_malloc(sizeof(*list));
+ list->head = head;
+ list->tail = tail;
+ return list;
+}
diff --git a/src/util.h b/CompilerPascal/util.h
similarity index 70%
rename from src/util.h
rename to CompilerPascal/util.h
index 6592be8..e26f3b1 100644
--- a/src/util.h
+++ b/CompilerPascal/util.h
@@ -1,5 +1,6 @@
#ifndef UTIL_H_
#define UTIL_H_
+
#include
typedef char *string;
@@ -14,4 +15,8 @@ string String(char *);
typedef struct U_boolList_ *U_boolList;
struct U_boolList_ {bool head; U_boolList tail;};
U_boolList U_BoolList(bool head, U_boolList tail);
+
+typedef struct U_intList_ *U_intList;
+struct U_intList_ {int head; U_intList tail;};
+U_intList U_IntList(int head, U_intList tail);
#endif
diff --git a/CompilerPascal/y.output b/CompilerPascal/y.output
new file mode 100644
index 0000000..6b30ae7
--- /dev/null
+++ b/CompilerPascal/y.output
@@ -0,0 +1,3952 @@
+状态 147conflicts: 1 shift/reduce
+
+
+语法
+
+ 0 $accept: program $end
+
+ 1 program: program_head routine DOT
+
+ 2 program_head: PROGRAM id SEMI
+
+ 3 routine: routine_head routine_body
+
+ 4 routine_head: label_part const_part type_part var_part routine_part
+
+ 5 label_part: %empty
+
+ 6 const_part: CONST const_expr_list
+ 7 | %empty
+
+ 8 const_expr_list: id EQUAL const_value SEMI const_expr_list
+ 9 | id EQUAL const_value SEMI
+ 10 | error_stmt const_expr_list
+ 11 | error_stmt
+
+ 12 const_value: INTEGER
+ 13 | REAL
+ 14 | CHAR
+ 15 | STRING
+ 16 | sys_con
+
+ 17 type_part: TYPE type_decl_list
+ 18 | %empty
+
+ 19 type_decl_list: type_definition type_decl_list
+ 20 | type_definition
+ 21 | error_stmt type_decl_list
+ 22 | error_stmt
+
+ 23 type_definition: id EQUAL type_decl SEMI
+
+ 24 type_decl: simple_type_decl
+ 25 | array_type_decl
+ 26 | record_type_decl
+
+ 27 simple_type_decl: sys_type
+ 28 | id
+ 29 | LP name_list RP
+ 30 | const_value DOTDOT const_value
+ 31 | MINUS const_value DOTDOT const_value
+ 32 | MINUS const_value DOTDOT MINUS const_value
+ 33 | id DOTDOT id
+
+ 34 array_type_decl: ARRAY LB simple_type_decl RB OF type_decl
+
+ 35 record_type_decl: RECORD field_decl_list END
+
+ 36 field_decl_list: field_decl field_decl_list
+ 37 | field_decl
+
+ 38 field_decl: name_list COLON type_decl SEMI
+
+ 39 name_list: name_list COMMA id
+ 40 | id
+
+ 41 var_part: VAR var_decl_list
+ 42 | %empty
+
+ 43 var_decl_list: var_decl var_decl_list
+ 44 | var_decl
+ 45 | error_stmt var_decl_list
+ 46 | error_stmt
+
+ 47 var_decl: name_list COLON type_decl SEMI
+
+ 48 routine_part: function_decl routine_part
+ 49 | procedure_decl routine_part
+ 50 | %empty
+
+ 51 function_decl: function_head SEMI sub_routine SEMI
+
+ 52 function_head: FUNCTION id parameters COLON simple_type_decl
+
+ 53 procedure_decl: procedure_head SEMI sub_routine SEMI
+
+ 54 procedure_head: PROCEDURE id parameters
+
+ 55 sub_routine: routine_head routine_body
+
+ 56 parameters: LP para_decl_list RP
+ 57 | %empty
+
+ 58 para_decl_list: para_decl_list SEMI para_type_list
+ 59 | para_type_list
+
+ 60 para_type_list: var_para_list COLON simple_type_decl
+ 61 | val_para_list COLON simple_type_decl
+
+ 62 var_para_list: VAR name_list
+
+ 63 val_para_list: name_list
+
+ 64 routine_body: compound_stmt
+
+ 65 compound_stmt: BEGIN_T stmt_list END
+
+ 66 stmt_list: stmt SEMI stmt_list
+ 67 | %empty
+ 68 | error_stmt stmt_list
+
+ 69 stmt: INTEGER COLON non_label_stmt
+ 70 | non_label_stmt
+
+ 71 non_label_stmt: assign_stmt
+ 72 | proc_stmt
+ 73 | compound_stmt
+ 74 | if_stmt
+ 75 | repeat_stmt
+ 76 | while_stmt
+ 77 | for_stmt
+ 78 | case_stmt
+ 79 | goto_stmt
+
+ 80 assign_stmt: id ASSIGN expression
+ 81 | id LB expression RB ASSIGN expression
+ 82 | id DOT id ASSIGN expression
+
+ 83 proc_stmt: id
+ 84 | id LP args_list RP
+ 85 | sys_proc
+ 86 | sys_proc LP expression_list RP
+ 87 | READ LP factor RP
+
+ 88 if_stmt: IF expression THEN stmt else_clause
+
+ 89 else_clause: ELSE stmt
+ 90 | %empty
+
+ 91 repeat_stmt: REPEAT stmt UNTIL expression
+
+ 92 while_stmt: WHILE expression DO stmt
+
+ 93 for_stmt: FOR id ASSIGN expression direction expression DO stmt
+
+ 94 direction: TO
+ 95 | DOWNTO
+
+ 96 case_stmt: CASE expression OF case_expr_list END
+
+ 97 case_expr_list: case_expr case_expr_list
+ 98 | case_expr
+
+ 99 case_expr: const_value COLON stmt SEMI
+ 100 | id COLON stmt SEMI
+
+ 101 goto_stmt: GOTO INTEGER
+
+ 102 expression_list: expression COMMA expression_list
+ 103 | expression
+
+ 104 expression: expression GE expr
+ 105 | expression GT expr
+ 106 | expression LE expr
+ 107 | expression LT expr
+ 108 | expression EQUAL expr
+ 109 | expression UNEQUAL expr
+ 110 | expr
+
+ 111 expr: expr PLUS term
+ 112 | expr MINUS term
+ 113 | expr OR term
+ 114 | term
+
+ 115 term: term MUL factor
+ 116 | term INTDIV factor
+ 117 | term REALDIV factor
+ 118 | term MOD factor
+ 119 | term AND factor
+ 120 | factor
+
+ 121 factor: id
+ 122 | id LP args_list RP
+ 123 | sys_funct
+ 124 | sys_funct LP args_list RP
+ 125 | const_value
+ 126 | LP expression RP
+ 127 | NOT factor
+ 128 | MINUS factor
+ 129 | id LB expression RB
+ 130 | id DOT id
+
+ 131 args_list: args_list COMMA expression
+ 132 | expression
+
+ 133 id: ID
+
+ 134 sys_con: SYS_CON
+
+ 135 sys_funct: SYS_FUNCT
+
+ 136 sys_proc: SYS_PROC
+
+ 137 sys_type: SYS_TYPE
+
+ 138 error_stmt: error SEMI
+
+
+Terminals, with rules where they appear
+
+$end (0) 0
+error (256) 138
+LP (258) 29 56 84 86 87 122 124 126
+RP (259) 29 56 84 86 87 122 124 126
+LB (260) 34 81 129
+RB (261) 34 81 129
+DOT (262) 1 82 130
+COMMA (263) 39 102 131
+COLON (264) 38 47 52 60 61 69 99 100
+SEMI (265) 2 8 9 23 38 47 51 53 58 66 99 100 138
+PLUS (266) 111
+MINUS (267) 31 32 112 128
+MUL (268) 115
+REALDIV (269) 117
+INTDIV (270) 116
+MOD (271) 118
+AND (272) 119
+OR (273) 113
+NOT (274) 127
+GE (275) 104
+GT (276) 105
+LE (277) 106
+LT (278) 107
+EQUAL (279) 8 9 23 108
+UNEQUAL (280) 109
+ASSIGN (281) 80 81 82 93
+PROGRAM (282) 2
+FUNCTION (283) 52
+PROCEDURE (284) 54
+BEGIN_T (285) 65
+END (286) 35 65 96
+TYPE (287) 17
+ARRAY (288) 34
+OF (289) 34 96
+RECORD (290) 35
+VAR (291) 41 62
+IF (292) 88
+THEN (293) 88
+ELSE (294) 89
+REPEAT (295) 91
+TO (296) 94
+DOWNTO (297) 95
+UNTIL (298) 91
+WHILE (299) 92
+DO (300) 92 93
+FOR (301) 93
+CASE (302) 96
+GOTO (303) 101
+READ (304) 87
+CONST (305) 6
+DOTDOT (306) 30 31 32 33
+INTEGER (307) 12 69 101
+REAL (308) 13
+CHAR (309) 14
+ID (310) 133
+STRING (311) 15
+SYS_CON (312) 134
+SYS_FUNCT (313) 135
+SYS_PROC (314) 136
+SYS_TYPE (315) 137
+
+
+Nonterminals, with rules where they appear
+
+$accept (61)
+ on left: 0
+program (62)
+ on left: 1, on right: 0
+program_head (63)
+ on left: 2, on right: 1
+routine (64)
+ on left: 3, on right: 1
+routine_head (65)
+ on left: 4, on right: 3 55
+label_part (66)
+ on left: 5, on right: 4
+const_part (67)
+ on left: 6 7, on right: 4
+const_expr_list (68)
+ on left: 8 9 10 11, on right: 6 8 10
+const_value (69)
+ on left: 12 13 14 15 16, on right: 8 9 30 31 32 99 125
+type_part (70)
+ on left: 17 18, on right: 4
+type_decl_list (71)
+ on left: 19 20 21 22, on right: 17 19 21
+type_definition (72)
+ on left: 23, on right: 19 20
+type_decl (73)
+ on left: 24 25 26, on right: 23 34 38 47
+simple_type_decl (74)
+ on left: 27 28 29 30 31 32 33, on right: 24 34 52 60 61
+array_type_decl (75)
+ on left: 34, on right: 25
+record_type_decl (76)
+ on left: 35, on right: 26
+field_decl_list (77)
+ on left: 36 37, on right: 35 36
+field_decl (78)
+ on left: 38, on right: 36 37
+name_list (79)
+ on left: 39 40, on right: 29 38 39 47 62 63
+var_part (80)
+ on left: 41 42, on right: 4
+var_decl_list (81)
+ on left: 43 44 45 46, on right: 41 43 45
+var_decl (82)
+ on left: 47, on right: 43 44
+routine_part (83)
+ on left: 48 49 50, on right: 4 48 49
+function_decl (84)
+ on left: 51, on right: 48
+function_head (85)
+ on left: 52, on right: 51
+procedure_decl (86)
+ on left: 53, on right: 49
+procedure_head (87)
+ on left: 54, on right: 53
+sub_routine (88)
+ on left: 55, on right: 51 53
+parameters (89)
+ on left: 56 57, on right: 52 54
+para_decl_list (90)
+ on left: 58 59, on right: 56 58
+para_type_list (91)
+ on left: 60 61, on right: 58 59
+var_para_list (92)
+ on left: 62, on right: 60
+val_para_list (93)
+ on left: 63, on right: 61
+routine_body (94)
+ on left: 64, on right: 3 55
+compound_stmt (95)
+ on left: 65, on right: 64 73
+stmt_list (96)
+ on left: 66 67 68, on right: 65 66 68
+stmt (97)
+ on left: 69 70, on right: 66 88 89 91 92 93 99 100
+non_label_stmt (98)
+ on left: 71 72 73 74 75 76 77 78 79, on right: 69 70
+assign_stmt (99)
+ on left: 80 81 82, on right: 71
+proc_stmt (100)
+ on left: 83 84 85 86 87, on right: 72
+if_stmt (101)
+ on left: 88, on right: 74
+else_clause (102)
+ on left: 89 90, on right: 88
+repeat_stmt (103)
+ on left: 91, on right: 75
+while_stmt (104)
+ on left: 92, on right: 76
+for_stmt (105)
+ on left: 93, on right: 77
+direction (106)
+ on left: 94 95, on right: 93
+case_stmt (107)
+ on left: 96, on right: 78
+case_expr_list (108)
+ on left: 97 98, on right: 96 97
+case_expr (109)
+ on left: 99 100, on right: 97 98
+goto_stmt (110)
+ on left: 101, on right: 79
+expression_list (111)
+ on left: 102 103, on right: 86 102
+expression (112)
+ on left: 104 105 106 107 108 109 110, on right: 80 81 82 88 91
+ 92 93 96 102 103 104 105 106 107 108 109 126 129 131 132
+expr (113)
+ on left: 111 112 113 114, on right: 104 105 106 107 108 109 110
+ 111 112 113
+term (114)
+ on left: 115 116 117 118 119 120, on right: 111 112 113 114 115
+ 116 117 118 119
+factor (115)
+ on left: 121 122 123 124 125 126 127 128 129 130, on right: 87
+ 115 116 117 118 119 120 127 128
+args_list (116)
+ on left: 131 132, on right: 84 122 124 131
+id (117)
+ on left: 133, on right: 2 8 9 23 28 33 39 40 52 54 80 81 82 83
+ 84 93 100 121 122 129 130
+sys_con (118)
+ on left: 134, on right: 16
+sys_funct (119)
+ on left: 135, on right: 123 124
+sys_proc (120)
+ on left: 136, on right: 85 86
+sys_type (121)
+ on left: 137, on right: 27
+error_stmt (122)
+ on left: 138, on right: 10 11 21 22 45 46 68
+
+
+State 0
+
+ 0 $accept: . program $end
+
+ PROGRAM shift, and go to state 1
+
+ program 转到状态 2
+ program_head 转到状态 3
+
+
+State 1
+
+ 2 program_head: PROGRAM . id SEMI
+
+ ID shift, and go to state 4
+
+ id 转到状态 5
+
+
+State 2
+
+ 0 $accept: program . $end
+
+ $end shift, and go to state 6
+
+
+State 3
+
+ 1 program: program_head . routine DOT
+
+ $default reduce using rule 5 (label_part)
+
+ routine 转到状态 7
+ routine_head 转到状态 8
+ label_part 转到状态 9
+
+
+State 4
+
+ 133 id: ID .
+
+ $default reduce using rule 133 (id)
+
+
+State 5
+
+ 2 program_head: PROGRAM id . SEMI
+
+ SEMI shift, and go to state 10
+
+
+State 6
+
+ 0 $accept: program $end .
+
+ $default 接受
+
+
+State 7
+
+ 1 program: program_head routine . DOT
+
+ DOT shift, and go to state 11
+
+
+State 8
+
+ 3 routine: routine_head . routine_body
+
+ BEGIN_T shift, and go to state 12
+
+ routine_body 转到状态 13
+ compound_stmt 转到状态 14
+
+
+State 9
+
+ 4 routine_head: label_part . const_part type_part var_part routine_part
+
+ CONST shift, and go to state 15
+
+ $default reduce using rule 7 (const_part)
+
+ const_part 转到状态 16
+
+
+State 10
+
+ 2 program_head: PROGRAM id SEMI .
+
+ $default reduce using rule 2 (program_head)
+
+
+State 11
+
+ 1 program: program_head routine DOT .
+
+ $default reduce using rule 1 (program)
+
+
+State 12
+
+ 65 compound_stmt: BEGIN_T . stmt_list END
+
+ error shift, and go to state 17
+ BEGIN_T shift, and go to state 12
+ IF shift, and go to state 18
+ REPEAT shift, and go to state 19
+ WHILE shift, and go to state 20
+ FOR shift, and go to state 21
+ CASE shift, and go to state 22
+ GOTO shift, and go to state 23
+ READ shift, and go to state 24
+ INTEGER shift, and go to state 25
+ ID shift, and go to state 4
+ SYS_PROC shift, and go to state 26
+
+ END reduce using rule 67 (stmt_list)
+
+ compound_stmt 转到状态 27
+ stmt_list 转到状态 28
+ stmt 转到状态 29
+ non_label_stmt 转到状态 30
+ assign_stmt 转到状态 31
+ proc_stmt 转到状态 32
+ if_stmt 转到状态 33
+ repeat_stmt 转到状态 34
+ while_stmt 转到状态 35
+ for_stmt 转到状态 36
+ case_stmt 转到状态 37
+ goto_stmt 转到状态 38
+ id 转到状态 39
+ sys_proc 转到状态 40
+ error_stmt 转到状态 41
+
+
+State 13
+
+ 3 routine: routine_head routine_body .
+
+ $default reduce using rule 3 (routine)
+
+
+State 14
+
+ 64 routine_body: compound_stmt .
+
+ $default reduce using rule 64 (routine_body)
+
+
+State 15
+
+ 6 const_part: CONST . const_expr_list
+
+ error shift, and go to state 17
+ ID shift, and go to state 4
+
+ const_expr_list 转到状态 42
+ id 转到状态 43
+ error_stmt 转到状态 44
+
+
+State 16
+
+ 4 routine_head: label_part const_part . type_part var_part routine_part
+
+ TYPE shift, and go to state 45
+
+ $default reduce using rule 18 (type_part)
+
+ type_part 转到状态 46
+
+
+State 17
+
+ 138 error_stmt: error . SEMI
+
+ SEMI shift, and go to state 47
+
+
+State 18
+
+ 88 if_stmt: IF . expression THEN stmt else_clause
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ expression 转到状态 58
+ expr 转到状态 59
+ term 转到状态 60
+ factor 转到状态 61
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 19
+
+ 91 repeat_stmt: REPEAT . stmt UNTIL expression
+
+ BEGIN_T shift, and go to state 12
+ IF shift, and go to state 18
+ REPEAT shift, and go to state 19
+ WHILE shift, and go to state 20
+ FOR shift, and go to state 21
+ CASE shift, and go to state 22
+ GOTO shift, and go to state 23
+ READ shift, and go to state 24
+ INTEGER shift, and go to state 25
+ ID shift, and go to state 4
+ SYS_PROC shift, and go to state 26
+
+ compound_stmt 转到状态 27
+ stmt 转到状态 65
+ non_label_stmt 转到状态 30
+ assign_stmt 转到状态 31
+ proc_stmt 转到状态 32
+ if_stmt 转到状态 33
+ repeat_stmt 转到状态 34
+ while_stmt 转到状态 35
+ for_stmt 转到状态 36
+ case_stmt 转到状态 37
+ goto_stmt 转到状态 38
+ id 转到状态 39
+ sys_proc 转到状态 40
+
+
+State 20
+
+ 92 while_stmt: WHILE . expression DO stmt
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ expression 转到状态 66
+ expr 转到状态 59
+ term 转到状态 60
+ factor 转到状态 61
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 21
+
+ 93 for_stmt: FOR . id ASSIGN expression direction expression DO stmt
+
+ ID shift, and go to state 4
+
+ id 转到状态 67
+
+
+State 22
+
+ 96 case_stmt: CASE . expression OF case_expr_list END
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ expression 转到状态 68
+ expr 转到状态 59
+ term 转到状态 60
+ factor 转到状态 61
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 23
+
+ 101 goto_stmt: GOTO . INTEGER
+
+ INTEGER shift, and go to state 69
+
+
+State 24
+
+ 87 proc_stmt: READ . LP factor RP
+
+ LP shift, and go to state 70
+
+
+State 25
+
+ 69 stmt: INTEGER . COLON non_label_stmt
+
+ COLON shift, and go to state 71
+
+
+State 26
+
+ 136 sys_proc: SYS_PROC .
+
+ $default reduce using rule 136 (sys_proc)
+
+
+State 27
+
+ 73 non_label_stmt: compound_stmt .
+
+ $default reduce using rule 73 (non_label_stmt)
+
+
+State 28
+
+ 65 compound_stmt: BEGIN_T stmt_list . END
+
+ END shift, and go to state 72
+
+
+State 29
+
+ 66 stmt_list: stmt . SEMI stmt_list
+
+ SEMI shift, and go to state 73
+
+
+State 30
+
+ 70 stmt: non_label_stmt .
+
+ $default reduce using rule 70 (stmt)
+
+
+State 31
+
+ 71 non_label_stmt: assign_stmt .
+
+ $default reduce using rule 71 (non_label_stmt)
+
+
+State 32
+
+ 72 non_label_stmt: proc_stmt .
+
+ $default reduce using rule 72 (non_label_stmt)
+
+
+State 33
+
+ 74 non_label_stmt: if_stmt .
+
+ $default reduce using rule 74 (non_label_stmt)
+
+
+State 34
+
+ 75 non_label_stmt: repeat_stmt .
+
+ $default reduce using rule 75 (non_label_stmt)
+
+
+State 35
+
+ 76 non_label_stmt: while_stmt .
+
+ $default reduce using rule 76 (non_label_stmt)
+
+
+State 36
+
+ 77 non_label_stmt: for_stmt .
+
+ $default reduce using rule 77 (non_label_stmt)
+
+
+State 37
+
+ 78 non_label_stmt: case_stmt .
+
+ $default reduce using rule 78 (non_label_stmt)
+
+
+State 38
+
+ 79 non_label_stmt: goto_stmt .
+
+ $default reduce using rule 79 (non_label_stmt)
+
+
+State 39
+
+ 80 assign_stmt: id . ASSIGN expression
+ 81 | id . LB expression RB ASSIGN expression
+ 82 | id . DOT id ASSIGN expression
+ 83 proc_stmt: id .
+ 84 | id . LP args_list RP
+
+ LP shift, and go to state 74
+ LB shift, and go to state 75
+ DOT shift, and go to state 76
+ ASSIGN shift, and go to state 77
+
+ $default reduce using rule 83 (proc_stmt)
+
+
+State 40
+
+ 85 proc_stmt: sys_proc .
+ 86 | sys_proc . LP expression_list RP
+
+ LP shift, and go to state 78
+
+ $default reduce using rule 85 (proc_stmt)
+
+
+State 41
+
+ 68 stmt_list: error_stmt . stmt_list
+
+ error shift, and go to state 17
+ BEGIN_T shift, and go to state 12
+ IF shift, and go to state 18
+ REPEAT shift, and go to state 19
+ WHILE shift, and go to state 20
+ FOR shift, and go to state 21
+ CASE shift, and go to state 22
+ GOTO shift, and go to state 23
+ READ shift, and go to state 24
+ INTEGER shift, and go to state 25
+ ID shift, and go to state 4
+ SYS_PROC shift, and go to state 26
+
+ END reduce using rule 67 (stmt_list)
+
+ compound_stmt 转到状态 27
+ stmt_list 转到状态 79
+ stmt 转到状态 29
+ non_label_stmt 转到状态 30
+ assign_stmt 转到状态 31
+ proc_stmt 转到状态 32
+ if_stmt 转到状态 33
+ repeat_stmt 转到状态 34
+ while_stmt 转到状态 35
+ for_stmt 转到状态 36
+ case_stmt 转到状态 37
+ goto_stmt 转到状态 38
+ id 转到状态 39
+ sys_proc 转到状态 40
+ error_stmt 转到状态 41
+
+
+State 42
+
+ 6 const_part: CONST const_expr_list .
+
+ $default reduce using rule 6 (const_part)
+
+
+State 43
+
+ 8 const_expr_list: id . EQUAL const_value SEMI const_expr_list
+ 9 | id . EQUAL const_value SEMI
+
+ EQUAL shift, and go to state 80
+
+
+State 44
+
+ 10 const_expr_list: error_stmt . const_expr_list
+ 11 | error_stmt .
+
+ error shift, and go to state 17
+ ID shift, and go to state 4
+
+ FUNCTION reduce using rule 11 (const_expr_list)
+ PROCEDURE reduce using rule 11 (const_expr_list)
+ BEGIN_T reduce using rule 11 (const_expr_list)
+ TYPE reduce using rule 11 (const_expr_list)
+ VAR reduce using rule 11 (const_expr_list)
+
+ const_expr_list 转到状态 81
+ id 转到状态 43
+ error_stmt 转到状态 44
+
+
+State 45
+
+ 17 type_part: TYPE . type_decl_list
+
+ error shift, and go to state 17
+ ID shift, and go to state 4
+
+ type_decl_list 转到状态 82
+ type_definition 转到状态 83
+ id 转到状态 84
+ error_stmt 转到状态 85
+
+
+State 46
+
+ 4 routine_head: label_part const_part type_part . var_part routine_part
+
+ VAR shift, and go to state 86
+
+ $default reduce using rule 42 (var_part)
+
+ var_part 转到状态 87
+
+
+State 47
+
+ 138 error_stmt: error SEMI .
+
+ $default reduce using rule 138 (error_stmt)
+
+
+State 48
+
+ 126 factor: LP . expression RP
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ expression 转到状态 88
+ expr 转到状态 59
+ term 转到状态 60
+ factor 转到状态 61
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 49
+
+ 128 factor: MINUS . factor
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ factor 转到状态 89
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 50
+
+ 127 factor: NOT . factor
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ factor 转到状态 90
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 51
+
+ 12 const_value: INTEGER .
+
+ $default reduce using rule 12 (const_value)
+
+
+State 52
+
+ 13 const_value: REAL .
+
+ $default reduce using rule 13 (const_value)
+
+
+State 53
+
+ 14 const_value: CHAR .
+
+ $default reduce using rule 14 (const_value)
+
+
+State 54
+
+ 15 const_value: STRING .
+
+ $default reduce using rule 15 (const_value)
+
+
+State 55
+
+ 134 sys_con: SYS_CON .
+
+ $default reduce using rule 134 (sys_con)
+
+
+State 56
+
+ 135 sys_funct: SYS_FUNCT .
+
+ $default reduce using rule 135 (sys_funct)
+
+
+State 57
+
+ 125 factor: const_value .
+
+ $default reduce using rule 125 (factor)
+
+
+State 58
+
+ 88 if_stmt: IF expression . THEN stmt else_clause
+ 104 expression: expression . GE expr
+ 105 | expression . GT expr
+ 106 | expression . LE expr
+ 107 | expression . LT expr
+ 108 | expression . EQUAL expr
+ 109 | expression . UNEQUAL expr
+
+ GE shift, and go to state 91
+ GT shift, and go to state 92
+ LE shift, and go to state 93
+ LT shift, and go to state 94
+ EQUAL shift, and go to state 95
+ UNEQUAL shift, and go to state 96
+ THEN shift, and go to state 97
+
+
+State 59
+
+ 110 expression: expr .
+ 111 expr: expr . PLUS term
+ 112 | expr . MINUS term
+ 113 | expr . OR term
+
+ PLUS shift, and go to state 98
+ MINUS shift, and go to state 99
+ OR shift, and go to state 100
+
+ $default reduce using rule 110 (expression)
+
+
+State 60
+
+ 114 expr: term .
+ 115 term: term . MUL factor
+ 116 | term . INTDIV factor
+ 117 | term . REALDIV factor
+ 118 | term . MOD factor
+ 119 | term . AND factor
+
+ MUL shift, and go to state 101
+ REALDIV shift, and go to state 102
+ INTDIV shift, and go to state 103
+ MOD shift, and go to state 104
+ AND shift, and go to state 105
+
+ $default reduce using rule 114 (expr)
+
+
+State 61
+
+ 120 term: factor .
+
+ $default reduce using rule 120 (term)
+
+
+State 62
+
+ 121 factor: id .
+ 122 | id . LP args_list RP
+ 129 | id . LB expression RB
+ 130 | id . DOT id
+
+ LP shift, and go to state 106
+ LB shift, and go to state 107
+ DOT shift, and go to state 108
+
+ $default reduce using rule 121 (factor)
+
+
+State 63
+
+ 16 const_value: sys_con .
+
+ $default reduce using rule 16 (const_value)
+
+
+State 64
+
+ 123 factor: sys_funct .
+ 124 | sys_funct . LP args_list RP
+
+ LP shift, and go to state 109
+
+ $default reduce using rule 123 (factor)
+
+
+State 65
+
+ 91 repeat_stmt: REPEAT stmt . UNTIL expression
+
+ UNTIL shift, and go to state 110
+
+
+State 66
+
+ 92 while_stmt: WHILE expression . DO stmt
+ 104 expression: expression . GE expr
+ 105 | expression . GT expr
+ 106 | expression . LE expr
+ 107 | expression . LT expr
+ 108 | expression . EQUAL expr
+ 109 | expression . UNEQUAL expr
+
+ GE shift, and go to state 91
+ GT shift, and go to state 92
+ LE shift, and go to state 93
+ LT shift, and go to state 94
+ EQUAL shift, and go to state 95
+ UNEQUAL shift, and go to state 96
+ DO shift, and go to state 111
+
+
+State 67
+
+ 93 for_stmt: FOR id . ASSIGN expression direction expression DO stmt
+
+ ASSIGN shift, and go to state 112
+
+
+State 68
+
+ 96 case_stmt: CASE expression . OF case_expr_list END
+ 104 expression: expression . GE expr
+ 105 | expression . GT expr
+ 106 | expression . LE expr
+ 107 | expression . LT expr
+ 108 | expression . EQUAL expr
+ 109 | expression . UNEQUAL expr
+
+ GE shift, and go to state 91
+ GT shift, and go to state 92
+ LE shift, and go to state 93
+ LT shift, and go to state 94
+ EQUAL shift, and go to state 95
+ UNEQUAL shift, and go to state 96
+ OF shift, and go to state 113
+
+
+State 69
+
+ 101 goto_stmt: GOTO INTEGER .
+
+ $default reduce using rule 101 (goto_stmt)
+
+
+State 70
+
+ 87 proc_stmt: READ LP . factor RP
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ factor 转到状态 114
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 71
+
+ 69 stmt: INTEGER COLON . non_label_stmt
+
+ BEGIN_T shift, and go to state 12
+ IF shift, and go to state 18
+ REPEAT shift, and go to state 19
+ WHILE shift, and go to state 20
+ FOR shift, and go to state 21
+ CASE shift, and go to state 22
+ GOTO shift, and go to state 23
+ READ shift, and go to state 24
+ ID shift, and go to state 4
+ SYS_PROC shift, and go to state 26
+
+ compound_stmt 转到状态 27
+ non_label_stmt 转到状态 115
+ assign_stmt 转到状态 31
+ proc_stmt 转到状态 32
+ if_stmt 转到状态 33
+ repeat_stmt 转到状态 34
+ while_stmt 转到状态 35
+ for_stmt 转到状态 36
+ case_stmt 转到状态 37
+ goto_stmt 转到状态 38
+ id 转到状态 39
+ sys_proc 转到状态 40
+
+
+State 72
+
+ 65 compound_stmt: BEGIN_T stmt_list END .
+
+ $default reduce using rule 65 (compound_stmt)
+
+
+State 73
+
+ 66 stmt_list: stmt SEMI . stmt_list
+
+ error shift, and go to state 17
+ BEGIN_T shift, and go to state 12
+ IF shift, and go to state 18
+ REPEAT shift, and go to state 19
+ WHILE shift, and go to state 20
+ FOR shift, and go to state 21
+ CASE shift, and go to state 22
+ GOTO shift, and go to state 23
+ READ shift, and go to state 24
+ INTEGER shift, and go to state 25
+ ID shift, and go to state 4
+ SYS_PROC shift, and go to state 26
+
+ END reduce using rule 67 (stmt_list)
+
+ compound_stmt 转到状态 27
+ stmt_list 转到状态 116
+ stmt 转到状态 29
+ non_label_stmt 转到状态 30
+ assign_stmt 转到状态 31
+ proc_stmt 转到状态 32
+ if_stmt 转到状态 33
+ repeat_stmt 转到状态 34
+ while_stmt 转到状态 35
+ for_stmt 转到状态 36
+ case_stmt 转到状态 37
+ goto_stmt 转到状态 38
+ id 转到状态 39
+ sys_proc 转到状态 40
+ error_stmt 转到状态 41
+
+
+State 74
+
+ 84 proc_stmt: id LP . args_list RP
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ expression 转到状态 117
+ expr 转到状态 59
+ term 转到状态 60
+ factor 转到状态 61
+ args_list 转到状态 118
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 75
+
+ 81 assign_stmt: id LB . expression RB ASSIGN expression
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ expression 转到状态 119
+ expr 转到状态 59
+ term 转到状态 60
+ factor 转到状态 61
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 76
+
+ 82 assign_stmt: id DOT . id ASSIGN expression
+
+ ID shift, and go to state 4
+
+ id 转到状态 120
+
+
+State 77
+
+ 80 assign_stmt: id ASSIGN . expression
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ expression 转到状态 121
+ expr 转到状态 59
+ term 转到状态 60
+ factor 转到状态 61
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 78
+
+ 86 proc_stmt: sys_proc LP . expression_list RP
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ expression_list 转到状态 122
+ expression 转到状态 123
+ expr 转到状态 59
+ term 转到状态 60
+ factor 转到状态 61
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 79
+
+ 68 stmt_list: error_stmt stmt_list .
+
+ $default reduce using rule 68 (stmt_list)
+
+
+State 80
+
+ 8 const_expr_list: id EQUAL . const_value SEMI const_expr_list
+ 9 | id EQUAL . const_value SEMI
+
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+
+ const_value 转到状态 124
+ sys_con 转到状态 63
+
+
+State 81
+
+ 10 const_expr_list: error_stmt const_expr_list .
+
+ $default reduce using rule 10 (const_expr_list)
+
+
+State 82
+
+ 17 type_part: TYPE type_decl_list .
+
+ $default reduce using rule 17 (type_part)
+
+
+State 83
+
+ 19 type_decl_list: type_definition . type_decl_list
+ 20 | type_definition .
+
+ error shift, and go to state 17
+ ID shift, and go to state 4
+
+ FUNCTION reduce using rule 20 (type_decl_list)
+ PROCEDURE reduce using rule 20 (type_decl_list)
+ BEGIN_T reduce using rule 20 (type_decl_list)
+ VAR reduce using rule 20 (type_decl_list)
+
+ type_decl_list 转到状态 125
+ type_definition 转到状态 83
+ id 转到状态 84
+ error_stmt 转到状态 85
+
+
+State 84
+
+ 23 type_definition: id . EQUAL type_decl SEMI
+
+ EQUAL shift, and go to state 126
+
+
+State 85
+
+ 21 type_decl_list: error_stmt . type_decl_list
+ 22 | error_stmt .
+
+ error shift, and go to state 17
+ ID shift, and go to state 4
+
+ FUNCTION reduce using rule 22 (type_decl_list)
+ PROCEDURE reduce using rule 22 (type_decl_list)
+ BEGIN_T reduce using rule 22 (type_decl_list)
+ VAR reduce using rule 22 (type_decl_list)
+
+ type_decl_list 转到状态 127
+ type_definition 转到状态 83
+ id 转到状态 84
+ error_stmt 转到状态 85
+
+
+State 86
+
+ 41 var_part: VAR . var_decl_list
+
+ error shift, and go to state 17
+ ID shift, and go to state 4
+
+ name_list 转到状态 128
+ var_decl_list 转到状态 129
+ var_decl 转到状态 130
+ id 转到状态 131
+ error_stmt 转到状态 132
+
+
+State 87
+
+ 4 routine_head: label_part const_part type_part var_part . routine_part
+
+ FUNCTION shift, and go to state 133
+ PROCEDURE shift, and go to state 134
+
+ $default reduce using rule 50 (routine_part)
+
+ routine_part 转到状态 135
+ function_decl 转到状态 136
+ function_head 转到状态 137
+ procedure_decl 转到状态 138
+ procedure_head 转到状态 139
+
+
+State 88
+
+ 104 expression: expression . GE expr
+ 105 | expression . GT expr
+ 106 | expression . LE expr
+ 107 | expression . LT expr
+ 108 | expression . EQUAL expr
+ 109 | expression . UNEQUAL expr
+ 126 factor: LP expression . RP
+
+ RP shift, and go to state 140
+ GE shift, and go to state 91
+ GT shift, and go to state 92
+ LE shift, and go to state 93
+ LT shift, and go to state 94
+ EQUAL shift, and go to state 95
+ UNEQUAL shift, and go to state 96
+
+
+State 89
+
+ 128 factor: MINUS factor .
+
+ $default reduce using rule 128 (factor)
+
+
+State 90
+
+ 127 factor: NOT factor .
+
+ $default reduce using rule 127 (factor)
+
+
+State 91
+
+ 104 expression: expression GE . expr
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ expr 转到状态 141
+ term 转到状态 60
+ factor 转到状态 61
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 92
+
+ 105 expression: expression GT . expr
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ expr 转到状态 142
+ term 转到状态 60
+ factor 转到状态 61
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 93
+
+ 106 expression: expression LE . expr
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ expr 转到状态 143
+ term 转到状态 60
+ factor 转到状态 61
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 94
+
+ 107 expression: expression LT . expr
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ expr 转到状态 144
+ term 转到状态 60
+ factor 转到状态 61
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 95
+
+ 108 expression: expression EQUAL . expr
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ expr 转到状态 145
+ term 转到状态 60
+ factor 转到状态 61
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 96
+
+ 109 expression: expression UNEQUAL . expr
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ expr 转到状态 146
+ term 转到状态 60
+ factor 转到状态 61
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 97
+
+ 88 if_stmt: IF expression THEN . stmt else_clause
+
+ BEGIN_T shift, and go to state 12
+ IF shift, and go to state 18
+ REPEAT shift, and go to state 19
+ WHILE shift, and go to state 20
+ FOR shift, and go to state 21
+ CASE shift, and go to state 22
+ GOTO shift, and go to state 23
+ READ shift, and go to state 24
+ INTEGER shift, and go to state 25
+ ID shift, and go to state 4
+ SYS_PROC shift, and go to state 26
+
+ compound_stmt 转到状态 27
+ stmt 转到状态 147
+ non_label_stmt 转到状态 30
+ assign_stmt 转到状态 31
+ proc_stmt 转到状态 32
+ if_stmt 转到状态 33
+ repeat_stmt 转到状态 34
+ while_stmt 转到状态 35
+ for_stmt 转到状态 36
+ case_stmt 转到状态 37
+ goto_stmt 转到状态 38
+ id 转到状态 39
+ sys_proc 转到状态 40
+
+
+State 98
+
+ 111 expr: expr PLUS . term
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ term 转到状态 148
+ factor 转到状态 61
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 99
+
+ 112 expr: expr MINUS . term
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ term 转到状态 149
+ factor 转到状态 61
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 100
+
+ 113 expr: expr OR . term
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ term 转到状态 150
+ factor 转到状态 61
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 101
+
+ 115 term: term MUL . factor
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ factor 转到状态 151
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 102
+
+ 117 term: term REALDIV . factor
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ factor 转到状态 152
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 103
+
+ 116 term: term INTDIV . factor
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ factor 转到状态 153
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 104
+
+ 118 term: term MOD . factor
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ factor 转到状态 154
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 105
+
+ 119 term: term AND . factor
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ factor 转到状态 155
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 106
+
+ 122 factor: id LP . args_list RP
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ expression 转到状态 117
+ expr 转到状态 59
+ term 转到状态 60
+ factor 转到状态 61
+ args_list 转到状态 156
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 107
+
+ 129 factor: id LB . expression RB
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ expression 转到状态 157
+ expr 转到状态 59
+ term 转到状态 60
+ factor 转到状态 61
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 108
+
+ 130 factor: id DOT . id
+
+ ID shift, and go to state 4
+
+ id 转到状态 158
+
+
+State 109
+
+ 124 factor: sys_funct LP . args_list RP
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ expression 转到状态 117
+ expr 转到状态 59
+ term 转到状态 60
+ factor 转到状态 61
+ args_list 转到状态 159
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 110
+
+ 91 repeat_stmt: REPEAT stmt UNTIL . expression
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ expression 转到状态 160
+ expr 转到状态 59
+ term 转到状态 60
+ factor 转到状态 61
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 111
+
+ 92 while_stmt: WHILE expression DO . stmt
+
+ BEGIN_T shift, and go to state 12
+ IF shift, and go to state 18
+ REPEAT shift, and go to state 19
+ WHILE shift, and go to state 20
+ FOR shift, and go to state 21
+ CASE shift, and go to state 22
+ GOTO shift, and go to state 23
+ READ shift, and go to state 24
+ INTEGER shift, and go to state 25
+ ID shift, and go to state 4
+ SYS_PROC shift, and go to state 26
+
+ compound_stmt 转到状态 27
+ stmt 转到状态 161
+ non_label_stmt 转到状态 30
+ assign_stmt 转到状态 31
+ proc_stmt 转到状态 32
+ if_stmt 转到状态 33
+ repeat_stmt 转到状态 34
+ while_stmt 转到状态 35
+ for_stmt 转到状态 36
+ case_stmt 转到状态 37
+ goto_stmt 转到状态 38
+ id 转到状态 39
+ sys_proc 转到状态 40
+
+
+State 112
+
+ 93 for_stmt: FOR id ASSIGN . expression direction expression DO stmt
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ expression 转到状态 162
+ expr 转到状态 59
+ term 转到状态 60
+ factor 转到状态 61
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 113
+
+ 96 case_stmt: CASE expression OF . case_expr_list END
+
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+
+ const_value 转到状态 163
+ case_expr_list 转到状态 164
+ case_expr 转到状态 165
+ id 转到状态 166
+ sys_con 转到状态 63
+
+
+State 114
+
+ 87 proc_stmt: READ LP factor . RP
+
+ RP shift, and go to state 167
+
+
+State 115
+
+ 69 stmt: INTEGER COLON non_label_stmt .
+
+ $default reduce using rule 69 (stmt)
+
+
+State 116
+
+ 66 stmt_list: stmt SEMI stmt_list .
+
+ $default reduce using rule 66 (stmt_list)
+
+
+State 117
+
+ 104 expression: expression . GE expr
+ 105 | expression . GT expr
+ 106 | expression . LE expr
+ 107 | expression . LT expr
+ 108 | expression . EQUAL expr
+ 109 | expression . UNEQUAL expr
+ 132 args_list: expression .
+
+ GE shift, and go to state 91
+ GT shift, and go to state 92
+ LE shift, and go to state 93
+ LT shift, and go to state 94
+ EQUAL shift, and go to state 95
+ UNEQUAL shift, and go to state 96
+
+ $default reduce using rule 132 (args_list)
+
+
+State 118
+
+ 84 proc_stmt: id LP args_list . RP
+ 131 args_list: args_list . COMMA expression
+
+ RP shift, and go to state 168
+ COMMA shift, and go to state 169
+
+
+State 119
+
+ 81 assign_stmt: id LB expression . RB ASSIGN expression
+ 104 expression: expression . GE expr
+ 105 | expression . GT expr
+ 106 | expression . LE expr
+ 107 | expression . LT expr
+ 108 | expression . EQUAL expr
+ 109 | expression . UNEQUAL expr
+
+ RB shift, and go to state 170
+ GE shift, and go to state 91
+ GT shift, and go to state 92
+ LE shift, and go to state 93
+ LT shift, and go to state 94
+ EQUAL shift, and go to state 95
+ UNEQUAL shift, and go to state 96
+
+
+State 120
+
+ 82 assign_stmt: id DOT id . ASSIGN expression
+
+ ASSIGN shift, and go to state 171
+
+
+State 121
+
+ 80 assign_stmt: id ASSIGN expression .
+ 104 expression: expression . GE expr
+ 105 | expression . GT expr
+ 106 | expression . LE expr
+ 107 | expression . LT expr
+ 108 | expression . EQUAL expr
+ 109 | expression . UNEQUAL expr
+
+ GE shift, and go to state 91
+ GT shift, and go to state 92
+ LE shift, and go to state 93
+ LT shift, and go to state 94
+ EQUAL shift, and go to state 95
+ UNEQUAL shift, and go to state 96
+
+ $default reduce using rule 80 (assign_stmt)
+
+
+State 122
+
+ 86 proc_stmt: sys_proc LP expression_list . RP
+
+ RP shift, and go to state 172
+
+
+State 123
+
+ 102 expression_list: expression . COMMA expression_list
+ 103 | expression .
+ 104 expression: expression . GE expr
+ 105 | expression . GT expr
+ 106 | expression . LE expr
+ 107 | expression . LT expr
+ 108 | expression . EQUAL expr
+ 109 | expression . UNEQUAL expr
+
+ COMMA shift, and go to state 173
+ GE shift, and go to state 91
+ GT shift, and go to state 92
+ LE shift, and go to state 93
+ LT shift, and go to state 94
+ EQUAL shift, and go to state 95
+ UNEQUAL shift, and go to state 96
+
+ $default reduce using rule 103 (expression_list)
+
+
+State 124
+
+ 8 const_expr_list: id EQUAL const_value . SEMI const_expr_list
+ 9 | id EQUAL const_value . SEMI
+
+ SEMI shift, and go to state 174
+
+
+State 125
+
+ 19 type_decl_list: type_definition type_decl_list .
+
+ $default reduce using rule 19 (type_decl_list)
+
+
+State 126
+
+ 23 type_definition: id EQUAL . type_decl SEMI
+
+ LP shift, and go to state 175
+ MINUS shift, and go to state 176
+ ARRAY shift, and go to state 177
+ RECORD shift, and go to state 178
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_TYPE shift, and go to state 179
+
+ const_value 转到状态 180
+ type_decl 转到状态 181
+ simple_type_decl 转到状态 182
+ array_type_decl 转到状态 183
+ record_type_decl 转到状态 184
+ id 转到状态 185
+ sys_con 转到状态 63
+ sys_type 转到状态 186
+
+
+State 127
+
+ 21 type_decl_list: error_stmt type_decl_list .
+
+ $default reduce using rule 21 (type_decl_list)
+
+
+State 128
+
+ 39 name_list: name_list . COMMA id
+ 47 var_decl: name_list . COLON type_decl SEMI
+
+ COMMA shift, and go to state 187
+ COLON shift, and go to state 188
+
+
+State 129
+
+ 41 var_part: VAR var_decl_list .
+
+ $default reduce using rule 41 (var_part)
+
+
+State 130
+
+ 43 var_decl_list: var_decl . var_decl_list
+ 44 | var_decl .
+
+ error shift, and go to state 17
+ ID shift, and go to state 4
+
+ FUNCTION reduce using rule 44 (var_decl_list)
+ PROCEDURE reduce using rule 44 (var_decl_list)
+ BEGIN_T reduce using rule 44 (var_decl_list)
+
+ name_list 转到状态 128
+ var_decl_list 转到状态 189
+ var_decl 转到状态 130
+ id 转到状态 131
+ error_stmt 转到状态 132
+
+
+State 131
+
+ 40 name_list: id .
+
+ $default reduce using rule 40 (name_list)
+
+
+State 132
+
+ 45 var_decl_list: error_stmt . var_decl_list
+ 46 | error_stmt .
+
+ error shift, and go to state 17
+ ID shift, and go to state 4
+
+ FUNCTION reduce using rule 46 (var_decl_list)
+ PROCEDURE reduce using rule 46 (var_decl_list)
+ BEGIN_T reduce using rule 46 (var_decl_list)
+
+ name_list 转到状态 128
+ var_decl_list 转到状态 190
+ var_decl 转到状态 130
+ id 转到状态 131
+ error_stmt 转到状态 132
+
+
+State 133
+
+ 52 function_head: FUNCTION . id parameters COLON simple_type_decl
+
+ ID shift, and go to state 4
+
+ id 转到状态 191
+
+
+State 134
+
+ 54 procedure_head: PROCEDURE . id parameters
+
+ ID shift, and go to state 4
+
+ id 转到状态 192
+
+
+State 135
+
+ 4 routine_head: label_part const_part type_part var_part routine_part .
+
+ $default reduce using rule 4 (routine_head)
+
+
+State 136
+
+ 48 routine_part: function_decl . routine_part
+
+ FUNCTION shift, and go to state 133
+ PROCEDURE shift, and go to state 134
+
+ $default reduce using rule 50 (routine_part)
+
+ routine_part 转到状态 193
+ function_decl 转到状态 136
+ function_head 转到状态 137
+ procedure_decl 转到状态 138
+ procedure_head 转到状态 139
+
+
+State 137
+
+ 51 function_decl: function_head . SEMI sub_routine SEMI
+
+ SEMI shift, and go to state 194
+
+
+State 138
+
+ 49 routine_part: procedure_decl . routine_part
+
+ FUNCTION shift, and go to state 133
+ PROCEDURE shift, and go to state 134
+
+ $default reduce using rule 50 (routine_part)
+
+ routine_part 转到状态 195
+ function_decl 转到状态 136
+ function_head 转到状态 137
+ procedure_decl 转到状态 138
+ procedure_head 转到状态 139
+
+
+State 139
+
+ 53 procedure_decl: procedure_head . SEMI sub_routine SEMI
+
+ SEMI shift, and go to state 196
+
+
+State 140
+
+ 126 factor: LP expression RP .
+
+ $default reduce using rule 126 (factor)
+
+
+State 141
+
+ 104 expression: expression GE expr .
+ 111 expr: expr . PLUS term
+ 112 | expr . MINUS term
+ 113 | expr . OR term
+
+ PLUS shift, and go to state 98
+ MINUS shift, and go to state 99
+ OR shift, and go to state 100
+
+ $default reduce using rule 104 (expression)
+
+
+State 142
+
+ 105 expression: expression GT expr .
+ 111 expr: expr . PLUS term
+ 112 | expr . MINUS term
+ 113 | expr . OR term
+
+ PLUS shift, and go to state 98
+ MINUS shift, and go to state 99
+ OR shift, and go to state 100
+
+ $default reduce using rule 105 (expression)
+
+
+State 143
+
+ 106 expression: expression LE expr .
+ 111 expr: expr . PLUS term
+ 112 | expr . MINUS term
+ 113 | expr . OR term
+
+ PLUS shift, and go to state 98
+ MINUS shift, and go to state 99
+ OR shift, and go to state 100
+
+ $default reduce using rule 106 (expression)
+
+
+State 144
+
+ 107 expression: expression LT expr .
+ 111 expr: expr . PLUS term
+ 112 | expr . MINUS term
+ 113 | expr . OR term
+
+ PLUS shift, and go to state 98
+ MINUS shift, and go to state 99
+ OR shift, and go to state 100
+
+ $default reduce using rule 107 (expression)
+
+
+State 145
+
+ 108 expression: expression EQUAL expr .
+ 111 expr: expr . PLUS term
+ 112 | expr . MINUS term
+ 113 | expr . OR term
+
+ PLUS shift, and go to state 98
+ MINUS shift, and go to state 99
+ OR shift, and go to state 100
+
+ $default reduce using rule 108 (expression)
+
+
+State 146
+
+ 109 expression: expression UNEQUAL expr .
+ 111 expr: expr . PLUS term
+ 112 | expr . MINUS term
+ 113 | expr . OR term
+
+ PLUS shift, and go to state 98
+ MINUS shift, and go to state 99
+ OR shift, and go to state 100
+
+ $default reduce using rule 109 (expression)
+
+
+State 147
+
+ 88 if_stmt: IF expression THEN stmt . else_clause
+
+ ELSE shift, and go to state 197
+
+ ELSE [reduce using rule 90 (else_clause)]
+ $default reduce using rule 90 (else_clause)
+
+ else_clause 转到状态 198
+
+
+State 148
+
+ 111 expr: expr PLUS term .
+ 115 term: term . MUL factor
+ 116 | term . INTDIV factor
+ 117 | term . REALDIV factor
+ 118 | term . MOD factor
+ 119 | term . AND factor
+
+ MUL shift, and go to state 101
+ REALDIV shift, and go to state 102
+ INTDIV shift, and go to state 103
+ MOD shift, and go to state 104
+ AND shift, and go to state 105
+
+ $default reduce using rule 111 (expr)
+
+
+State 149
+
+ 112 expr: expr MINUS term .
+ 115 term: term . MUL factor
+ 116 | term . INTDIV factor
+ 117 | term . REALDIV factor
+ 118 | term . MOD factor
+ 119 | term . AND factor
+
+ MUL shift, and go to state 101
+ REALDIV shift, and go to state 102
+ INTDIV shift, and go to state 103
+ MOD shift, and go to state 104
+ AND shift, and go to state 105
+
+ $default reduce using rule 112 (expr)
+
+
+State 150
+
+ 113 expr: expr OR term .
+ 115 term: term . MUL factor
+ 116 | term . INTDIV factor
+ 117 | term . REALDIV factor
+ 118 | term . MOD factor
+ 119 | term . AND factor
+
+ MUL shift, and go to state 101
+ REALDIV shift, and go to state 102
+ INTDIV shift, and go to state 103
+ MOD shift, and go to state 104
+ AND shift, and go to state 105
+
+ $default reduce using rule 113 (expr)
+
+
+State 151
+
+ 115 term: term MUL factor .
+
+ $default reduce using rule 115 (term)
+
+
+State 152
+
+ 117 term: term REALDIV factor .
+
+ $default reduce using rule 117 (term)
+
+
+State 153
+
+ 116 term: term INTDIV factor .
+
+ $default reduce using rule 116 (term)
+
+
+State 154
+
+ 118 term: term MOD factor .
+
+ $default reduce using rule 118 (term)
+
+
+State 155
+
+ 119 term: term AND factor .
+
+ $default reduce using rule 119 (term)
+
+
+State 156
+
+ 122 factor: id LP args_list . RP
+ 131 args_list: args_list . COMMA expression
+
+ RP shift, and go to state 199
+ COMMA shift, and go to state 169
+
+
+State 157
+
+ 104 expression: expression . GE expr
+ 105 | expression . GT expr
+ 106 | expression . LE expr
+ 107 | expression . LT expr
+ 108 | expression . EQUAL expr
+ 109 | expression . UNEQUAL expr
+ 129 factor: id LB expression . RB
+
+ RB shift, and go to state 200
+ GE shift, and go to state 91
+ GT shift, and go to state 92
+ LE shift, and go to state 93
+ LT shift, and go to state 94
+ EQUAL shift, and go to state 95
+ UNEQUAL shift, and go to state 96
+
+
+State 158
+
+ 130 factor: id DOT id .
+
+ $default reduce using rule 130 (factor)
+
+
+State 159
+
+ 124 factor: sys_funct LP args_list . RP
+ 131 args_list: args_list . COMMA expression
+
+ RP shift, and go to state 201
+ COMMA shift, and go to state 169
+
+
+State 160
+
+ 91 repeat_stmt: REPEAT stmt UNTIL expression .
+ 104 expression: expression . GE expr
+ 105 | expression . GT expr
+ 106 | expression . LE expr
+ 107 | expression . LT expr
+ 108 | expression . EQUAL expr
+ 109 | expression . UNEQUAL expr
+
+ GE shift, and go to state 91
+ GT shift, and go to state 92
+ LE shift, and go to state 93
+ LT shift, and go to state 94
+ EQUAL shift, and go to state 95
+ UNEQUAL shift, and go to state 96
+
+ $default reduce using rule 91 (repeat_stmt)
+
+
+State 161
+
+ 92 while_stmt: WHILE expression DO stmt .
+
+ $default reduce using rule 92 (while_stmt)
+
+
+State 162
+
+ 93 for_stmt: FOR id ASSIGN expression . direction expression DO stmt
+ 104 expression: expression . GE expr
+ 105 | expression . GT expr
+ 106 | expression . LE expr
+ 107 | expression . LT expr
+ 108 | expression . EQUAL expr
+ 109 | expression . UNEQUAL expr
+
+ GE shift, and go to state 91
+ GT shift, and go to state 92
+ LE shift, and go to state 93
+ LT shift, and go to state 94
+ EQUAL shift, and go to state 95
+ UNEQUAL shift, and go to state 96
+ TO shift, and go to state 202
+ DOWNTO shift, and go to state 203
+
+ direction 转到状态 204
+
+
+State 163
+
+ 99 case_expr: const_value . COLON stmt SEMI
+
+ COLON shift, and go to state 205
+
+
+State 164
+
+ 96 case_stmt: CASE expression OF case_expr_list . END
+
+ END shift, and go to state 206
+
+
+State 165
+
+ 97 case_expr_list: case_expr . case_expr_list
+ 98 | case_expr .
+
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+
+ $default reduce using rule 98 (case_expr_list)
+
+ const_value 转到状态 163
+ case_expr_list 转到状态 207
+ case_expr 转到状态 165
+ id 转到状态 166
+ sys_con 转到状态 63
+
+
+State 166
+
+ 100 case_expr: id . COLON stmt SEMI
+
+ COLON shift, and go to state 208
+
+
+State 167
+
+ 87 proc_stmt: READ LP factor RP .
+
+ $default reduce using rule 87 (proc_stmt)
+
+
+State 168
+
+ 84 proc_stmt: id LP args_list RP .
+
+ $default reduce using rule 84 (proc_stmt)
+
+
+State 169
+
+ 131 args_list: args_list COMMA . expression
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ expression 转到状态 209
+ expr 转到状态 59
+ term 转到状态 60
+ factor 转到状态 61
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 170
+
+ 81 assign_stmt: id LB expression RB . ASSIGN expression
+
+ ASSIGN shift, and go to state 210
+
+
+State 171
+
+ 82 assign_stmt: id DOT id ASSIGN . expression
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ expression 转到状态 211
+ expr 转到状态 59
+ term 转到状态 60
+ factor 转到状态 61
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 172
+
+ 86 proc_stmt: sys_proc LP expression_list RP .
+
+ $default reduce using rule 86 (proc_stmt)
+
+
+State 173
+
+ 102 expression_list: expression COMMA . expression_list
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ expression_list 转到状态 212
+ expression 转到状态 123
+ expr 转到状态 59
+ term 转到状态 60
+ factor 转到状态 61
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 174
+
+ 8 const_expr_list: id EQUAL const_value SEMI . const_expr_list
+ 9 | id EQUAL const_value SEMI .
+
+ error shift, and go to state 17
+ ID shift, and go to state 4
+
+ FUNCTION reduce using rule 9 (const_expr_list)
+ PROCEDURE reduce using rule 9 (const_expr_list)
+ BEGIN_T reduce using rule 9 (const_expr_list)
+ TYPE reduce using rule 9 (const_expr_list)
+ VAR reduce using rule 9 (const_expr_list)
+
+ const_expr_list 转到状态 213
+ id 转到状态 43
+ error_stmt 转到状态 44
+
+
+State 175
+
+ 29 simple_type_decl: LP . name_list RP
+
+ ID shift, and go to state 4
+
+ name_list 转到状态 214
+ id 转到状态 131
+
+
+State 176
+
+ 31 simple_type_decl: MINUS . const_value DOTDOT const_value
+ 32 | MINUS . const_value DOTDOT MINUS const_value
+
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+
+ const_value 转到状态 215
+ sys_con 转到状态 63
+
+
+State 177
+
+ 34 array_type_decl: ARRAY . LB simple_type_decl RB OF type_decl
+
+ LB shift, and go to state 216
+
+
+State 178
+
+ 35 record_type_decl: RECORD . field_decl_list END
+
+ ID shift, and go to state 4
+
+ field_decl_list 转到状态 217
+ field_decl 转到状态 218
+ name_list 转到状态 219
+ id 转到状态 131
+
+
+State 179
+
+ 137 sys_type: SYS_TYPE .
+
+ $default reduce using rule 137 (sys_type)
+
+
+State 180
+
+ 30 simple_type_decl: const_value . DOTDOT const_value
+
+ DOTDOT shift, and go to state 220
+
+
+State 181
+
+ 23 type_definition: id EQUAL type_decl . SEMI
+
+ SEMI shift, and go to state 221
+
+
+State 182
+
+ 24 type_decl: simple_type_decl .
+
+ $default reduce using rule 24 (type_decl)
+
+
+State 183
+
+ 25 type_decl: array_type_decl .
+
+ $default reduce using rule 25 (type_decl)
+
+
+State 184
+
+ 26 type_decl: record_type_decl .
+
+ $default reduce using rule 26 (type_decl)
+
+
+State 185
+
+ 28 simple_type_decl: id .
+ 33 | id . DOTDOT id
+
+ DOTDOT shift, and go to state 222
+
+ $default reduce using rule 28 (simple_type_decl)
+
+
+State 186
+
+ 27 simple_type_decl: sys_type .
+
+ $default reduce using rule 27 (simple_type_decl)
+
+
+State 187
+
+ 39 name_list: name_list COMMA . id
+
+ ID shift, and go to state 4
+
+ id 转到状态 223
+
+
+State 188
+
+ 47 var_decl: name_list COLON . type_decl SEMI
+
+ LP shift, and go to state 175
+ MINUS shift, and go to state 176
+ ARRAY shift, and go to state 177
+ RECORD shift, and go to state 178
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_TYPE shift, and go to state 179
+
+ const_value 转到状态 180
+ type_decl 转到状态 224
+ simple_type_decl 转到状态 182
+ array_type_decl 转到状态 183
+ record_type_decl 转到状态 184
+ id 转到状态 185
+ sys_con 转到状态 63
+ sys_type 转到状态 186
+
+
+State 189
+
+ 43 var_decl_list: var_decl var_decl_list .
+
+ $default reduce using rule 43 (var_decl_list)
+
+
+State 190
+
+ 45 var_decl_list: error_stmt var_decl_list .
+
+ $default reduce using rule 45 (var_decl_list)
+
+
+State 191
+
+ 52 function_head: FUNCTION id . parameters COLON simple_type_decl
+
+ LP shift, and go to state 225
+
+ $default reduce using rule 57 (parameters)
+
+ parameters 转到状态 226
+
+
+State 192
+
+ 54 procedure_head: PROCEDURE id . parameters
+
+ LP shift, and go to state 225
+
+ $default reduce using rule 57 (parameters)
+
+ parameters 转到状态 227
+
+
+State 193
+
+ 48 routine_part: function_decl routine_part .
+
+ $default reduce using rule 48 (routine_part)
+
+
+State 194
+
+ 51 function_decl: function_head SEMI . sub_routine SEMI
+
+ $default reduce using rule 5 (label_part)
+
+ routine_head 转到状态 228
+ label_part 转到状态 9
+ sub_routine 转到状态 229
+
+
+State 195
+
+ 49 routine_part: procedure_decl routine_part .
+
+ $default reduce using rule 49 (routine_part)
+
+
+State 196
+
+ 53 procedure_decl: procedure_head SEMI . sub_routine SEMI
+
+ $default reduce using rule 5 (label_part)
+
+ routine_head 转到状态 228
+ label_part 转到状态 9
+ sub_routine 转到状态 230
+
+
+State 197
+
+ 89 else_clause: ELSE . stmt
+
+ BEGIN_T shift, and go to state 12
+ IF shift, and go to state 18
+ REPEAT shift, and go to state 19
+ WHILE shift, and go to state 20
+ FOR shift, and go to state 21
+ CASE shift, and go to state 22
+ GOTO shift, and go to state 23
+ READ shift, and go to state 24
+ INTEGER shift, and go to state 25
+ ID shift, and go to state 4
+ SYS_PROC shift, and go to state 26
+
+ compound_stmt 转到状态 27
+ stmt 转到状态 231
+ non_label_stmt 转到状态 30
+ assign_stmt 转到状态 31
+ proc_stmt 转到状态 32
+ if_stmt 转到状态 33
+ repeat_stmt 转到状态 34
+ while_stmt 转到状态 35
+ for_stmt 转到状态 36
+ case_stmt 转到状态 37
+ goto_stmt 转到状态 38
+ id 转到状态 39
+ sys_proc 转到状态 40
+
+
+State 198
+
+ 88 if_stmt: IF expression THEN stmt else_clause .
+
+ $default reduce using rule 88 (if_stmt)
+
+
+State 199
+
+ 122 factor: id LP args_list RP .
+
+ $default reduce using rule 122 (factor)
+
+
+State 200
+
+ 129 factor: id LB expression RB .
+
+ $default reduce using rule 129 (factor)
+
+
+State 201
+
+ 124 factor: sys_funct LP args_list RP .
+
+ $default reduce using rule 124 (factor)
+
+
+State 202
+
+ 94 direction: TO .
+
+ $default reduce using rule 94 (direction)
+
+
+State 203
+
+ 95 direction: DOWNTO .
+
+ $default reduce using rule 95 (direction)
+
+
+State 204
+
+ 93 for_stmt: FOR id ASSIGN expression direction . expression DO stmt
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ expression 转到状态 232
+ expr 转到状态 59
+ term 转到状态 60
+ factor 转到状态 61
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 205
+
+ 99 case_expr: const_value COLON . stmt SEMI
+
+ BEGIN_T shift, and go to state 12
+ IF shift, and go to state 18
+ REPEAT shift, and go to state 19
+ WHILE shift, and go to state 20
+ FOR shift, and go to state 21
+ CASE shift, and go to state 22
+ GOTO shift, and go to state 23
+ READ shift, and go to state 24
+ INTEGER shift, and go to state 25
+ ID shift, and go to state 4
+ SYS_PROC shift, and go to state 26
+
+ compound_stmt 转到状态 27
+ stmt 转到状态 233
+ non_label_stmt 转到状态 30
+ assign_stmt 转到状态 31
+ proc_stmt 转到状态 32
+ if_stmt 转到状态 33
+ repeat_stmt 转到状态 34
+ while_stmt 转到状态 35
+ for_stmt 转到状态 36
+ case_stmt 转到状态 37
+ goto_stmt 转到状态 38
+ id 转到状态 39
+ sys_proc 转到状态 40
+
+
+State 206
+
+ 96 case_stmt: CASE expression OF case_expr_list END .
+
+ $default reduce using rule 96 (case_stmt)
+
+
+State 207
+
+ 97 case_expr_list: case_expr case_expr_list .
+
+ $default reduce using rule 97 (case_expr_list)
+
+
+State 208
+
+ 100 case_expr: id COLON . stmt SEMI
+
+ BEGIN_T shift, and go to state 12
+ IF shift, and go to state 18
+ REPEAT shift, and go to state 19
+ WHILE shift, and go to state 20
+ FOR shift, and go to state 21
+ CASE shift, and go to state 22
+ GOTO shift, and go to state 23
+ READ shift, and go to state 24
+ INTEGER shift, and go to state 25
+ ID shift, and go to state 4
+ SYS_PROC shift, and go to state 26
+
+ compound_stmt 转到状态 27
+ stmt 转到状态 234
+ non_label_stmt 转到状态 30
+ assign_stmt 转到状态 31
+ proc_stmt 转到状态 32
+ if_stmt 转到状态 33
+ repeat_stmt 转到状态 34
+ while_stmt 转到状态 35
+ for_stmt 转到状态 36
+ case_stmt 转到状态 37
+ goto_stmt 转到状态 38
+ id 转到状态 39
+ sys_proc 转到状态 40
+
+
+State 209
+
+ 104 expression: expression . GE expr
+ 105 | expression . GT expr
+ 106 | expression . LE expr
+ 107 | expression . LT expr
+ 108 | expression . EQUAL expr
+ 109 | expression . UNEQUAL expr
+ 131 args_list: args_list COMMA expression .
+
+ GE shift, and go to state 91
+ GT shift, and go to state 92
+ LE shift, and go to state 93
+ LT shift, and go to state 94
+ EQUAL shift, and go to state 95
+ UNEQUAL shift, and go to state 96
+
+ $default reduce using rule 131 (args_list)
+
+
+State 210
+
+ 81 assign_stmt: id LB expression RB ASSIGN . expression
+
+ LP shift, and go to state 48
+ MINUS shift, and go to state 49
+ NOT shift, and go to state 50
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_FUNCT shift, and go to state 56
+
+ const_value 转到状态 57
+ expression 转到状态 235
+ expr 转到状态 59
+ term 转到状态 60
+ factor 转到状态 61
+ id 转到状态 62
+ sys_con 转到状态 63
+ sys_funct 转到状态 64
+
+
+State 211
+
+ 82 assign_stmt: id DOT id ASSIGN expression .
+ 104 expression: expression . GE expr
+ 105 | expression . GT expr
+ 106 | expression . LE expr
+ 107 | expression . LT expr
+ 108 | expression . EQUAL expr
+ 109 | expression . UNEQUAL expr
+
+ GE shift, and go to state 91
+ GT shift, and go to state 92
+ LE shift, and go to state 93
+ LT shift, and go to state 94
+ EQUAL shift, and go to state 95
+ UNEQUAL shift, and go to state 96
+
+ $default reduce using rule 82 (assign_stmt)
+
+
+State 212
+
+ 102 expression_list: expression COMMA expression_list .
+
+ $default reduce using rule 102 (expression_list)
+
+
+State 213
+
+ 8 const_expr_list: id EQUAL const_value SEMI const_expr_list .
+
+ $default reduce using rule 8 (const_expr_list)
+
+
+State 214
+
+ 29 simple_type_decl: LP name_list . RP
+ 39 name_list: name_list . COMMA id
+
+ RP shift, and go to state 236
+ COMMA shift, and go to state 187
+
+
+State 215
+
+ 31 simple_type_decl: MINUS const_value . DOTDOT const_value
+ 32 | MINUS const_value . DOTDOT MINUS const_value
+
+ DOTDOT shift, and go to state 237
+
+
+State 216
+
+ 34 array_type_decl: ARRAY LB . simple_type_decl RB OF type_decl
+
+ LP shift, and go to state 175
+ MINUS shift, and go to state 176
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_TYPE shift, and go to state 179
+
+ const_value 转到状态 180
+ simple_type_decl 转到状态 238
+ id 转到状态 185
+ sys_con 转到状态 63
+ sys_type 转到状态 186
+
+
+State 217
+
+ 35 record_type_decl: RECORD field_decl_list . END
+
+ END shift, and go to state 239
+
+
+State 218
+
+ 36 field_decl_list: field_decl . field_decl_list
+ 37 | field_decl .
+
+ ID shift, and go to state 4
+
+ $default reduce using rule 37 (field_decl_list)
+
+ field_decl_list 转到状态 240
+ field_decl 转到状态 218
+ name_list 转到状态 219
+ id 转到状态 131
+
+
+State 219
+
+ 38 field_decl: name_list . COLON type_decl SEMI
+ 39 name_list: name_list . COMMA id
+
+ COMMA shift, and go to state 187
+ COLON shift, and go to state 241
+
+
+State 220
+
+ 30 simple_type_decl: const_value DOTDOT . const_value
+
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+
+ const_value 转到状态 242
+ sys_con 转到状态 63
+
+
+State 221
+
+ 23 type_definition: id EQUAL type_decl SEMI .
+
+ $default reduce using rule 23 (type_definition)
+
+
+State 222
+
+ 33 simple_type_decl: id DOTDOT . id
+
+ ID shift, and go to state 4
+
+ id 转到状态 243
+
+
+State 223
+
+ 39 name_list: name_list COMMA id .
+
+ $default reduce using rule 39 (name_list)
+
+
+State 224
+
+ 47 var_decl: name_list COLON type_decl . SEMI
+
+ SEMI shift, and go to state 244
+
+
+State 225
+
+ 56 parameters: LP . para_decl_list RP
+
+ VAR shift, and go to state 245
+ ID shift, and go to state 4
+
+ name_list 转到状态 246
+ para_decl_list 转到状态 247
+ para_type_list 转到状态 248
+ var_para_list 转到状态 249
+ val_para_list 转到状态 250
+ id 转到状态 131
+
+
+State 226
+
+ 52 function_head: FUNCTION id parameters . COLON simple_type_decl
+
+ COLON shift, and go to state 251
+
+
+State 227
+
+ 54 procedure_head: PROCEDURE id parameters .
+
+ $default reduce using rule 54 (procedure_head)
+
+
+State 228
+
+ 55 sub_routine: routine_head . routine_body
+
+ BEGIN_T shift, and go to state 12
+
+ routine_body 转到状态 252
+ compound_stmt 转到状态 14
+
+
+State 229
+
+ 51 function_decl: function_head SEMI sub_routine . SEMI
+
+ SEMI shift, and go to state 253
+
+
+State 230
+
+ 53 procedure_decl: procedure_head SEMI sub_routine . SEMI
+
+ SEMI shift, and go to state 254
+
+
+State 231
+
+ 89 else_clause: ELSE stmt .
+
+ $default reduce using rule 89 (else_clause)
+
+
+State 232
+
+ 93 for_stmt: FOR id ASSIGN expression direction expression . DO stmt
+ 104 expression: expression . GE expr
+ 105 | expression . GT expr
+ 106 | expression . LE expr
+ 107 | expression . LT expr
+ 108 | expression . EQUAL expr
+ 109 | expression . UNEQUAL expr
+
+ GE shift, and go to state 91
+ GT shift, and go to state 92
+ LE shift, and go to state 93
+ LT shift, and go to state 94
+ EQUAL shift, and go to state 95
+ UNEQUAL shift, and go to state 96
+ DO shift, and go to state 255
+
+
+State 233
+
+ 99 case_expr: const_value COLON stmt . SEMI
+
+ SEMI shift, and go to state 256
+
+
+State 234
+
+ 100 case_expr: id COLON stmt . SEMI
+
+ SEMI shift, and go to state 257
+
+
+State 235
+
+ 81 assign_stmt: id LB expression RB ASSIGN expression .
+ 104 expression: expression . GE expr
+ 105 | expression . GT expr
+ 106 | expression . LE expr
+ 107 | expression . LT expr
+ 108 | expression . EQUAL expr
+ 109 | expression . UNEQUAL expr
+
+ GE shift, and go to state 91
+ GT shift, and go to state 92
+ LE shift, and go to state 93
+ LT shift, and go to state 94
+ EQUAL shift, and go to state 95
+ UNEQUAL shift, and go to state 96
+
+ $default reduce using rule 81 (assign_stmt)
+
+
+State 236
+
+ 29 simple_type_decl: LP name_list RP .
+
+ $default reduce using rule 29 (simple_type_decl)
+
+
+State 237
+
+ 31 simple_type_decl: MINUS const_value DOTDOT . const_value
+ 32 | MINUS const_value DOTDOT . MINUS const_value
+
+ MINUS shift, and go to state 258
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+
+ const_value 转到状态 259
+ sys_con 转到状态 63
+
+
+State 238
+
+ 34 array_type_decl: ARRAY LB simple_type_decl . RB OF type_decl
+
+ RB shift, and go to state 260
+
+
+State 239
+
+ 35 record_type_decl: RECORD field_decl_list END .
+
+ $default reduce using rule 35 (record_type_decl)
+
+
+State 240
+
+ 36 field_decl_list: field_decl field_decl_list .
+
+ $default reduce using rule 36 (field_decl_list)
+
+
+State 241
+
+ 38 field_decl: name_list COLON . type_decl SEMI
+
+ LP shift, and go to state 175
+ MINUS shift, and go to state 176
+ ARRAY shift, and go to state 177
+ RECORD shift, and go to state 178
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_TYPE shift, and go to state 179
+
+ const_value 转到状态 180
+ type_decl 转到状态 261
+ simple_type_decl 转到状态 182
+ array_type_decl 转到状态 183
+ record_type_decl 转到状态 184
+ id 转到状态 185
+ sys_con 转到状态 63
+ sys_type 转到状态 186
+
+
+State 242
+
+ 30 simple_type_decl: const_value DOTDOT const_value .
+
+ $default reduce using rule 30 (simple_type_decl)
+
+
+State 243
+
+ 33 simple_type_decl: id DOTDOT id .
+
+ $default reduce using rule 33 (simple_type_decl)
+
+
+State 244
+
+ 47 var_decl: name_list COLON type_decl SEMI .
+
+ $default reduce using rule 47 (var_decl)
+
+
+State 245
+
+ 62 var_para_list: VAR . name_list
+
+ ID shift, and go to state 4
+
+ name_list 转到状态 262
+ id 转到状态 131
+
+
+State 246
+
+ 39 name_list: name_list . COMMA id
+ 63 val_para_list: name_list .
+
+ COMMA shift, and go to state 187
+
+ $default reduce using rule 63 (val_para_list)
+
+
+State 247
+
+ 56 parameters: LP para_decl_list . RP
+ 58 para_decl_list: para_decl_list . SEMI para_type_list
+
+ RP shift, and go to state 263
+ SEMI shift, and go to state 264
+
+
+State 248
+
+ 59 para_decl_list: para_type_list .
+
+ $default reduce using rule 59 (para_decl_list)
+
+
+State 249
+
+ 60 para_type_list: var_para_list . COLON simple_type_decl
+
+ COLON shift, and go to state 265
+
+
+State 250
+
+ 61 para_type_list: val_para_list . COLON simple_type_decl
+
+ COLON shift, and go to state 266
+
+
+State 251
+
+ 52 function_head: FUNCTION id parameters COLON . simple_type_decl
+
+ LP shift, and go to state 175
+ MINUS shift, and go to state 176
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_TYPE shift, and go to state 179
+
+ const_value 转到状态 180
+ simple_type_decl 转到状态 267
+ id 转到状态 185
+ sys_con 转到状态 63
+ sys_type 转到状态 186
+
+
+State 252
+
+ 55 sub_routine: routine_head routine_body .
+
+ $default reduce using rule 55 (sub_routine)
+
+
+State 253
+
+ 51 function_decl: function_head SEMI sub_routine SEMI .
+
+ $default reduce using rule 51 (function_decl)
+
+
+State 254
+
+ 53 procedure_decl: procedure_head SEMI sub_routine SEMI .
+
+ $default reduce using rule 53 (procedure_decl)
+
+
+State 255
+
+ 93 for_stmt: FOR id ASSIGN expression direction expression DO . stmt
+
+ BEGIN_T shift, and go to state 12
+ IF shift, and go to state 18
+ REPEAT shift, and go to state 19
+ WHILE shift, and go to state 20
+ FOR shift, and go to state 21
+ CASE shift, and go to state 22
+ GOTO shift, and go to state 23
+ READ shift, and go to state 24
+ INTEGER shift, and go to state 25
+ ID shift, and go to state 4
+ SYS_PROC shift, and go to state 26
+
+ compound_stmt 转到状态 27
+ stmt 转到状态 268
+ non_label_stmt 转到状态 30
+ assign_stmt 转到状态 31
+ proc_stmt 转到状态 32
+ if_stmt 转到状态 33
+ repeat_stmt 转到状态 34
+ while_stmt 转到状态 35
+ for_stmt 转到状态 36
+ case_stmt 转到状态 37
+ goto_stmt 转到状态 38
+ id 转到状态 39
+ sys_proc 转到状态 40
+
+
+State 256
+
+ 99 case_expr: const_value COLON stmt SEMI .
+
+ $default reduce using rule 99 (case_expr)
+
+
+State 257
+
+ 100 case_expr: id COLON stmt SEMI .
+
+ $default reduce using rule 100 (case_expr)
+
+
+State 258
+
+ 32 simple_type_decl: MINUS const_value DOTDOT MINUS . const_value
+
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+
+ const_value 转到状态 269
+ sys_con 转到状态 63
+
+
+State 259
+
+ 31 simple_type_decl: MINUS const_value DOTDOT const_value .
+
+ $default reduce using rule 31 (simple_type_decl)
+
+
+State 260
+
+ 34 array_type_decl: ARRAY LB simple_type_decl RB . OF type_decl
+
+ OF shift, and go to state 270
+
+
+State 261
+
+ 38 field_decl: name_list COLON type_decl . SEMI
+
+ SEMI shift, and go to state 271
+
+
+State 262
+
+ 39 name_list: name_list . COMMA id
+ 62 var_para_list: VAR name_list .
+
+ COMMA shift, and go to state 187
+
+ $default reduce using rule 62 (var_para_list)
+
+
+State 263
+
+ 56 parameters: LP para_decl_list RP .
+
+ $default reduce using rule 56 (parameters)
+
+
+State 264
+
+ 58 para_decl_list: para_decl_list SEMI . para_type_list
+
+ VAR shift, and go to state 245
+ ID shift, and go to state 4
+
+ name_list 转到状态 246
+ para_type_list 转到状态 272
+ var_para_list 转到状态 249
+ val_para_list 转到状态 250
+ id 转到状态 131
+
+
+State 265
+
+ 60 para_type_list: var_para_list COLON . simple_type_decl
+
+ LP shift, and go to state 175
+ MINUS shift, and go to state 176
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_TYPE shift, and go to state 179
+
+ const_value 转到状态 180
+ simple_type_decl 转到状态 273
+ id 转到状态 185
+ sys_con 转到状态 63
+ sys_type 转到状态 186
+
+
+State 266
+
+ 61 para_type_list: val_para_list COLON . simple_type_decl
+
+ LP shift, and go to state 175
+ MINUS shift, and go to state 176
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_TYPE shift, and go to state 179
+
+ const_value 转到状态 180
+ simple_type_decl 转到状态 274
+ id 转到状态 185
+ sys_con 转到状态 63
+ sys_type 转到状态 186
+
+
+State 267
+
+ 52 function_head: FUNCTION id parameters COLON simple_type_decl .
+
+ $default reduce using rule 52 (function_head)
+
+
+State 268
+
+ 93 for_stmt: FOR id ASSIGN expression direction expression DO stmt .
+
+ $default reduce using rule 93 (for_stmt)
+
+
+State 269
+
+ 32 simple_type_decl: MINUS const_value DOTDOT MINUS const_value .
+
+ $default reduce using rule 32 (simple_type_decl)
+
+
+State 270
+
+ 34 array_type_decl: ARRAY LB simple_type_decl RB OF . type_decl
+
+ LP shift, and go to state 175
+ MINUS shift, and go to state 176
+ ARRAY shift, and go to state 177
+ RECORD shift, and go to state 178
+ INTEGER shift, and go to state 51
+ REAL shift, and go to state 52
+ CHAR shift, and go to state 53
+ ID shift, and go to state 4
+ STRING shift, and go to state 54
+ SYS_CON shift, and go to state 55
+ SYS_TYPE shift, and go to state 179
+
+ const_value 转到状态 180
+ type_decl 转到状态 275
+ simple_type_decl 转到状态 182
+ array_type_decl 转到状态 183
+ record_type_decl 转到状态 184
+ id 转到状态 185
+ sys_con 转到状态 63
+ sys_type 转到状态 186
+
+
+State 271
+
+ 38 field_decl: name_list COLON type_decl SEMI .
+
+ $default reduce using rule 38 (field_decl)
+
+
+State 272
+
+ 58 para_decl_list: para_decl_list SEMI para_type_list .
+
+ $default reduce using rule 58 (para_decl_list)
+
+
+State 273
+
+ 60 para_type_list: var_para_list COLON simple_type_decl .
+
+ $default reduce using rule 60 (para_type_list)
+
+
+State 274
+
+ 61 para_type_list: val_para_list COLON simple_type_decl .
+
+ $default reduce using rule 61 (para_type_list)
+
+
+State 275
+
+ 34 array_type_decl: ARRAY LB simple_type_decl RB OF type_decl .
+
+ $default reduce using rule 34 (array_type_decl)
diff --git a/src/y.tab.c b/CompilerPascal/y.tab.c
similarity index 75%
rename from src/y.tab.c
rename to CompilerPascal/y.tab.c
index 5e42041..ff6ad62 100644
--- a/src/y.tab.c
+++ b/CompilerPascal/y.tab.c
@@ -532,16 +532,16 @@ union yyalloc
/* YYFINAL -- State number of the termination state. */
#define YYFINAL 6
/* YYLAST -- Last index in YYTABLE. */
-#define YYLAST 390
+#define YYLAST 467
/* YYNTOKENS -- Number of terminals. */
#define YYNTOKENS 61
/* YYNNTS -- Number of nonterminals. */
#define YYNNTS 62
/* YYNRULES -- Number of rules. */
-#define YYNRULES 133
+#define YYNRULES 139
/* YYNSTATES -- Number of states. */
-#define YYNSTATES 269
+#define YYNSTATES 276
/* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
by yylex, with out-of-bounds checking. */
@@ -591,22 +591,22 @@ static const yytype_uint8 yytranslate[] =
#if YYDEBUG
/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
-static const yytype_uint8 yyrline[] =
+static const yytype_uint16 yyrline[] =
{
0, 81, 81, 82, 83, 84, 98, 101, 102, 103,
- 104, 105, 106, 107, 108, 109, 112, 113, 114, 115,
+ 104, 105, 106, 107, 108, 109, 110, 111, 114, 115,
116, 117, 118, 119, 120, 121, 122, 123, 124, 125,
- 126, 127, 128, 130, 131, 132, 133, 134, 137, 138,
- 139, 140, 141, 144, 145, 146, 148, 149, 150, 151,
- 152, 153, 154, 155, 156, 157, 158, 159, 160, 163,
- 164, 165, 166, 167, 168, 169, 170, 171, 172, 173,
+ 126, 127, 128, 129, 130, 131, 132, 134, 135, 136,
+ 137, 138, 141, 142, 143, 144, 145, 146, 147, 150,
+ 151, 152, 154, 155, 156, 157, 158, 159, 160, 161,
+ 162, 163, 164, 165, 166, 169, 170, 171, 172, 173,
174, 175, 176, 177, 178, 179, 180, 181, 182, 183,
- 184, 185, 186, 187, 188, 189, 190, 192, 193, 203,
- 204, 205, 206, 207, 208, 209, 210, 212, 213, 214,
- 215, 216, 217, 218, 219, 220, 222, 223, 224, 225,
- 226, 227, 228, 229, 230, 231, 232, 233, 234, 235,
- 236, 237, 238, 239, 240, 241, 242, 243, 245, 246,
- 247, 248, 249, 251
+ 184, 185, 186, 187, 188, 189, 190, 191, 192, 193,
+ 194, 195, 196, 198, 199, 209, 210, 211, 212, 213,
+ 214, 215, 216, 218, 219, 220, 221, 222, 223, 224,
+ 225, 226, 228, 229, 230, 231, 232, 233, 234, 235,
+ 236, 237, 238, 239, 240, 241, 242, 243, 244, 245,
+ 246, 247, 248, 249, 251, 252, 253, 254, 255, 257
};
#endif
@@ -635,7 +635,7 @@ static const char *const yytname[] =
"repeat_stmt", "while_stmt", "for_stmt", "direction", "case_stmt",
"case_expr_list", "case_expr", "goto_stmt", "expression_list",
"expression", "expr", "term", "factor", "args_list", "id", "sys_con",
- "sys_funct", "sys_proc", "sys_type", "stat", YY_NULLPTR
+ "sys_funct", "sys_proc", "sys_type", "error_stmt", YY_NULLPTR
};
#endif
@@ -654,12 +654,12 @@ static const yytype_uint16 yytoknum[] =
};
# endif
-#define YYPACT_NINF -204
+#define YYPACT_NINF -188
#define yypact_value_is_default(Yystate) \
- (!!((Yystate) == (-204)))
+ (!!((Yystate) == (-188)))
-#define YYTABLE_NINF -63
+#define YYTABLE_NINF -69
#define yytable_value_is_error(Yytable_value) \
0
@@ -668,33 +668,34 @@ static const yytype_uint16 yytoknum[] =
STATE-NUM. */
static const yytype_int16 yypact[] =
{
- -23, -38, 33, -204, -204, 32, -204, 52, 37, 28,
- -204, -204, 88, -204, -204, -38, 54, 74, 233, 262,
- 233, -38, 233, 36, 104, 107, -204, -204, 98, 110,
- -204, -204, -204, -204, -204, -204, -204, -204, -204, 5,
- 138, -204, -204, 109, -38, 106, -204, 233, 233, 233,
- -204, -204, -204, -204, -204, -204, -204, 338, 34, 190,
- -204, 25, -204, 142, 108, 2, 120, 344, -204, 233,
- 282, -204, 88, 233, 233, -38, 233, 233, 197, -204,
- -38, 125, -38, 68, 198, -204, -204, 233, 233, 233,
- 233, 233, 233, 262, 233, 233, 233, 233, 233, 233,
- 233, 233, 233, 233, -38, 233, 233, 262, 233, 318,
- 149, -204, -204, 359, 58, 326, 140, 359, 160, 273,
- 162, -204, 213, 114, -204, -38, -204, -38, -38, -204,
- 68, 163, 68, 165, -204, 34, 34, 34, 34, 34,
- 34, 131, 190, 190, 190, -204, -204, -204, -204, -204,
- 64, 332, -204, 72, 359, -204, 89, 167, 146, 318,
- 169, -204, -204, 233, 157, 233, -204, 233, -38, -38,
- 197, 182, -38, -204, 137, 181, -204, -204, -204, 141,
- -204, -38, 213, -204, 192, 192, -204, -204, -204, -204,
- 262, -204, -204, -204, -204, -204, -204, 233, 262, -204,
- -204, 262, 359, 233, 359, -204, -204, 79, 145, 223,
- 168, -38, 130, 197, -204, -38, -204, 191, -7, 200,
- -204, 37, 201, 202, -204, 15, 203, 214, 359, -204,
- 103, 221, -204, -204, 213, -204, -204, -204, -38, 220,
- 11, -204, 222, 225, 223, -204, -204, -204, 262, -204,
- -204, 197, -204, 195, 228, 220, -204, -7, 223, 223,
- -204, -204, -204, 213, -204, -204, -204, -204, -204
+ -15, -29, 41, -188, -188, 69, -188, 74, 81, 38,
+ -188, -188, 230, -188, -188, 12, 96, 133, 269, 298,
+ 269, -29, 269, 93, 144, 149, -188, -188, 129, 156,
+ -188, -188, -188, -188, -188, -188, -188, -188, -188, 22,
+ 164, 230, -188, 147, 23, 12, 139, -188, 269, 269,
+ 269, -188, -188, -188, -188, -188, -188, -188, 402, 5,
+ 242, -188, 117, -188, 175, 136, 284, 157, 413, -188,
+ 269, 318, -188, 230, 269, 269, -29, 269, 269, -188,
+ -19, -188, -188, 126, 160, 140, 12, 58, 370, -188,
+ -188, 269, 269, 269, 269, 269, 269, 298, 269, 269,
+ 269, 269, 269, 269, 269, 269, 269, 269, -29, 269,
+ 269, 298, 269, 397, 185, -188, -188, 435, 89, 390,
+ 159, 435, 190, 421, 192, -188, 259, -188, 141, -188,
+ 171, -188, 181, -29, -29, -188, 58, 193, 58, 195,
+ -188, 5, 5, 5, 5, 5, 5, 167, 242, 242,
+ 242, -188, -188, -188, -188, -188, 115, 396, -188, 122,
+ 435, -188, 364, 199, 182, 397, 203, -188, -188, 269,
+ 194, 269, -188, 269, 108, -29, -19, 211, -29, -188,
+ 168, 212, -188, -188, -188, 174, -188, -29, 259, -188,
+ -188, 224, 224, -188, -188, -188, -188, 298, -188, -188,
+ -188, -188, -188, -188, 269, 298, -188, -188, 298, 435,
+ 269, 435, -188, -188, 131, 178, 61, 201, -29, 143,
+ -19, -188, -29, -188, 220, -27, 225, -188, 81, 223,
+ 227, -188, 358, 229, 231, 435, -188, -7, 243, -188,
+ -188, 259, -188, -188, -188, -29, 240, 11, -188, 244,
+ 264, 61, -188, -188, -188, 298, -188, -188, -19, -188,
+ 217, 258, 240, -188, -27, 61, 61, -188, -188, -188,
+ 259, -188, -188, -188, -188, -188
};
/* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
@@ -702,57 +703,58 @@ static const yytype_int16 yypact[] =
means the default is an error. */
static const yytype_uint8 yydefact[] =
{
- 0, 0, 0, 6, 128, 0, 1, 0, 0, 8,
- 3, 2, 0, 4, 59, 0, 17, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 131, 68, 0, 0,
- 65, 66, 67, 69, 70, 71, 72, 73, 74, 78,
- 80, 63, 7, 0, 0, 39, 133, 0, 0, 0,
- 11, 12, 13, 14, 129, 130, 120, 0, 105, 109,
- 115, 116, 15, 118, 0, 0, 0, 0, 96, 0,
- 0, 60, 0, 0, 0, 0, 0, 0, 0, 16,
- 19, 0, 0, 45, 0, 123, 122, 0, 0, 0,
+ 0, 0, 0, 6, 134, 0, 1, 0, 0, 8,
+ 3, 2, 0, 4, 65, 0, 19, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 137, 74, 0, 0,
+ 71, 72, 73, 75, 76, 77, 78, 79, 80, 84,
+ 86, 0, 7, 0, 0, 0, 43, 139, 0, 0,
+ 0, 13, 14, 15, 16, 135, 136, 126, 0, 111,
+ 115, 121, 122, 17, 124, 0, 0, 0, 0, 102,
+ 0, 0, 66, 0, 0, 0, 0, 0, 0, 69,
+ 0, 11, 18, 0, 0, 0, 0, 51, 0, 129,
+ 128, 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, 64, 61, 127, 0, 0, 0, 75, 0, 98,
- 0, 18, 0, 0, 38, 41, 37, 0, 0, 5,
- 45, 0, 45, 0, 121, 99, 100, 101, 102, 103,
- 104, 85, 106, 107, 108, 110, 112, 111, 113, 114,
- 0, 0, 125, 0, 86, 87, 0, 0, 0, 93,
- 0, 82, 79, 0, 0, 0, 81, 0, 10, 0,
- 0, 0, 0, 132, 0, 0, 21, 22, 23, 25,
- 24, 0, 0, 40, 52, 52, 43, 6, 44, 6,
- 0, 83, 117, 124, 119, 89, 90, 0, 0, 91,
- 92, 0, 126, 0, 77, 97, 9, 0, 0, 0,
- 0, 34, 0, 0, 20, 0, 36, 0, 0, 0,
- 49, 0, 0, 0, 84, 0, 0, 0, 76, 26,
- 0, 0, 32, 33, 0, 27, 30, 42, 0, 58,
- 0, 54, 0, 0, 0, 50, 46, 48, 0, 94,
- 95, 0, 28, 0, 0, 57, 51, 0, 0, 0,
- 47, 88, 29, 0, 35, 53, 55, 56, 31
+ 0, 0, 0, 0, 0, 70, 67, 133, 0, 0,
+ 0, 81, 0, 104, 0, 20, 0, 22, 0, 42,
+ 0, 41, 0, 0, 0, 5, 51, 0, 51, 0,
+ 127, 105, 106, 107, 108, 109, 110, 91, 112, 113,
+ 114, 116, 118, 117, 119, 120, 0, 0, 131, 0,
+ 92, 93, 0, 0, 0, 99, 0, 88, 85, 0,
+ 0, 0, 87, 0, 0, 0, 0, 0, 0, 138,
+ 0, 0, 25, 26, 27, 29, 28, 0, 0, 44,
+ 46, 58, 58, 49, 6, 50, 6, 0, 89, 123,
+ 130, 125, 95, 96, 0, 0, 97, 98, 0, 132,
+ 0, 83, 103, 9, 0, 0, 0, 0, 38, 0,
+ 0, 24, 0, 40, 0, 0, 0, 55, 0, 0,
+ 0, 90, 0, 0, 0, 82, 30, 0, 0, 36,
+ 37, 0, 31, 34, 48, 0, 64, 0, 60, 0,
+ 0, 0, 56, 52, 54, 0, 100, 101, 0, 32,
+ 0, 0, 63, 57, 0, 0, 0, 53, 94, 33,
+ 0, 39, 59, 61, 62, 35
};
/* YYPGOTO[NTERM-NUM]. */
static const yytype_int16 yypgoto[] =
{
- -204, -204, -204, -204, 227, -204, -204, 71, -65, -204,
- 161, -204, -181, -203, -204, -204, 29, -204, -153, -204,
- 117, -204, -57, -204, -204, -204, -204, 55, 70, -204,
- 3, -204, -204, 38, -6, 189, -16, 193, -204, -204,
- -204, -204, -204, -204, -204, -204, -204, 105, -204, -204,
- 115, -13, 298, 67, 1, -51, -1, -204, -204, -204,
- -204, -204
+ -188, -188, -188, -188, 249, -188, -188, -40, -23, -188,
+ -53, -188, -187, -174, -188, -188, 57, -188, -156, -188,
+ -74, -188, -62, -188, -188, -188, -188, 84, 91, -188,
+ 20, -188, -188, 59, -5, -34, -17, 215, -188, -188,
+ -188, -188, -188, -188, -188, -188, -188, 125, -188, -188,
+ 118, -12, 371, 6, 196, -38, -1, -188, -188, -188,
+ -188, 16
};
/* YYDEFGOTO[NTERM-NUM]. */
static const yytype_int16 yydefgoto[] =
{
- -1, 2, 3, 7, 221, 9, 16, 42, 56, 45,
- 79, 80, 175, 176, 177, 178, 210, 211, 123, 83,
- 124, 125, 129, 130, 131, 132, 133, 222, 219, 240,
- 241, 242, 243, 13, 27, 28, 29, 30, 31, 32,
- 33, 191, 34, 35, 36, 197, 37, 158, 159, 38,
- 118, 113, 58, 59, 60, 114, 61, 62, 63, 40,
- 180, 41
+ -1, 2, 3, 7, 228, 9, 16, 42, 57, 46,
+ 82, 83, 181, 182, 183, 184, 217, 218, 128, 87,
+ 129, 130, 135, 136, 137, 138, 139, 229, 226, 247,
+ 248, 249, 250, 13, 27, 28, 29, 30, 31, 32,
+ 33, 198, 34, 35, 36, 204, 37, 164, 165, 38,
+ 122, 117, 59, 60, 61, 118, 62, 63, 64, 40,
+ 186, 41
};
/* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
@@ -760,90 +762,104 @@ static const yytype_int16 yydefgoto[] =
number is the opposite. If YYTABLE_NINF, syntax error. */
static const yytype_int16 yytable[] =
{
- 5, 217, 14, 64, 1, 57, 231, 65, 73, 67,
- 74, 39, 75, 120, 43, 256, 207, 4, 39, 212,
- 66, 257, 87, 88, 89, 90, 91, 92, 102, 238,
- 103, 76, 104, 6, 84, 87, 88, 89, 90, 91,
- 92, 260, 10, 81, 157, 94, 95, 107, 4, 85,
- 86, 150, 96, 254, 153, 266, 267, 174, 212, 11,
- 248, 115, 162, 117, 119, 239, 163, 12, 192, 39,
- 110, 39, 163, 186, 116, 188, 194, 141, 15, 81,
- 163, 126, 268, 229, 46, 255, 44, 181, 68, 17,
- 151, 155, 39, 154, 157, 156, 127, 128, 145, 146,
- 147, 148, 149, 152, 239, 208, 39, 69, 160, 87,
- 88, 89, 90, 91, 92, 251, 70, 174, 12, -62,
- 72, 179, 181, 182, 126, 18, 184, 185, 19, 71,
- 195, 196, 20, 78, 21, 22, 23, 24, 181, 234,
- 25, 77, 82, 4, 174, 105, 108, 26, 235, 122,
- 202, 106, 204, 161, 119, 50, 51, 52, 160, 53,
- 54, 142, 143, 144, 166, 252, 165, 43, 126, 174,
- 190, 126, 168, 187, 224, 189, 198, 199, 201, 174,
- 216, 179, 226, 203, 225, 227, 262, 209, 213, 39,
- 228, 214, 215, 174, 174, 218, 230, 39, 174, 232,
- 39, 237, 134, 97, 98, 99, 100, 101, 179, 244,
- 126, 246, 247, 249, 236, 14, 169, 126, 87, 88,
- 89, 90, 91, 92, 250, 170, 169, 253, 181, 263,
- 8, 258, 261, 179, 259, 170, 47, 126, 264, 206,
- 233, 121, 183, 179, 223, 48, 171, 39, 172, 50,
- 51, 52, 49, 53, 54, 220, 126, 179, 179, 245,
- 265, 112, 179, 111, 200, 50, 51, 52, 4, 53,
- 54, 0, 0, 173, 0, 50, 51, 52, 4, 53,
- 54, 167, 205, 173, 0, 50, 51, 52, 4, 53,
- 54, 55, 12, 87, 88, 89, 90, 91, 92, 18,
- 0, 0, 19, 0, 0, 0, 20, 0, 21, 22,
- 23, 24, 12, 0, 25, 0, 0, 4, 0, 18,
- 0, 26, 19, 0, 0, 0, 20, 0, 21, 22,
- 23, 24, 164, 0, 0, 0, 0, 4, 193, 0,
- 0, 26, 0, 0, 0, 0, 87, 88, 89, 90,
- 91, 92, 87, 88, 89, 90, 91, 92, 87, 88,
- 89, 90, 91, 92, 87, 88, 89, 90, 91, 92,
- 50, 51, 52, 4, 53, 54, 93, 0, 109, 87,
- 88, 89, 90, 91, 92, 135, 136, 137, 138, 139,
- 140
+ 5, 224, 65, 14, 81, 258, 58, 79, 66, 245,
+ 68, 39, 1, 17, 43, 263, 98, 99, 39, 214,
+ 67, 264, 219, 100, 17, 74, 4, 75, 4, 76,
+ 125, 44, 127, 51, 52, 53, 88, 54, 55, 116,
+ 39, 6, 238, 43, 84, 51, 52, 53, 77, 54,
+ 55, -12, -12, -12, 261, -12, 189, 124, 190, -12,
+ 44, 85, 219, 119, 175, 121, 123, 4, 156, 246,
+ 39, 159, 39, 176, 193, 120, 195, 267, 4, 10,
+ 147, 11, 84, 275, 84, 131, 133, 134, 15, 262,
+ 163, 273, 274, 168, 161, 157, 39, 169, 160, 85,
+ 162, 85, 132, 180, 148, 149, 150, 158, 246, 17,
+ 39, 12, 166, 51, 52, 53, 4, 54, 55, 199,
+ 106, 179, 107, 169, 108, 185, 201, 17, 45, 131,
+ 169, 131, 191, 192, 213, 236, -10, -10, -10, 187,
+ -10, 17, 163, 47, -10, 69, 132, 70, 132, 187,
+ 188, 187, 241, 215, -21, -21, -21, 209, 71, 211,
+ 72, 123, -21, 4, 166, 180, 73, 78, -23, -23,
+ -23, 80, 17, 43, 131, 86, -23, 131, 109, 110,
+ 231, 4, 17, 112, 126, 171, 223, 185, 233, 167,
+ 44, 234, 232, 180, 172, 4, 39, 242, 235, -45,
+ -45, -45, 174, 194, 39, 196, 197, 39, 205, -47,
+ -47, -47, 208, 206, 259, 185, 216, 131, 180, 220,
+ 210, 243, 221, 14, 131, 222, 4, 225, 180, 237,
+ 244, 17, 239, 253, 251, 269, 4, 254, 268, 256,
+ 185, 257, 180, 180, 131, 89, 90, 180, 187, 260,
+ 185, 270, 8, 265, 39, 101, 102, 103, 104, 105,
+ 12, -68, 175, 131, 185, 185, 114, 18, 271, 185,
+ 19, 176, 48, 266, 20, 240, 21, 22, 23, 24,
+ 230, 49, 25, 227, 272, 4, 115, 252, 50, 26,
+ 207, 212, 177, 0, 178, 0, 0, 151, 152, 153,
+ 154, 155, 0, 0, 91, 92, 93, 94, 95, 96,
+ 0, 51, 52, 53, 4, 54, 55, 0, 0, 179,
+ 0, 51, 52, 53, 4, 54, 55, 56, 12, 111,
+ 0, 0, 0, 0, 0, 18, 0, 0, 19, 0,
+ 0, 0, 20, 0, 21, 22, 23, 24, 12, 0,
+ 25, 0, 0, 4, 0, 18, 0, 26, 19, 0,
+ 0, 0, 20, 0, 21, 22, 23, 24, 0, 0,
+ 0, 0, 0, 4, 140, 0, 0, 26, 91, 92,
+ 93, 94, 95, 96, 91, 92, 93, 94, 95, 96,
+ 91, 92, 93, 94, 95, 96, 170, 0, 0, 0,
+ 0, 0, 200, 255, 0, 202, 203, 0, 0, 0,
+ 91, 92, 93, 94, 95, 96, 91, 92, 93, 94,
+ 95, 96, 91, 92, 93, 94, 95, 96, 0, 173,
+ 0, 0, 0, 91, 92, 93, 94, 95, 96, 0,
+ 97, 91, 92, 93, 94, 95, 96, 113, 0, 51,
+ 52, 53, 4, 54, 55, 91, 92, 93, 94, 95,
+ 96, 0, 141, 142, 143, 144, 145, 146
};
static const yytype_int16 yycheck[] =
{
- 1, 182, 8, 19, 27, 18, 209, 20, 3, 22,
- 5, 12, 7, 78, 15, 4, 169, 55, 19, 172,
- 21, 10, 20, 21, 22, 23, 24, 25, 3, 36,
- 5, 26, 7, 0, 47, 20, 21, 22, 23, 24,
- 25, 244, 10, 44, 109, 11, 12, 45, 55, 48,
- 49, 102, 18, 234, 105, 258, 259, 122, 211, 7,
- 45, 74, 4, 76, 77, 218, 8, 30, 4, 70,
- 69, 72, 8, 130, 75, 132, 4, 93, 50, 80,
- 8, 82, 263, 4, 10, 238, 32, 8, 52, 1,
- 103, 107, 93, 106, 159, 108, 28, 29, 97, 98,
- 99, 100, 101, 104, 257, 170, 107, 3, 109, 20,
- 21, 22, 23, 24, 25, 12, 9, 182, 30, 31,
- 10, 122, 8, 9, 125, 37, 127, 128, 40, 31,
- 41, 42, 44, 24, 46, 47, 48, 49, 8, 9,
- 52, 3, 36, 55, 209, 3, 26, 59, 213, 24,
- 163, 43, 165, 4, 167, 52, 53, 54, 159, 56,
- 57, 94, 95, 96, 4, 230, 26, 168, 169, 234,
- 39, 172, 10, 10, 190, 10, 9, 31, 9, 244,
- 181, 182, 198, 26, 197, 201, 251, 5, 51, 190,
- 203, 10, 51, 258, 259, 3, 51, 198, 263, 31,
- 201, 10, 4, 13, 14, 15, 16, 17, 209, 9,
- 211, 10, 10, 10, 215, 221, 3, 218, 20, 21,
- 22, 23, 24, 25, 10, 12, 3, 6, 8, 34,
- 3, 9, 248, 234, 9, 12, 3, 238, 10, 168,
- 211, 80, 125, 244, 189, 12, 33, 248, 35, 52,
- 53, 54, 19, 56, 57, 185, 257, 258, 259, 221,
- 257, 72, 263, 70, 159, 52, 53, 54, 55, 56,
- 57, -1, -1, 60, -1, 52, 53, 54, 55, 56,
- 57, 8, 167, 60, -1, 52, 53, 54, 55, 56,
- 57, 58, 30, 20, 21, 22, 23, 24, 25, 37,
- -1, -1, 40, -1, -1, -1, 44, -1, 46, 47,
- 48, 49, 30, -1, 52, -1, -1, 55, -1, 37,
- -1, 59, 40, -1, -1, -1, 44, -1, 46, 47,
- 48, 49, 6, -1, -1, -1, -1, 55, 6, -1,
- -1, 59, -1, -1, -1, -1, 20, 21, 22, 23,
- 24, 25, 20, 21, 22, 23, 24, 25, 20, 21,
+ 1, 188, 19, 8, 44, 12, 18, 41, 20, 36,
+ 22, 12, 27, 1, 15, 4, 11, 12, 19, 175,
+ 21, 10, 178, 18, 1, 3, 55, 5, 55, 7,
+ 83, 15, 85, 52, 53, 54, 48, 56, 57, 73,
+ 41, 0, 216, 44, 45, 52, 53, 54, 26, 56,
+ 57, 28, 29, 30, 241, 32, 130, 80, 132, 36,
+ 44, 45, 218, 75, 3, 77, 78, 55, 106, 225,
+ 71, 109, 73, 12, 136, 76, 138, 251, 55, 10,
+ 97, 7, 83, 270, 85, 86, 28, 29, 50, 245,
+ 113, 265, 266, 4, 111, 107, 97, 8, 110, 83,
+ 112, 85, 86, 126, 98, 99, 100, 108, 264, 1,
+ 111, 30, 113, 52, 53, 54, 55, 56, 57, 4,
+ 3, 60, 5, 8, 7, 126, 4, 1, 32, 130,
+ 8, 132, 133, 134, 174, 4, 28, 29, 30, 8,
+ 32, 1, 165, 10, 36, 52, 130, 3, 132, 8,
+ 9, 8, 9, 176, 28, 29, 30, 169, 9, 171,
+ 31, 173, 36, 55, 165, 188, 10, 3, 28, 29,
+ 30, 24, 1, 174, 175, 36, 36, 178, 3, 43,
+ 197, 55, 1, 26, 24, 26, 187, 188, 205, 4,
+ 174, 208, 204, 216, 4, 55, 197, 220, 210, 28,
+ 29, 30, 10, 10, 205, 10, 39, 208, 9, 28,
+ 29, 30, 9, 31, 237, 216, 5, 218, 241, 51,
+ 26, 222, 10, 228, 225, 51, 55, 3, 251, 51,
+ 10, 1, 31, 10, 9, 258, 55, 10, 255, 10,
+ 241, 10, 265, 266, 245, 49, 50, 270, 8, 6,
+ 251, 34, 3, 9, 255, 13, 14, 15, 16, 17,
+ 30, 31, 3, 264, 265, 266, 70, 37, 10, 270,
+ 40, 12, 3, 9, 44, 218, 46, 47, 48, 49,
+ 196, 12, 52, 192, 264, 55, 71, 228, 19, 59,
+ 165, 173, 33, -1, 35, -1, -1, 101, 102, 103,
+ 104, 105, -1, -1, 20, 21, 22, 23, 24, 25,
+ -1, 52, 53, 54, 55, 56, 57, -1, -1, 60,
+ -1, 52, 53, 54, 55, 56, 57, 58, 30, 45,
+ -1, -1, -1, -1, -1, 37, -1, -1, 40, -1,
+ -1, -1, 44, -1, 46, 47, 48, 49, 30, -1,
+ 52, -1, -1, 55, -1, 37, -1, 59, 40, -1,
+ -1, -1, 44, -1, 46, 47, 48, 49, -1, -1,
+ -1, -1, -1, 55, 4, -1, -1, 59, 20, 21,
22, 23, 24, 25, 20, 21, 22, 23, 24, 25,
- 52, 53, 54, 55, 56, 57, 38, -1, 34, 20,
- 21, 22, 23, 24, 25, 87, 88, 89, 90, 91,
- 92
+ 20, 21, 22, 23, 24, 25, 6, -1, -1, -1,
+ -1, -1, 6, 45, -1, 41, 42, -1, -1, -1,
+ 20, 21, 22, 23, 24, 25, 20, 21, 22, 23,
+ 24, 25, 20, 21, 22, 23, 24, 25, -1, 8,
+ -1, -1, -1, 20, 21, 22, 23, 24, 25, -1,
+ 38, 20, 21, 22, 23, 24, 25, 34, -1, 52,
+ 53, 54, 55, 56, 57, 20, 21, 22, 23, 24,
+ 25, -1, 91, 92, 93, 94, 95, 96
};
/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
@@ -854,67 +870,68 @@ static const yytype_uint8 yystos[] =
10, 7, 30, 94, 95, 50, 67, 1, 37, 40,
44, 46, 47, 48, 49, 52, 59, 95, 96, 97,
98, 99, 100, 101, 103, 104, 105, 107, 110, 117,
- 120, 122, 68, 117, 32, 70, 10, 3, 12, 19,
- 52, 53, 54, 56, 57, 58, 69, 112, 113, 114,
- 115, 117, 118, 119, 97, 112, 117, 112, 52, 3,
- 9, 31, 10, 3, 5, 7, 26, 3, 24, 71,
- 72, 117, 36, 80, 112, 115, 115, 20, 21, 22,
- 23, 24, 25, 38, 11, 12, 18, 13, 14, 15,
- 16, 17, 3, 5, 7, 3, 43, 45, 26, 34,
- 115, 98, 96, 112, 116, 112, 117, 112, 111, 112,
- 69, 71, 24, 79, 81, 82, 117, 28, 29, 83,
- 84, 85, 86, 87, 4, 113, 113, 113, 113, 113,
- 113, 97, 114, 114, 114, 115, 115, 115, 115, 115,
- 116, 112, 117, 116, 112, 97, 112, 69, 108, 109,
- 117, 4, 4, 8, 6, 26, 4, 8, 10, 3,
- 12, 33, 35, 60, 69, 73, 74, 75, 76, 117,
- 121, 8, 9, 81, 117, 117, 83, 10, 83, 10,
- 39, 102, 4, 6, 4, 41, 42, 106, 9, 31,
- 108, 9, 112, 26, 112, 111, 68, 79, 69, 5,
- 77, 78, 79, 51, 10, 51, 117, 73, 3, 89,
- 89, 65, 88, 88, 97, 112, 97, 97, 112, 4,
- 51, 74, 31, 77, 9, 69, 117, 10, 36, 79,
- 90, 91, 92, 93, 9, 94, 10, 10, 45, 10,
- 10, 12, 69, 6, 73, 79, 4, 10, 9, 9,
- 74, 97, 69, 34, 10, 91, 74, 74, 73
+ 120, 122, 68, 117, 122, 32, 70, 10, 3, 12,
+ 19, 52, 53, 54, 56, 57, 58, 69, 112, 113,
+ 114, 115, 117, 118, 119, 97, 112, 117, 112, 52,
+ 3, 9, 31, 10, 3, 5, 7, 26, 3, 96,
+ 24, 68, 71, 72, 117, 122, 36, 80, 112, 115,
+ 115, 20, 21, 22, 23, 24, 25, 38, 11, 12,
+ 18, 13, 14, 15, 16, 17, 3, 5, 7, 3,
+ 43, 45, 26, 34, 115, 98, 96, 112, 116, 112,
+ 117, 112, 111, 112, 69, 71, 24, 71, 79, 81,
+ 82, 117, 122, 28, 29, 83, 84, 85, 86, 87,
+ 4, 113, 113, 113, 113, 113, 113, 97, 114, 114,
+ 114, 115, 115, 115, 115, 115, 116, 112, 117, 116,
+ 112, 97, 112, 69, 108, 109, 117, 4, 4, 8,
+ 6, 26, 4, 8, 10, 3, 12, 33, 35, 60,
+ 69, 73, 74, 75, 76, 117, 121, 8, 9, 81,
+ 81, 117, 117, 83, 10, 83, 10, 39, 102, 4,
+ 6, 4, 41, 42, 106, 9, 31, 108, 9, 112,
+ 26, 112, 111, 68, 79, 69, 5, 77, 78, 79,
+ 51, 10, 51, 117, 73, 3, 89, 89, 65, 88,
+ 88, 97, 112, 97, 97, 112, 4, 51, 74, 31,
+ 77, 9, 69, 117, 10, 36, 79, 90, 91, 92,
+ 93, 9, 94, 10, 10, 45, 10, 10, 12, 69,
+ 6, 73, 79, 4, 10, 9, 9, 74, 97, 69,
+ 34, 10, 91, 74, 74, 73
};
/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
static const yytype_uint8 yyr1[] =
{
0, 61, 62, 63, 64, 65, 66, 67, 67, 68,
- 68, 69, 69, 69, 69, 69, 70, 70, 71, 71,
- 72, 73, 73, 73, 74, 74, 74, 74, 74, 74,
- 74, 75, 76, 77, 77, 78, 79, 79, 80, 80,
- 81, 81, 82, 83, 83, 83, 84, 85, 86, 87,
- 88, 89, 89, 90, 90, 91, 91, 92, 93, 94,
- 95, 96, 96, 96, 97, 97, 98, 98, 98, 98,
- 98, 98, 98, 98, 98, 99, 99, 99, 100, 100,
- 100, 100, 100, 101, 102, 102, 103, 104, 105, 106,
- 106, 107, 108, 108, 109, 109, 110, 111, 111, 112,
- 112, 112, 112, 112, 112, 112, 113, 113, 113, 113,
- 114, 114, 114, 114, 114, 114, 115, 115, 115, 115,
- 115, 115, 115, 115, 115, 115, 116, 116, 117, 118,
- 119, 120, 121, 122
+ 68, 68, 68, 69, 69, 69, 69, 69, 70, 70,
+ 71, 71, 71, 71, 72, 73, 73, 73, 74, 74,
+ 74, 74, 74, 74, 74, 75, 76, 77, 77, 78,
+ 79, 79, 80, 80, 81, 81, 81, 81, 82, 83,
+ 83, 83, 84, 85, 86, 87, 88, 89, 89, 90,
+ 90, 91, 91, 92, 93, 94, 95, 96, 96, 96,
+ 97, 97, 98, 98, 98, 98, 98, 98, 98, 98,
+ 98, 99, 99, 99, 100, 100, 100, 100, 100, 101,
+ 102, 102, 103, 104, 105, 106, 106, 107, 108, 108,
+ 109, 109, 110, 111, 111, 112, 112, 112, 112, 112,
+ 112, 112, 113, 113, 113, 113, 114, 114, 114, 114,
+ 114, 114, 115, 115, 115, 115, 115, 115, 115, 115,
+ 115, 115, 116, 116, 117, 118, 119, 120, 121, 122
};
/* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
static const yytype_uint8 yyr2[] =
{
0, 2, 3, 3, 2, 5, 0, 2, 0, 5,
- 4, 1, 1, 1, 1, 1, 2, 0, 2, 1,
- 4, 1, 1, 1, 1, 1, 3, 3, 4, 5,
- 3, 6, 3, 2, 1, 4, 3, 1, 2, 0,
- 2, 1, 4, 2, 2, 0, 4, 5, 4, 3,
- 2, 3, 0, 3, 1, 3, 3, 2, 1, 1,
- 3, 3, 0, 1, 3, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 3, 6, 5, 1, 4,
- 1, 4, 4, 5, 2, 0, 4, 4, 8, 1,
- 1, 5, 2, 1, 4, 4, 2, 3, 1, 3,
- 3, 3, 3, 3, 3, 1, 3, 3, 3, 1,
- 3, 3, 3, 3, 3, 1, 1, 4, 1, 4,
- 1, 3, 2, 2, 4, 3, 3, 1, 1, 1,
- 1, 1, 1, 2
+ 4, 2, 1, 1, 1, 1, 1, 1, 2, 0,
+ 2, 1, 2, 1, 4, 1, 1, 1, 1, 1,
+ 3, 3, 4, 5, 3, 6, 3, 2, 1, 4,
+ 3, 1, 2, 0, 2, 1, 2, 1, 4, 2,
+ 2, 0, 4, 5, 4, 3, 2, 3, 0, 3,
+ 1, 3, 3, 2, 1, 1, 3, 3, 0, 2,
+ 3, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 3, 6, 5, 1, 4, 1, 4, 4, 5,
+ 2, 0, 4, 4, 8, 1, 1, 5, 2, 1,
+ 4, 4, 2, 3, 1, 3, 3, 3, 3, 3,
+ 3, 1, 3, 3, 3, 1, 3, 3, 3, 3,
+ 3, 1, 1, 4, 1, 4, 1, 3, 2, 2,
+ 4, 3, 3, 1, 1, 1, 1, 1, 1, 2
};
@@ -1592,20 +1609,20 @@ yyparse (void)
{
case 2:
#line 81 "Pascal.y" /* yacc.c:1646 */
- {/*set root for abstract syntax tree*/ A_synTreeRoot = (yyvsp[-1].exp); /*printf("Program parsed.\n");*/}
-#line 1597 "y.tab.c" /* yacc.c:1646 */
+ {/*set root for abstract syntax tree*/ A_synTreeRoot = (yyvsp[-1].exp); }
+#line 1614 "y.tab.c" /* yacc.c:1646 */
break;
case 3:
#line 82 "Pascal.y" /* yacc.c:1646 */
- {/*printf("Program head.\n");*/}
-#line 1603 "y.tab.c" /* yacc.c:1646 */
+ {}
+#line 1620 "y.tab.c" /* yacc.c:1646 */
break;
case 4:
#line 83 "Pascal.y" /* yacc.c:1646 */
{/*head:declaration with type A_decList, body:expression with type A_exp*/ (yyval.exp) = A_LetExp(EM_tokPos, (yyvsp[-1].declist), (yyvsp[0].exp));}
-#line 1609 "y.tab.c" /* yacc.c:1646 */
+#line 1626 "y.tab.c" /* yacc.c:1646 */
break;
case 5:
@@ -1623,789 +1640,825 @@ yyparse (void)
A_linkDecList(decList, A_DecList(A_FunctionDec(EM_tokPos, (yyvsp[0].fundeclist)), NULL));
(yyval.declist) = decList->tail;
}
-#line 1627 "y.tab.c" /* yacc.c:1646 */
+#line 1644 "y.tab.c" /* yacc.c:1646 */
break;
case 6:
#line 98 "Pascal.y" /* yacc.c:1646 */
{/*label part is empty in pascal*/ (yyval.declist) = NULL;}
-#line 1633 "y.tab.c" /* yacc.c:1646 */
+#line 1650 "y.tab.c" /* yacc.c:1646 */
break;
case 7:
#line 101 "Pascal.y" /* yacc.c:1646 */
{/*const declaration part*/ (yyval.declist) = (yyvsp[0].declist);}
-#line 1639 "y.tab.c" /* yacc.c:1646 */
+#line 1656 "y.tab.c" /* yacc.c:1646 */
break;
case 8:
#line 102 "Pascal.y" /* yacc.c:1646 */
{/*no const declaration*/ (yyval.declist) = NULL;}
-#line 1645 "y.tab.c" /* yacc.c:1646 */
+#line 1662 "y.tab.c" /* yacc.c:1646 */
break;
case 9:
#line 103 "Pascal.y" /* yacc.c:1646 */
{/*const declaration list*/ (yyval.declist) = A_DecList(A_ConstDec(EM_tokPos, (yyvsp[-4].sym), (yyvsp[-2].exp)),(yyvsp[0].declist));}
-#line 1651 "y.tab.c" /* yacc.c:1646 */
+#line 1668 "y.tab.c" /* yacc.c:1646 */
break;
case 10:
#line 104 "Pascal.y" /* yacc.c:1646 */
{/*first one in list*/ (yyval.declist) = A_DecList(A_ConstDec(EM_tokPos, (yyvsp[-3].sym), (yyvsp[-1].exp)), NULL);}
-#line 1657 "y.tab.c" /* yacc.c:1646 */
+#line 1674 "y.tab.c" /* yacc.c:1646 */
break;
case 11:
#line 105 "Pascal.y" /* yacc.c:1646 */
- {/*integer value*/ (yyval.exp) = A_IntExp(EM_tokPos, (yyvsp[0].ival));}
-#line 1663 "y.tab.c" /* yacc.c:1646 */
+ {/*run into error*/ (yyval.declist) = (yyvsp[0].declist);}
+#line 1680 "y.tab.c" /* yacc.c:1646 */
break;
case 12:
#line 106 "Pascal.y" /* yacc.c:1646 */
- {/*real value*/ (yyval.exp) = A_RealExp(EM_tokPos, (yyvsp[0].rval));}
-#line 1669 "y.tab.c" /* yacc.c:1646 */
+ {(yyval.declist) = NULL;}
+#line 1686 "y.tab.c" /* yacc.c:1646 */
break;
case 13:
#line 107 "Pascal.y" /* yacc.c:1646 */
- {/*char value*/ (yyval.exp) = A_CharExp(EM_tokPos, (yyvsp[0].cval));}
-#line 1675 "y.tab.c" /* yacc.c:1646 */
+ {/*integer value*/ (yyval.exp) = A_IntExp(EM_tokPos, (yyvsp[0].ival));}
+#line 1692 "y.tab.c" /* yacc.c:1646 */
break;
case 14:
#line 108 "Pascal.y" /* yacc.c:1646 */
- {/*string value*/ (yyval.exp) = A_StringExp(EM_tokPos, (yyvsp[0].sval));}
-#line 1681 "y.tab.c" /* yacc.c:1646 */
+ {/*real value*/ (yyval.exp) = A_RealExp(EM_tokPos, (yyvsp[0].rval));}
+#line 1698 "y.tab.c" /* yacc.c:1646 */
break;
case 15:
#line 109 "Pascal.y" /* yacc.c:1646 */
- {/*system const value*/ /*$$ = A_SysConstExp(EM_tokPos, $1);*/}
-#line 1687 "y.tab.c" /* yacc.c:1646 */
+ {/*char value*/ (yyval.exp) = A_CharExp(EM_tokPos, (yyvsp[0].cval));}
+#line 1704 "y.tab.c" /* yacc.c:1646 */
break;
case 16:
-#line 112 "Pascal.y" /* yacc.c:1646 */
- {/*type declaration part*/ (yyval.declist) = A_DecList(A_TypeDec(EM_tokPos, (yyvsp[0].nametylist)), NULL);}
-#line 1693 "y.tab.c" /* yacc.c:1646 */
+#line 110 "Pascal.y" /* yacc.c:1646 */
+ {/*string value*/ (yyval.exp) = A_StringExp(EM_tokPos, (yyvsp[0].sval));}
+#line 1710 "y.tab.c" /* yacc.c:1646 */
break;
case 17:
-#line 113 "Pascal.y" /* yacc.c:1646 */
- {/*no type declaration*/ (yyval.declist) = NULL;}
-#line 1699 "y.tab.c" /* yacc.c:1646 */
+#line 111 "Pascal.y" /* yacc.c:1646 */
+ {/*system const value*/ /*$$ = A_SysConstExp(EM_tokPos, $1);*/}
+#line 1716 "y.tab.c" /* yacc.c:1646 */
break;
case 18:
#line 114 "Pascal.y" /* yacc.c:1646 */
- {/*type declaration list*/ (yyval.nametylist) = A_NametyList((yyvsp[-1].namety), (yyvsp[0].nametylist));}
-#line 1705 "y.tab.c" /* yacc.c:1646 */
+ {/*type declaration part*/ (yyval.declist) = A_DecList(A_TypeDec(EM_tokPos, (yyvsp[0].nametylist)), NULL);}
+#line 1722 "y.tab.c" /* yacc.c:1646 */
break;
case 19:
#line 115 "Pascal.y" /* yacc.c:1646 */
- {/*last type definition, tail points to NULL*/(yyval.nametylist) = A_NametyList((yyvsp[0].namety), NULL);}
-#line 1711 "y.tab.c" /* yacc.c:1646 */
+ {/*no type declaration*/ (yyval.declist) = NULL;}
+#line 1728 "y.tab.c" /* yacc.c:1646 */
break;
case 20:
#line 116 "Pascal.y" /* yacc.c:1646 */
- {/*type declaration*/(yyval.namety) =A_Namety((yyvsp[-3].sym), (yyvsp[-1].ty));}
-#line 1717 "y.tab.c" /* yacc.c:1646 */
+ {/*type declaration list*/ (yyval.nametylist) = A_NametyList((yyvsp[-1].namety), (yyvsp[0].nametylist));}
+#line 1734 "y.tab.c" /* yacc.c:1646 */
break;
case 21:
#line 117 "Pascal.y" /* yacc.c:1646 */
- {/*simple type*/ (yyval.ty) = (yyvsp[0].ty);}
-#line 1723 "y.tab.c" /* yacc.c:1646 */
+ {/*last type definition, tail points to NULL*/(yyval.nametylist) = A_NametyList((yyvsp[0].namety), NULL);}
+#line 1740 "y.tab.c" /* yacc.c:1646 */
break;
case 22:
#line 118 "Pascal.y" /* yacc.c:1646 */
- {/*array type*/ (yyval.ty) = (yyvsp[0].ty);}
-#line 1729 "y.tab.c" /* yacc.c:1646 */
+ {/*run into error*/ (yyval.nametylist) = (yyvsp[0].nametylist);}
+#line 1746 "y.tab.c" /* yacc.c:1646 */
break;
case 23:
#line 119 "Pascal.y" /* yacc.c:1646 */
- {/*record type*/ (yyval.ty) = (yyvsp[0].ty);}
-#line 1735 "y.tab.c" /* yacc.c:1646 */
+ {(yyval.nametylist) = NULL;}
+#line 1752 "y.tab.c" /* yacc.c:1646 */
break;
case 24:
#line 120 "Pascal.y" /* yacc.c:1646 */
- {/*system defined type*/ (yyval.ty) = A_NameTy(EM_tokPos, (yyvsp[0].sym));}
-#line 1741 "y.tab.c" /* yacc.c:1646 */
+ {/*type declaration*/(yyval.namety) =A_Namety((yyvsp[-3].sym), (yyvsp[-1].ty));}
+#line 1758 "y.tab.c" /* yacc.c:1646 */
break;
case 25:
#line 121 "Pascal.y" /* yacc.c:1646 */
- {/*self define simple type*/ (yyval.ty) = A_NameTy(EM_tokPos, (yyvsp[0].sym));}
-#line 1747 "y.tab.c" /* yacc.c:1646 */
+ {/*simple type*/ (yyval.ty) = (yyvsp[0].ty);}
+#line 1764 "y.tab.c" /* yacc.c:1646 */
break;
case 26:
#line 122 "Pascal.y" /* yacc.c:1646 */
- {/*enum type*/ (yyval.ty) = A_EnumType(EM_tokPos, (yyvsp[-1].fieldlist));}
-#line 1753 "y.tab.c" /* yacc.c:1646 */
+ {/*array type*/ (yyval.ty) = (yyvsp[0].ty);}
+#line 1770 "y.tab.c" /* yacc.c:1646 */
break;
case 27:
#line 123 "Pascal.y" /* yacc.c:1646 */
- {/*subrange type*/ (yyval.ty) = A_RangeTy(EM_tokPos, (yyvsp[-2].exp), (yyvsp[0].exp));}
-#line 1759 "y.tab.c" /* yacc.c:1646 */
+ {/*record type*/ (yyval.ty) = (yyvsp[0].ty);}
+#line 1776 "y.tab.c" /* yacc.c:1646 */
break;
case 28:
#line 124 "Pascal.y" /* yacc.c:1646 */
- {/*subrange type*/ A_RangeTy(EM_tokPos, A_OpExp(EM_tokPos, A_minusOp, A_IntExp(EM_tokPos, 0), (yyvsp[-2].exp)), (yyvsp[0].exp));}
-#line 1765 "y.tab.c" /* yacc.c:1646 */
+ {/*system defined type*/ (yyval.ty) = A_NameTy(EM_tokPos, (yyvsp[0].sym));}
+#line 1782 "y.tab.c" /* yacc.c:1646 */
break;
case 29:
#line 125 "Pascal.y" /* yacc.c:1646 */
- {/*subrange type*/ A_RangeTy(EM_tokPos, A_OpExp(EM_tokPos, A_minusOp, A_IntExp(EM_tokPos, 0), (yyvsp[-3].exp)), A_OpExp(EM_tokPos, A_minusOp, A_IntExp(EM_tokPos, 0), (yyvsp[0].exp)));}
-#line 1771 "y.tab.c" /* yacc.c:1646 */
+ {/*self define simple type*/ (yyval.ty) = A_NameTy(EM_tokPos, (yyvsp[0].sym));}
+#line 1788 "y.tab.c" /* yacc.c:1646 */
break;
case 30:
#line 126 "Pascal.y" /* yacc.c:1646 */
- {/*subrange type*/ A_RangeTy(EM_tokPos, A_VarExp(EM_tokPos, A_SimpleVar(EM_tokPos, (yyvsp[-2].sym))), A_VarExp(EM_tokPos, A_SimpleVar(EM_tokPos, (yyvsp[0].sym))));}
-#line 1777 "y.tab.c" /* yacc.c:1646 */
+ {/*enum type*/ (yyval.ty) = A_EnumType(EM_tokPos, (yyvsp[-1].fieldlist));}
+#line 1794 "y.tab.c" /* yacc.c:1646 */
break;
case 31:
#line 127 "Pascal.y" /* yacc.c:1646 */
- {/*array type, simple_type_dec is range of array, type_dec is actual type of array element*/ (yyval.ty) = A_ArrayTy(EM_tokPos, (yyvsp[-3].ty), (yyvsp[0].ty)->u.name);}
-#line 1783 "y.tab.c" /* yacc.c:1646 */
+ {/*subrange type*/ (yyval.ty) = A_RangeTy(EM_tokPos, (yyvsp[-2].exp), (yyvsp[0].exp));}
+#line 1800 "y.tab.c" /* yacc.c:1646 */
break;
case 32:
#line 128 "Pascal.y" /* yacc.c:1646 */
- {/*record type*/ (yyval.ty) = A_RecordTy(EM_tokPos, (yyvsp[-1].fieldlist));}
-#line 1789 "y.tab.c" /* yacc.c:1646 */
+ {/*subrange type*/ A_RangeTy(EM_tokPos, A_OpExp(EM_tokPos, A_minusOp, A_IntExp(EM_tokPos, 0), (yyvsp[-2].exp)), (yyvsp[0].exp));}
+#line 1806 "y.tab.c" /* yacc.c:1646 */
break;
case 33:
-#line 130 "Pascal.y" /* yacc.c:1646 */
- {/*link parts of fieldlists*/ (yyval.fieldlist) = A_linkFieldList((yyvsp[-1].fieldlist), (yyvsp[0].fieldlist)); }
-#line 1795 "y.tab.c" /* yacc.c:1646 */
+#line 129 "Pascal.y" /* yacc.c:1646 */
+ {/*subrange type*/ A_RangeTy(EM_tokPos, A_OpExp(EM_tokPos, A_minusOp, A_IntExp(EM_tokPos, 0), (yyvsp[-3].exp)), A_OpExp(EM_tokPos, A_minusOp, A_IntExp(EM_tokPos, 0), (yyvsp[0].exp)));}
+#line 1812 "y.tab.c" /* yacc.c:1646 */
break;
case 34:
-#line 131 "Pascal.y" /* yacc.c:1646 */
- {(yyval.fieldlist) = (yyvsp[0].fieldlist);}
-#line 1801 "y.tab.c" /* yacc.c:1646 */
+#line 130 "Pascal.y" /* yacc.c:1646 */
+ {/*subrange type*/ A_RangeTy(EM_tokPos, A_VarExp(EM_tokPos, A_SimpleVar(EM_tokPos, (yyvsp[-2].sym))), A_VarExp(EM_tokPos, A_SimpleVar(EM_tokPos, (yyvsp[0].sym))));}
+#line 1818 "y.tab.c" /* yacc.c:1646 */
break;
case 35:
-#line 132 "Pascal.y" /* yacc.c:1646 */
- { /*set type of namelist*/(yyval.fieldlist) = A_setFieldListType((yyvsp[-3].fieldlist), (yyvsp[-1].ty));}
-#line 1807 "y.tab.c" /* yacc.c:1646 */
+#line 131 "Pascal.y" /* yacc.c:1646 */
+ {/*array type, simple_type_dec is range of array, type_dec is actual type of array element*/ (yyval.ty) = A_ArrayTy(EM_tokPos, (yyvsp[-3].ty), (yyvsp[0].ty));}
+#line 1824 "y.tab.c" /* yacc.c:1646 */
break;
case 36:
-#line 133 "Pascal.y" /* yacc.c:1646 */
- {/*namelist is fieldlist of same unknown type*/ (yyval.fieldlist) = A_linkFieldList((yyvsp[-2].fieldlist), A_FieldList(A_Field(EM_tokPos, (yyvsp[0].sym), NULL), NULL));}
-#line 1813 "y.tab.c" /* yacc.c:1646 */
+#line 132 "Pascal.y" /* yacc.c:1646 */
+ {/*record type*/ (yyval.ty) = A_RecordTy(EM_tokPos, (yyvsp[-1].fieldlist));}
+#line 1830 "y.tab.c" /* yacc.c:1646 */
break;
case 37:
#line 134 "Pascal.y" /* yacc.c:1646 */
- {(yyval.fieldlist) = A_FieldList(A_Field(EM_tokPos, (yyvsp[0].sym), NULL), NULL);}
-#line 1819 "y.tab.c" /* yacc.c:1646 */
+ {/*link parts of fieldlists*/ (yyval.fieldlist) = A_linkFieldList((yyvsp[-1].fieldlist), (yyvsp[0].fieldlist)); }
+#line 1836 "y.tab.c" /* yacc.c:1646 */
break;
case 38:
-#line 137 "Pascal.y" /* yacc.c:1646 */
- {/*variable declaration part*/ (yyval.declist) = (yyvsp[0].declist);}
-#line 1825 "y.tab.c" /* yacc.c:1646 */
+#line 135 "Pascal.y" /* yacc.c:1646 */
+ {(yyval.fieldlist) = (yyvsp[0].fieldlist);}
+#line 1842 "y.tab.c" /* yacc.c:1646 */
break;
case 39:
-#line 138 "Pascal.y" /* yacc.c:1646 */
- {/*no variable declaration*/ (yyval.declist) = NULL;}
-#line 1831 "y.tab.c" /* yacc.c:1646 */
+#line 136 "Pascal.y" /* yacc.c:1646 */
+ { /*set type of namelist*/(yyval.fieldlist) = A_setFieldListType((yyvsp[-3].fieldlist), (yyvsp[-1].ty));}
+#line 1848 "y.tab.c" /* yacc.c:1646 */
break;
case 40:
-#line 139 "Pascal.y" /* yacc.c:1646 */
- {/*variable declaration list*/ (yyval.declist) = A_linkDecList((yyvsp[-1].declist), (yyvsp[0].declist));}
-#line 1837 "y.tab.c" /* yacc.c:1646 */
+#line 137 "Pascal.y" /* yacc.c:1646 */
+ {/*namelist is fieldlist of same unknown type*/ (yyval.fieldlist) = A_linkFieldList((yyvsp[-2].fieldlist), A_FieldList(A_Field(EM_tokPos, (yyvsp[0].sym), NULL), NULL));}
+#line 1854 "y.tab.c" /* yacc.c:1646 */
break;
case 41:
-#line 140 "Pascal.y" /* yacc.c:1646 */
- {(yyval.declist) = (yyvsp[0].declist);}
-#line 1843 "y.tab.c" /* yacc.c:1646 */
+#line 138 "Pascal.y" /* yacc.c:1646 */
+ {(yyval.fieldlist) = A_FieldList(A_Field(EM_tokPos, (yyvsp[0].sym), NULL), NULL);}
+#line 1860 "y.tab.c" /* yacc.c:1646 */
break;
case 42:
#line 141 "Pascal.y" /* yacc.c:1646 */
- {/*change name_list to variable declaration list*/ (yyval.declist) = A_setDecListType(A_unDecList((yyvsp[-3].fieldlist)), (yyvsp[-1].ty));}
-#line 1849 "y.tab.c" /* yacc.c:1646 */
+ {/*variable declaration part*/ (yyval.declist) = (yyvsp[0].declist);}
+#line 1866 "y.tab.c" /* yacc.c:1646 */
break;
case 43:
-#line 144 "Pascal.y" /* yacc.c:1646 */
- {/*routine declaration part, new function*/ (yyval.fundeclist) = A_FundecList((yyvsp[-1].fundec), (yyvsp[0].fundeclist));}
-#line 1855 "y.tab.c" /* yacc.c:1646 */
+#line 142 "Pascal.y" /* yacc.c:1646 */
+ {/*no variable declaration*/ (yyval.declist) = NULL;}
+#line 1872 "y.tab.c" /* yacc.c:1646 */
break;
case 44:
-#line 145 "Pascal.y" /* yacc.c:1646 */
- {/*routine declaration part, new routine*/ (yyval.fundeclist) = A_FundecList((yyvsp[-1].fundec), (yyvsp[0].fundeclist));}
-#line 1861 "y.tab.c" /* yacc.c:1646 */
+#line 143 "Pascal.y" /* yacc.c:1646 */
+ {/*variable declaration list*/ (yyval.declist) = A_linkDecList((yyvsp[-1].declist), (yyvsp[0].declist));}
+#line 1878 "y.tab.c" /* yacc.c:1646 */
break;
case 45:
-#line 146 "Pascal.y" /* yacc.c:1646 */
- {(yyval.fundeclist) = NULL;}
-#line 1867 "y.tab.c" /* yacc.c:1646 */
+#line 144 "Pascal.y" /* yacc.c:1646 */
+ {(yyval.declist) = (yyvsp[0].declist);}
+#line 1884 "y.tab.c" /* yacc.c:1646 */
break;
case 46:
-#line 148 "Pascal.y" /* yacc.c:1646 */
- {/*set function body*/(yyval.fundec) = (yyvsp[-3].fundec); (yyval.fundec)->body = (yyvsp[-1].exp);}
-#line 1873 "y.tab.c" /* yacc.c:1646 */
+#line 145 "Pascal.y" /* yacc.c:1646 */
+ {(yyval.declist) = (yyvsp[0].declist);}
+#line 1890 "y.tab.c" /* yacc.c:1646 */
break;
case 47:
-#line 149 "Pascal.y" /* yacc.c:1646 */
- {/*declare function head*/(yyval.fundec) = A_Fundec(EM_tokPos, (yyvsp[-3].sym), (yyvsp[-2].fieldlist), (yyvsp[0].ty)->u.name, NULL);}
-#line 1879 "y.tab.c" /* yacc.c:1646 */
+#line 146 "Pascal.y" /* yacc.c:1646 */
+ {(yyval.declist) = NULL;}
+#line 1896 "y.tab.c" /* yacc.c:1646 */
break;
case 48:
-#line 150 "Pascal.y" /* yacc.c:1646 */
- {/*set procedure body*/ (yyval.fundec) = (yyvsp[-3].fundec); (yyval.fundec)->body = (yyvsp[-1].exp);}
-#line 1885 "y.tab.c" /* yacc.c:1646 */
+#line 147 "Pascal.y" /* yacc.c:1646 */
+ {/*change name_list to variable declaration list*/ (yyval.declist) = A_setDecListType(A_unDecList((yyvsp[-3].fieldlist)), (yyvsp[-1].ty));}
+#line 1902 "y.tab.c" /* yacc.c:1646 */
break;
case 49:
-#line 151 "Pascal.y" /* yacc.c:1646 */
- {/*declare procedure head, return type is NULL*/ (yyval.fundec) = A_Fundec(EM_tokPos, (yyvsp[-1].sym), (yyvsp[0].fieldlist), NULL, NULL);}
-#line 1891 "y.tab.c" /* yacc.c:1646 */
+#line 150 "Pascal.y" /* yacc.c:1646 */
+ {/*routine declaration part, new function*/ (yyval.fundeclist) = A_FundecList((yyvsp[-1].fundec), (yyvsp[0].fundeclist));}
+#line 1908 "y.tab.c" /* yacc.c:1646 */
break;
case 50:
-#line 152 "Pascal.y" /* yacc.c:1646 */
- {/*sub_routine in declaration*/(yyval.exp) = A_LetExp(EM_tokPos, (yyvsp[-1].declist), (yyvsp[0].exp));}
-#line 1897 "y.tab.c" /* yacc.c:1646 */
+#line 151 "Pascal.y" /* yacc.c:1646 */
+ {/*routine declaration part, new routine*/ (yyval.fundeclist) = A_FundecList((yyvsp[-1].fundec), (yyvsp[0].fundeclist));}
+#line 1914 "y.tab.c" /* yacc.c:1646 */
break;
case 51:
-#line 153 "Pascal.y" /* yacc.c:1646 */
- {/*parameters declaration*/ (yyval.fieldlist) = (yyvsp[-1].fieldlist);}
-#line 1903 "y.tab.c" /* yacc.c:1646 */
+#line 152 "Pascal.y" /* yacc.c:1646 */
+ {(yyval.fundeclist) = NULL;}
+#line 1920 "y.tab.c" /* yacc.c:1646 */
break;
case 52:
#line 154 "Pascal.y" /* yacc.c:1646 */
- {/*no parameters*/ (yyval.fieldlist) = NULL;}
-#line 1909 "y.tab.c" /* yacc.c:1646 */
+ {/*set function body*/(yyval.fundec) = (yyvsp[-3].fundec); (yyval.fundec)->body = (yyvsp[-1].exp);}
+#line 1926 "y.tab.c" /* yacc.c:1646 */
break;
case 53:
#line 155 "Pascal.y" /* yacc.c:1646 */
- {/*represent parameter declaration as A_fieldList*/ (yyval.fieldlist) = A_linkFieldList((yyvsp[-2].fieldlist), (yyvsp[0].fieldlist));}
-#line 1915 "y.tab.c" /* yacc.c:1646 */
+ {/*declare function head*/(yyval.fundec) = A_Fundec(EM_tokPos, (yyvsp[-3].sym), (yyvsp[-2].fieldlist), (yyvsp[0].ty)->u.name, NULL);}
+#line 1932 "y.tab.c" /* yacc.c:1646 */
break;
case 54:
#line 156 "Pascal.y" /* yacc.c:1646 */
- {(yyval.fieldlist) = (yyvsp[0].fieldlist);}
-#line 1921 "y.tab.c" /* yacc.c:1646 */
+ {/*set procedure body*/ (yyval.fundec) = (yyvsp[-3].fundec); (yyval.fundec)->body = (yyvsp[-1].exp);}
+#line 1938 "y.tab.c" /* yacc.c:1646 */
break;
case 55:
#line 157 "Pascal.y" /* yacc.c:1646 */
- { (yyval.fieldlist) = A_setFieldListType((yyvsp[-2].fieldlist), (yyvsp[0].ty));}
-#line 1927 "y.tab.c" /* yacc.c:1646 */
+ {/*declare procedure head, return type is NULL*/ (yyval.fundec) = A_Fundec(EM_tokPos, (yyvsp[-1].sym), (yyvsp[0].fieldlist), NULL, NULL);}
+#line 1944 "y.tab.c" /* yacc.c:1646 */
break;
case 56:
#line 158 "Pascal.y" /* yacc.c:1646 */
- { (yyval.fieldlist) = A_setFieldListType((yyvsp[-2].fieldlist), (yyvsp[0].ty));}
-#line 1933 "y.tab.c" /* yacc.c:1646 */
+ {/*sub_routine in declaration*/(yyval.exp) = A_LetExp(EM_tokPos, (yyvsp[-1].declist), (yyvsp[0].exp));}
+#line 1950 "y.tab.c" /* yacc.c:1646 */
break;
case 57:
#line 159 "Pascal.y" /* yacc.c:1646 */
- {(yyval.fieldlist) = (yyvsp[0].fieldlist);}
-#line 1939 "y.tab.c" /* yacc.c:1646 */
+ {/*parameters declaration*/ (yyval.fieldlist) = (yyvsp[-1].fieldlist);}
+#line 1956 "y.tab.c" /* yacc.c:1646 */
break;
case 58:
#line 160 "Pascal.y" /* yacc.c:1646 */
- {(yyval.fieldlist) = (yyvsp[0].fieldlist);}
-#line 1945 "y.tab.c" /* yacc.c:1646 */
+ {/*no parameters*/ (yyval.fieldlist) = NULL;}
+#line 1962 "y.tab.c" /* yacc.c:1646 */
break;
case 59:
-#line 163 "Pascal.y" /* yacc.c:1646 */
- {/*set routine body as A_exp*/ (yyval.exp) = (yyvsp[0].exp);}
-#line 1951 "y.tab.c" /* yacc.c:1646 */
+#line 161 "Pascal.y" /* yacc.c:1646 */
+ {/*represent parameter declaration as A_fieldList*/ (yyval.fieldlist) = A_linkFieldList((yyvsp[-2].fieldlist), (yyvsp[0].fieldlist));}
+#line 1968 "y.tab.c" /* yacc.c:1646 */
break;
case 60:
-#line 164 "Pascal.y" /* yacc.c:1646 */
- { (yyval.exp) = A_SeqExp(EM_tokPos, (yyvsp[-1].explist));}
-#line 1957 "y.tab.c" /* yacc.c:1646 */
+#line 162 "Pascal.y" /* yacc.c:1646 */
+ {(yyval.fieldlist) = (yyvsp[0].fieldlist);}
+#line 1974 "y.tab.c" /* yacc.c:1646 */
break;
case 61:
-#line 165 "Pascal.y" /* yacc.c:1646 */
- { /*statement in routine body*/(yyval.explist) = A_ExpList((yyvsp[-2].exp), (yyvsp[0].explist));}
-#line 1963 "y.tab.c" /* yacc.c:1646 */
+#line 163 "Pascal.y" /* yacc.c:1646 */
+ { (yyval.fieldlist) = A_setFieldListType((yyvsp[-2].fieldlist), (yyvsp[0].ty));}
+#line 1980 "y.tab.c" /* yacc.c:1646 */
break;
case 62:
-#line 166 "Pascal.y" /* yacc.c:1646 */
- {(yyval.explist) = NULL;}
-#line 1969 "y.tab.c" /* yacc.c:1646 */
+#line 164 "Pascal.y" /* yacc.c:1646 */
+ { (yyval.fieldlist) = A_setFieldListType((yyvsp[-2].fieldlist), (yyvsp[0].ty));}
+#line 1986 "y.tab.c" /* yacc.c:1646 */
break;
case 63:
-#line 167 "Pascal.y" /* yacc.c:1646 */
- {(yyval.explist) = NULL;}
-#line 1975 "y.tab.c" /* yacc.c:1646 */
+#line 165 "Pascal.y" /* yacc.c:1646 */
+ {(yyval.fieldlist) = (yyvsp[0].fieldlist);}
+#line 1992 "y.tab.c" /* yacc.c:1646 */
break;
case 64:
-#line 168 "Pascal.y" /* yacc.c:1646 */
- {(yyval.exp) = (yyvsp[0].exp);}
-#line 1981 "y.tab.c" /* yacc.c:1646 */
+#line 166 "Pascal.y" /* yacc.c:1646 */
+ {(yyval.fieldlist) = (yyvsp[0].fieldlist);}
+#line 1998 "y.tab.c" /* yacc.c:1646 */
break;
case 65:
#line 169 "Pascal.y" /* yacc.c:1646 */
- { (yyval.exp) = (yyvsp[0].exp);}
-#line 1987 "y.tab.c" /* yacc.c:1646 */
+ {/*set routine body as A_exp*/ (yyval.exp) = (yyvsp[0].exp);}
+#line 2004 "y.tab.c" /* yacc.c:1646 */
break;
case 66:
#line 170 "Pascal.y" /* yacc.c:1646 */
- { (yyval.exp) = (yyvsp[0].exp);}
-#line 1993 "y.tab.c" /* yacc.c:1646 */
+ { (yyval.exp) = A_SeqExp(EM_tokPos, (yyvsp[-1].explist));}
+#line 2010 "y.tab.c" /* yacc.c:1646 */
break;
case 67:
#line 171 "Pascal.y" /* yacc.c:1646 */
- {/*call function or procedure*/ (yyval.exp) = (yyvsp[0].exp);}
-#line 1999 "y.tab.c" /* yacc.c:1646 */
+ { /*statement in routine body*/(yyval.explist) = A_ExpList((yyvsp[-2].exp), (yyvsp[0].explist));}
+#line 2016 "y.tab.c" /* yacc.c:1646 */
break;
case 68:
#line 172 "Pascal.y" /* yacc.c:1646 */
- {(yyval.exp) = (yyvsp[0].exp);}
-#line 2005 "y.tab.c" /* yacc.c:1646 */
+ {(yyval.explist) = NULL;}
+#line 2022 "y.tab.c" /* yacc.c:1646 */
break;
case 69:
#line 173 "Pascal.y" /* yacc.c:1646 */
- {(yyval.exp) = (yyvsp[0].exp);}
-#line 2011 "y.tab.c" /* yacc.c:1646 */
+ {(yyval.explist) = (yyvsp[0].explist);}
+#line 2028 "y.tab.c" /* yacc.c:1646 */
break;
case 70:
#line 174 "Pascal.y" /* yacc.c:1646 */
- { (yyval.exp) = (yyvsp[0].exp);}
-#line 2017 "y.tab.c" /* yacc.c:1646 */
+ {(yyval.exp) = (yyvsp[0].exp);}
+#line 2034 "y.tab.c" /* yacc.c:1646 */
break;
case 71:
#line 175 "Pascal.y" /* yacc.c:1646 */
- {(yyval.exp) = (yyvsp[0].exp);}
-#line 2023 "y.tab.c" /* yacc.c:1646 */
+ { (yyval.exp) = (yyvsp[0].exp);}
+#line 2040 "y.tab.c" /* yacc.c:1646 */
break;
case 72:
#line 176 "Pascal.y" /* yacc.c:1646 */
- {(yyval.exp) = (yyvsp[0].exp);}
-#line 2029 "y.tab.c" /* yacc.c:1646 */
+ { (yyval.exp) = (yyvsp[0].exp);}
+#line 2046 "y.tab.c" /* yacc.c:1646 */
break;
case 73:
#line 177 "Pascal.y" /* yacc.c:1646 */
- {(yyval.exp) = (yyvsp[0].exp);}
-#line 2035 "y.tab.c" /* yacc.c:1646 */
+ {/*call function or procedure*/ (yyval.exp) = (yyvsp[0].exp);}
+#line 2052 "y.tab.c" /* yacc.c:1646 */
break;
case 74:
#line 178 "Pascal.y" /* yacc.c:1646 */
{(yyval.exp) = (yyvsp[0].exp);}
-#line 2041 "y.tab.c" /* yacc.c:1646 */
+#line 2058 "y.tab.c" /* yacc.c:1646 */
break;
case 75:
#line 179 "Pascal.y" /* yacc.c:1646 */
- {/*simple variable assignment*/ (yyval.exp) = A_AssignExp(EM_tokPos,A_SimpleVar(EM_tokPos, (yyvsp[-2].sym)), (yyvsp[0].exp));}
-#line 2047 "y.tab.c" /* yacc.c:1646 */
+ {(yyval.exp) = (yyvsp[0].exp);}
+#line 2064 "y.tab.c" /* yacc.c:1646 */
break;
case 76:
#line 180 "Pascal.y" /* yacc.c:1646 */
- {/*subscript variable of array assignment*/ (yyval.exp) = A_AssignExp(EM_tokPos, A_SubscriptVar(EM_tokPos, A_SimpleVar(EM_tokPos, (yyvsp[-5].sym)), (yyvsp[-3].exp)),(yyvsp[0].exp));}
-#line 2053 "y.tab.c" /* yacc.c:1646 */
+ { (yyval.exp) = (yyvsp[0].exp);}
+#line 2070 "y.tab.c" /* yacc.c:1646 */
break;
case 77:
#line 181 "Pascal.y" /* yacc.c:1646 */
- {/*field variable of record assignment*/(yyval.exp) = A_AssignExp(EM_tokPos, A_FieldVar(EM_tokPos, A_SimpleVar(EM_tokPos, (yyvsp[-4].sym)), (yyvsp[-2].sym)),(yyvsp[0].exp));}
-#line 2059 "y.tab.c" /* yacc.c:1646 */
+ {(yyval.exp) = (yyvsp[0].exp);}
+#line 2076 "y.tab.c" /* yacc.c:1646 */
break;
case 78:
#line 182 "Pascal.y" /* yacc.c:1646 */
- {/*call function*/ (yyval.exp) = A_CallExp(EM_tokPos, (yyvsp[0].sym), NULL);}
-#line 2065 "y.tab.c" /* yacc.c:1646 */
+ {(yyval.exp) = (yyvsp[0].exp);}
+#line 2082 "y.tab.c" /* yacc.c:1646 */
break;
case 79:
#line 183 "Pascal.y" /* yacc.c:1646 */
- {/*call function with arguments*/ (yyval.exp) = A_CallExp(EM_tokPos, (yyvsp[-3].sym), (yyvsp[-1].explist));}
-#line 2071 "y.tab.c" /* yacc.c:1646 */
+ {(yyval.exp) = (yyvsp[0].exp);}
+#line 2088 "y.tab.c" /* yacc.c:1646 */
break;
case 80:
#line 184 "Pascal.y" /* yacc.c:1646 */
- {/*call system procedure*/(yyval.exp) = A_CallExp(EM_tokPos, (yyvsp[0].sym), NULL);}
-#line 2077 "y.tab.c" /* yacc.c:1646 */
+ {(yyval.exp) = (yyvsp[0].exp);}
+#line 2094 "y.tab.c" /* yacc.c:1646 */
break;
case 81:
#line 185 "Pascal.y" /* yacc.c:1646 */
- {/*call system procedure with arguments*/(yyval.exp) = A_CallExp(EM_tokPos, (yyvsp[-3].sym), (yyvsp[-1].explist));}
-#line 2083 "y.tab.c" /* yacc.c:1646 */
+ {/*simple variable assignment*/ (yyval.exp) = A_AssignExp(EM_tokPos,A_SimpleVar(EM_tokPos, (yyvsp[-2].sym)), (yyvsp[0].exp));}
+#line 2100 "y.tab.c" /* yacc.c:1646 */
break;
case 82:
#line 186 "Pascal.y" /* yacc.c:1646 */
- {}
-#line 2089 "y.tab.c" /* yacc.c:1646 */
+ {/*subscript variable of array assignment*/ (yyval.exp) = A_AssignExp(EM_tokPos, A_SubscriptVar(EM_tokPos, A_SimpleVar(EM_tokPos, (yyvsp[-5].sym)), (yyvsp[-3].exp)),(yyvsp[0].exp));}
+#line 2106 "y.tab.c" /* yacc.c:1646 */
break;
case 83:
#line 187 "Pascal.y" /* yacc.c:1646 */
- {/*if statement*/ (yyval.exp) = A_IfExp(EM_tokPos, (yyvsp[-3].exp), (yyvsp[-1].exp), (yyvsp[0].exp));}
-#line 2095 "y.tab.c" /* yacc.c:1646 */
+ {/*field variable of record assignment*/(yyval.exp) = A_AssignExp(EM_tokPos, A_FieldVar(EM_tokPos, A_SimpleVar(EM_tokPos, (yyvsp[-4].sym)), (yyvsp[-2].sym)),(yyvsp[0].exp));}
+#line 2112 "y.tab.c" /* yacc.c:1646 */
break;
case 84:
#line 188 "Pascal.y" /* yacc.c:1646 */
- {/*with else clause*/ (yyval.exp) = (yyvsp[0].exp);}
-#line 2101 "y.tab.c" /* yacc.c:1646 */
+ {/*call function*/ (yyval.exp) = A_CallExp(EM_tokPos, (yyvsp[0].sym), NULL);}
+#line 2118 "y.tab.c" /* yacc.c:1646 */
break;
case 85:
#line 189 "Pascal.y" /* yacc.c:1646 */
- {/*no else clause*/ (yyval.exp) = NULL;}
-#line 2107 "y.tab.c" /* yacc.c:1646 */
+ {/*call function with arguments*/ (yyval.exp) = A_CallExp(EM_tokPos, (yyvsp[-3].sym), (yyvsp[-1].explist));}
+#line 2124 "y.tab.c" /* yacc.c:1646 */
break;
case 86:
#line 190 "Pascal.y" /* yacc.c:1646 */
- {/*repeat statement*/
- (yyval.exp) = A_RepeatExp(EM_tokPos, (yyvsp[-2].exp), (yyvsp[0].exp));}
-#line 2114 "y.tab.c" /* yacc.c:1646 */
+ {/*call system procedure*/(yyval.exp) = A_CallExp(EM_tokPos, (yyvsp[0].sym), NULL);}
+#line 2130 "y.tab.c" /* yacc.c:1646 */
break;
case 87:
-#line 192 "Pascal.y" /* yacc.c:1646 */
- {/*while statement*/ (yyval.exp) = A_WhileExp(EM_tokPos, (yyvsp[-2].exp), (yyvsp[0].exp));}
-#line 2120 "y.tab.c" /* yacc.c:1646 */
+#line 191 "Pascal.y" /* yacc.c:1646 */
+ {/*call system procedure with arguments*/(yyval.exp) = A_CallExp(EM_tokPos, (yyvsp[-3].sym), (yyvsp[-1].explist));}
+#line 2136 "y.tab.c" /* yacc.c:1646 */
break;
case 88:
-#line 193 "Pascal.y" /* yacc.c:1646 */
- {/*for statement*/
- A_var var = A_SimpleVar(EM_tokPos, (yyvsp[-6].sym));
- if (!((yyvsp[-3].cval))) {
- // to
- (yyval.exp) = A_SeqExp(EM_tokPos, A_ExpList(A_AssignExp(EM_tokPos, var, (yyvsp[-4].exp)), A_ExpList(A_WhileExp(EM_tokPos, A_OpExp(EM_tokPos, A_ltOp, A_VarExp(EM_tokPos, var), (yyvsp[-2].exp)), (yyvsp[0].exp)), NULL )));
- } else {
- // downto
- (yyval.exp) = A_SeqExp(EM_tokPos, A_ExpList(A_AssignExp(EM_tokPos, var, (yyvsp[-4].exp)), A_ExpList(A_WhileExp(EM_tokPos, A_OpExp(EM_tokPos, A_gtOp, A_VarExp(EM_tokPos ,var), (yyvsp[-2].exp)), (yyvsp[0].exp)), NULL )));
- }
-}
-#line 2135 "y.tab.c" /* yacc.c:1646 */
+#line 192 "Pascal.y" /* yacc.c:1646 */
+ {}
+#line 2142 "y.tab.c" /* yacc.c:1646 */
break;
case 89:
-#line 203 "Pascal.y" /* yacc.c:1646 */
- {(yyval.cval) = 0;}
-#line 2141 "y.tab.c" /* yacc.c:1646 */
+#line 193 "Pascal.y" /* yacc.c:1646 */
+ {/*if statement*/ (yyval.exp) = A_IfExp(EM_tokPos, (yyvsp[-3].exp), (yyvsp[-1].exp), (yyvsp[0].exp));}
+#line 2148 "y.tab.c" /* yacc.c:1646 */
break;
case 90:
-#line 204 "Pascal.y" /* yacc.c:1646 */
- {(yyval.cval) = 1;}
-#line 2147 "y.tab.c" /* yacc.c:1646 */
+#line 194 "Pascal.y" /* yacc.c:1646 */
+ {/*with else clause*/ (yyval.exp) = (yyvsp[0].exp);}
+#line 2154 "y.tab.c" /* yacc.c:1646 */
break;
case 91:
-#line 205 "Pascal.y" /* yacc.c:1646 */
- {/*case statement, case_expr_list is all the possible value*/ (yyval.exp) = A_CaseExp(EM_tokPos, (yyvsp[-3].exp), (yyvsp[-1].explist));}
-#line 2153 "y.tab.c" /* yacc.c:1646 */
+#line 195 "Pascal.y" /* yacc.c:1646 */
+ {/*no else clause*/ (yyval.exp) = NULL;}
+#line 2160 "y.tab.c" /* yacc.c:1646 */
break;
case 92:
-#line 206 "Pascal.y" /* yacc.c:1646 */
- {(yyval.explist) = A_ExpList((yyvsp[-1].exp), (yyvsp[0].explist));}
-#line 2159 "y.tab.c" /* yacc.c:1646 */
+#line 196 "Pascal.y" /* yacc.c:1646 */
+ {/*repeat statement*/
+ (yyval.exp) = A_RepeatExp(EM_tokPos, (yyvsp[-2].exp), (yyvsp[0].exp));}
+#line 2167 "y.tab.c" /* yacc.c:1646 */
break;
case 93:
-#line 207 "Pascal.y" /* yacc.c:1646 */
- {(yyval.explist) = A_ExpList((yyvsp[0].exp), NULL);}
-#line 2165 "y.tab.c" /* yacc.c:1646 */
+#line 198 "Pascal.y" /* yacc.c:1646 */
+ {/*while statement*/ (yyval.exp) = A_WhileExp(EM_tokPos, (yyvsp[-2].exp), (yyvsp[0].exp));}
+#line 2173 "y.tab.c" /* yacc.c:1646 */
break;
case 94:
-#line 208 "Pascal.y" /* yacc.c:1646 */
- {(yyval.exp) = A_CaseValExp(EM_tokPos, (yyvsp[-3].exp), (yyvsp[-1].exp));}
-#line 2171 "y.tab.c" /* yacc.c:1646 */
+#line 199 "Pascal.y" /* yacc.c:1646 */
+ {/*for statement*/
+ A_var var = A_SimpleVar(EM_tokPos, (yyvsp[-6].sym));
+ if (!((yyvsp[-3].cval))) {
+ // to
+ (yyval.exp) = A_SeqExp(EM_tokPos, A_ExpList(A_AssignExp(EM_tokPos, var, (yyvsp[-4].exp)), A_ExpList(A_WhileExp(EM_tokPos, A_OpExp(EM_tokPos, A_ltOp, A_VarExp(EM_tokPos, var), (yyvsp[-2].exp)), (yyvsp[0].exp)), NULL )));
+ } else {
+ // downto
+ (yyval.exp) = A_SeqExp(EM_tokPos, A_ExpList(A_AssignExp(EM_tokPos, var, (yyvsp[-4].exp)), A_ExpList(A_WhileExp(EM_tokPos, A_OpExp(EM_tokPos, A_gtOp, A_VarExp(EM_tokPos ,var), (yyvsp[-2].exp)), (yyvsp[0].exp)), NULL )));
+ }
+}
+#line 2188 "y.tab.c" /* yacc.c:1646 */
break;
case 95:
#line 209 "Pascal.y" /* yacc.c:1646 */
- {(yyval.exp) = A_CaseValExp(EM_tokPos, A_VarExp(EM_tokPos, A_SimpleVar(EM_tokPos, (yyvsp[-3].sym))), (yyvsp[-1].exp));}
-#line 2177 "y.tab.c" /* yacc.c:1646 */
+ {(yyval.cval) = 0;}
+#line 2194 "y.tab.c" /* yacc.c:1646 */
break;
case 96:
#line 210 "Pascal.y" /* yacc.c:1646 */
- {/*goto statement*/ (yyval.exp) = A_GotoExp(EM_tokPos, A_IntExp(EM_tokPos, (yyvsp[0].ival)));}
-#line 2183 "y.tab.c" /* yacc.c:1646 */
+ {(yyval.cval) = 1;}
+#line 2200 "y.tab.c" /* yacc.c:1646 */
break;
case 97:
-#line 212 "Pascal.y" /* yacc.c:1646 */
- { (yyval.explist) = A_ExpList((yyvsp[-2].exp), (yyvsp[0].explist));}
-#line 2189 "y.tab.c" /* yacc.c:1646 */
+#line 211 "Pascal.y" /* yacc.c:1646 */
+ {/*case statement, case_expr_list is all the possible value*/ (yyval.exp) = A_CaseExp(EM_tokPos, (yyvsp[-3].exp), (yyvsp[-1].explist));}
+#line 2206 "y.tab.c" /* yacc.c:1646 */
break;
case 98:
-#line 213 "Pascal.y" /* yacc.c:1646 */
- {(yyval.explist) = A_ExpList((yyvsp[0].exp), NULL);}
-#line 2195 "y.tab.c" /* yacc.c:1646 */
+#line 212 "Pascal.y" /* yacc.c:1646 */
+ {(yyval.explist) = A_ExpList((yyvsp[-1].exp), (yyvsp[0].explist));}
+#line 2212 "y.tab.c" /* yacc.c:1646 */
break;
case 99:
-#line 214 "Pascal.y" /* yacc.c:1646 */
- {/*greater equal expression*/ (yyval.exp) = A_OpExp(EM_tokPos, A_geOp, (yyvsp[-2].exp), (yyvsp[0].exp));}
-#line 2201 "y.tab.c" /* yacc.c:1646 */
+#line 213 "Pascal.y" /* yacc.c:1646 */
+ {(yyval.explist) = A_ExpList((yyvsp[0].exp), NULL);}
+#line 2218 "y.tab.c" /* yacc.c:1646 */
break;
case 100:
-#line 215 "Pascal.y" /* yacc.c:1646 */
- {/*greater than expression*/ (yyval.exp) = A_OpExp(EM_tokPos, A_gtOp, (yyvsp[-2].exp), (yyvsp[0].exp));}
-#line 2207 "y.tab.c" /* yacc.c:1646 */
+#line 214 "Pascal.y" /* yacc.c:1646 */
+ {(yyval.exp) = A_CaseValExp(EM_tokPos, (yyvsp[-3].exp), (yyvsp[-1].exp));}
+#line 2224 "y.tab.c" /* yacc.c:1646 */
break;
case 101:
-#line 216 "Pascal.y" /* yacc.c:1646 */
- {/*less equal expression*/ (yyval.exp) = A_OpExp(EM_tokPos, A_leOp, (yyvsp[-2].exp), (yyvsp[0].exp)); }
-#line 2213 "y.tab.c" /* yacc.c:1646 */
+#line 215 "Pascal.y" /* yacc.c:1646 */
+ {(yyval.exp) = A_CaseValExp(EM_tokPos, A_VarExp(EM_tokPos, A_SimpleVar(EM_tokPos, (yyvsp[-3].sym))), (yyvsp[-1].exp));}
+#line 2230 "y.tab.c" /* yacc.c:1646 */
break;
case 102:
-#line 217 "Pascal.y" /* yacc.c:1646 */
- {/*less than expression*/ (yyval.exp) = A_OpExp(EM_tokPos, A_ltOp, (yyvsp[-2].exp), (yyvsp[0].exp));}
-#line 2219 "y.tab.c" /* yacc.c:1646 */
+#line 216 "Pascal.y" /* yacc.c:1646 */
+ {/*goto statement*/ (yyval.exp) = A_GotoExp(EM_tokPos, A_IntExp(EM_tokPos, (yyvsp[0].ival)));}
+#line 2236 "y.tab.c" /* yacc.c:1646 */
break;
case 103:
#line 218 "Pascal.y" /* yacc.c:1646 */
- {/*equal expression*/ (yyval.exp) = A_OpExp(EM_tokPos, A_eqOp, (yyvsp[-2].exp), (yyvsp[0].exp));}
-#line 2225 "y.tab.c" /* yacc.c:1646 */
+ { (yyval.explist) = A_ExpList((yyvsp[-2].exp), (yyvsp[0].explist));}
+#line 2242 "y.tab.c" /* yacc.c:1646 */
break;
case 104:
#line 219 "Pascal.y" /* yacc.c:1646 */
- {/*unequal expression*/ (yyval.exp) = A_OpExp(EM_tokPos, A_neqOp, (yyvsp[-2].exp), (yyvsp[0].exp));}
-#line 2231 "y.tab.c" /* yacc.c:1646 */
+ {(yyval.explist) = A_ExpList((yyvsp[0].exp), NULL);}
+#line 2248 "y.tab.c" /* yacc.c:1646 */
break;
case 105:
#line 220 "Pascal.y" /* yacc.c:1646 */
- { (yyval.exp) = (yyvsp[0].exp);}
-#line 2237 "y.tab.c" /* yacc.c:1646 */
+ {/*greater equal expression*/ (yyval.exp) = A_OpExp(EM_tokPos, A_geOp, (yyvsp[-2].exp), (yyvsp[0].exp));}
+#line 2254 "y.tab.c" /* yacc.c:1646 */
break;
case 106:
-#line 222 "Pascal.y" /* yacc.c:1646 */
- {(yyval.exp) = A_OpExp(EM_tokPos, A_plusOp, (yyvsp[-2].exp), (yyvsp[0].exp));}
-#line 2243 "y.tab.c" /* yacc.c:1646 */
+#line 221 "Pascal.y" /* yacc.c:1646 */
+ {/*greater than expression*/ (yyval.exp) = A_OpExp(EM_tokPos, A_gtOp, (yyvsp[-2].exp), (yyvsp[0].exp));}
+#line 2260 "y.tab.c" /* yacc.c:1646 */
break;
case 107:
-#line 223 "Pascal.y" /* yacc.c:1646 */
- {(yyval.exp) = A_OpExp(EM_tokPos, A_minusOp, (yyvsp[-2].exp), (yyvsp[0].exp));}
-#line 2249 "y.tab.c" /* yacc.c:1646 */
+#line 222 "Pascal.y" /* yacc.c:1646 */
+ {/*less equal expression*/ (yyval.exp) = A_OpExp(EM_tokPos, A_leOp, (yyvsp[-2].exp), (yyvsp[0].exp)); }
+#line 2266 "y.tab.c" /* yacc.c:1646 */
break;
case 108:
-#line 224 "Pascal.y" /* yacc.c:1646 */
- {/*bool operation or*/ (yyval.exp) = A_IfExp(EM_tokPos, (yyvsp[-2].exp), A_IntExp(EM_tokPos, 1), (yyvsp[0].exp));}
-#line 2255 "y.tab.c" /* yacc.c:1646 */
+#line 223 "Pascal.y" /* yacc.c:1646 */
+ {/*less than expression*/ (yyval.exp) = A_OpExp(EM_tokPos, A_ltOp, (yyvsp[-2].exp), (yyvsp[0].exp));}
+#line 2272 "y.tab.c" /* yacc.c:1646 */
break;
case 109:
-#line 225 "Pascal.y" /* yacc.c:1646 */
- { (yyval.exp) = (yyvsp[0].exp);}
-#line 2261 "y.tab.c" /* yacc.c:1646 */
+#line 224 "Pascal.y" /* yacc.c:1646 */
+ {/*equal expression*/ (yyval.exp) = A_OpExp(EM_tokPos, A_eqOp, (yyvsp[-2].exp), (yyvsp[0].exp));}
+#line 2278 "y.tab.c" /* yacc.c:1646 */
break;
case 110:
-#line 226 "Pascal.y" /* yacc.c:1646 */
- { (yyval.exp) = A_OpExp(EM_tokPos, A_timesOp, (yyvsp[-2].exp), (yyvsp[0].exp));}
-#line 2267 "y.tab.c" /* yacc.c:1646 */
+#line 225 "Pascal.y" /* yacc.c:1646 */
+ {/*unequal expression*/ (yyval.exp) = A_OpExp(EM_tokPos, A_neqOp, (yyvsp[-2].exp), (yyvsp[0].exp));}
+#line 2284 "y.tab.c" /* yacc.c:1646 */
break;
case 111:
-#line 227 "Pascal.y" /* yacc.c:1646 */
- { /*intdiv operation*/ (yyval.exp) = A_OpExp(EM_tokPos, A_divideOp, (yyvsp[-2].exp), (yyvsp[0].exp)); }
-#line 2273 "y.tab.c" /* yacc.c:1646 */
+#line 226 "Pascal.y" /* yacc.c:1646 */
+ { (yyval.exp) = (yyvsp[0].exp);}
+#line 2290 "y.tab.c" /* yacc.c:1646 */
break;
case 112:
#line 228 "Pascal.y" /* yacc.c:1646 */
- { /*real div operaiton*/ (yyval.exp) = A_OpExp(EM_tokPos, A_realDivideOp, (yyvsp[-2].exp), (yyvsp[0].exp));}
-#line 2279 "y.tab.c" /* yacc.c:1646 */
+ {(yyval.exp) = A_OpExp(EM_tokPos, A_plusOp, (yyvsp[-2].exp), (yyvsp[0].exp));}
+#line 2296 "y.tab.c" /* yacc.c:1646 */
break;
case 113:
#line 229 "Pascal.y" /* yacc.c:1646 */
- { /*mod operation*/ (yyval.exp) = A_OpExp(EM_tokPos, A_modOp, (yyvsp[-2].exp), (yyvsp[0].exp));}
-#line 2285 "y.tab.c" /* yacc.c:1646 */
+ {(yyval.exp) = A_OpExp(EM_tokPos, A_minusOp, (yyvsp[-2].exp), (yyvsp[0].exp));}
+#line 2302 "y.tab.c" /* yacc.c:1646 */
break;
case 114:
#line 230 "Pascal.y" /* yacc.c:1646 */
- { /*bool operation and*/ (yyval.exp) = A_IfExp(EM_tokPos, (yyvsp[-2].exp), (yyvsp[0].exp), A_IntExp(EM_tokPos, 0));}
-#line 2291 "y.tab.c" /* yacc.c:1646 */
+ {/*bool operation or*/ (yyval.exp) = A_IfExp(EM_tokPos, (yyvsp[-2].exp), A_IntExp(EM_tokPos, 1), (yyvsp[0].exp));}
+#line 2308 "y.tab.c" /* yacc.c:1646 */
break;
case 115:
#line 231 "Pascal.y" /* yacc.c:1646 */
{ (yyval.exp) = (yyvsp[0].exp);}
-#line 2297 "y.tab.c" /* yacc.c:1646 */
+#line 2314 "y.tab.c" /* yacc.c:1646 */
break;
case 116:
#line 232 "Pascal.y" /* yacc.c:1646 */
- {(yyval.exp) = A_VarExp(EM_tokPos, A_SimpleVar(EM_tokPos, (yyvsp[0].sym)));}
-#line 2303 "y.tab.c" /* yacc.c:1646 */
+ { (yyval.exp) = A_OpExp(EM_tokPos, A_timesOp, (yyvsp[-2].exp), (yyvsp[0].exp));}
+#line 2320 "y.tab.c" /* yacc.c:1646 */
break;
case 117:
#line 233 "Pascal.y" /* yacc.c:1646 */
- {/*call function*/(yyval.exp) = A_CallExp(EM_tokPos, (yyvsp[-3].sym), (yyvsp[-1].explist));}
-#line 2309 "y.tab.c" /* yacc.c:1646 */
+ { /*intdiv operation*/ (yyval.exp) = A_OpExp(EM_tokPos, A_divideOp, (yyvsp[-2].exp), (yyvsp[0].exp)); }
+#line 2326 "y.tab.c" /* yacc.c:1646 */
break;
case 118:
#line 234 "Pascal.y" /* yacc.c:1646 */
- {/*call system function without argument*/(yyval.exp) = A_CallExp(EM_tokPos, (yyvsp[0].sym), NULL);}
-#line 2315 "y.tab.c" /* yacc.c:1646 */
+ { /*real div operaiton*/ (yyval.exp) = A_OpExp(EM_tokPos, A_realDivideOp, (yyvsp[-2].exp), (yyvsp[0].exp));}
+#line 2332 "y.tab.c" /* yacc.c:1646 */
break;
case 119:
#line 235 "Pascal.y" /* yacc.c:1646 */
- {/*call system function with arguments*/(yyval.exp) = A_CallExp(EM_tokPos, (yyvsp[-3].sym), (yyvsp[-1].explist));}
-#line 2321 "y.tab.c" /* yacc.c:1646 */
+ { /*mod operation*/ (yyval.exp) = A_OpExp(EM_tokPos, A_modOp, (yyvsp[-2].exp), (yyvsp[0].exp));}
+#line 2338 "y.tab.c" /* yacc.c:1646 */
break;
case 120:
#line 236 "Pascal.y" /* yacc.c:1646 */
- {/*const expression*/ (yyval.exp) = (yyvsp[0].exp);}
-#line 2327 "y.tab.c" /* yacc.c:1646 */
+ { /*bool operation and*/ (yyval.exp) = A_IfExp(EM_tokPos, (yyvsp[-2].exp), (yyvsp[0].exp), A_IntExp(EM_tokPos, 0));}
+#line 2344 "y.tab.c" /* yacc.c:1646 */
break;
case 121:
#line 237 "Pascal.y" /* yacc.c:1646 */
- { /*expression*/ (yyval.exp) = (yyvsp[-1].exp);}
-#line 2333 "y.tab.c" /* yacc.c:1646 */
+ { (yyval.exp) = (yyvsp[0].exp);}
+#line 2350 "y.tab.c" /* yacc.c:1646 */
break;
case 122:
#line 238 "Pascal.y" /* yacc.c:1646 */
- { /*bool operation, not*/ (yyval.exp) = A_IfExp(EM_tokPos, (yyvsp[0].exp), A_IntExp(EM_tokPos, 0), A_IntExp(EM_tokPos,1));}
-#line 2339 "y.tab.c" /* yacc.c:1646 */
+ {(yyval.exp) = A_VarExp(EM_tokPos, A_SimpleVar(EM_tokPos, (yyvsp[0].sym)));}
+#line 2356 "y.tab.c" /* yacc.c:1646 */
break;
case 123:
#line 239 "Pascal.y" /* yacc.c:1646 */
- {/*expression with negative value*/ (yyval.exp) = A_OpExp(EM_tokPos, A_minusOp, A_IntExp(EM_tokPos, 0), (yyvsp[0].exp));}
-#line 2345 "y.tab.c" /* yacc.c:1646 */
+ {/*call function*/(yyval.exp) = A_CallExp(EM_tokPos, (yyvsp[-3].sym), (yyvsp[-1].explist));}
+#line 2362 "y.tab.c" /* yacc.c:1646 */
break;
case 124:
#line 240 "Pascal.y" /* yacc.c:1646 */
- { /*subscript variable expression*/ (yyval.exp) = A_VarExp(EM_tokPos,A_SubscriptVar(EM_tokPos, A_SimpleVar(EM_tokPos, (yyvsp[-3].sym)), (yyvsp[-1].exp)));}
-#line 2351 "y.tab.c" /* yacc.c:1646 */
+ {/*call system function without argument*/(yyval.exp) = A_CallExp(EM_tokPos, (yyvsp[0].sym), NULL);}
+#line 2368 "y.tab.c" /* yacc.c:1646 */
break;
case 125:
#line 241 "Pascal.y" /* yacc.c:1646 */
- { /*field variable expression*/ (yyval.exp) = A_VarExp(EM_tokPos, A_FieldVar(EM_tokPos, A_SimpleVar(EM_tokPos, (yyvsp[-2].sym)), (yyvsp[0].sym)));}
-#line 2357 "y.tab.c" /* yacc.c:1646 */
+ {/*call system function with arguments*/(yyval.exp) = A_CallExp(EM_tokPos, (yyvsp[-3].sym), (yyvsp[-1].explist));}
+#line 2374 "y.tab.c" /* yacc.c:1646 */
break;
case 126:
#line 242 "Pascal.y" /* yacc.c:1646 */
- {(yyval.explist) = (yyvsp[-2].explist); (yyvsp[-2].explist)->tail = A_ExpList((yyvsp[0].exp), NULL);}
-#line 2363 "y.tab.c" /* yacc.c:1646 */
+ {/*const expression*/ (yyval.exp) = (yyvsp[0].exp);}
+#line 2380 "y.tab.c" /* yacc.c:1646 */
break;
case 127:
#line 243 "Pascal.y" /* yacc.c:1646 */
- {(yyval.explist) = A_ExpList((yyvsp[0].exp), NULL);}
-#line 2369 "y.tab.c" /* yacc.c:1646 */
+ { /*expression*/ (yyval.exp) = (yyvsp[-1].exp);}
+#line 2386 "y.tab.c" /* yacc.c:1646 */
break;
case 128:
-#line 245 "Pascal.y" /* yacc.c:1646 */
- {(yyval.sym) = S_Symbol((yyvsp[0].sval));}
-#line 2375 "y.tab.c" /* yacc.c:1646 */
+#line 244 "Pascal.y" /* yacc.c:1646 */
+ { /*bool operation, not*/ (yyval.exp) = A_IfExp(EM_tokPos, (yyvsp[0].exp), A_IntExp(EM_tokPos, 0), A_IntExp(EM_tokPos,1));}
+#line 2392 "y.tab.c" /* yacc.c:1646 */
break;
case 129:
-#line 246 "Pascal.y" /* yacc.c:1646 */
- {(yyval.sym) = S_Symbol((yyvsp[0].sval));}
-#line 2381 "y.tab.c" /* yacc.c:1646 */
+#line 245 "Pascal.y" /* yacc.c:1646 */
+ {/*expression with negative value*/ (yyval.exp) = A_OpExp(EM_tokPos, A_minusOp, A_IntExp(EM_tokPos, 0), (yyvsp[0].exp));}
+#line 2398 "y.tab.c" /* yacc.c:1646 */
break;
case 130:
-#line 247 "Pascal.y" /* yacc.c:1646 */
- {(yyval.sym) = S_Symbol((yyvsp[0].sval));}
-#line 2387 "y.tab.c" /* yacc.c:1646 */
+#line 246 "Pascal.y" /* yacc.c:1646 */
+ { /*subscript variable expression*/ (yyval.exp) = A_VarExp(EM_tokPos,A_SubscriptVar(EM_tokPos, A_SimpleVar(EM_tokPos, (yyvsp[-3].sym)), (yyvsp[-1].exp)));}
+#line 2404 "y.tab.c" /* yacc.c:1646 */
break;
case 131:
-#line 248 "Pascal.y" /* yacc.c:1646 */
- {(yyval.sym) = S_Symbol((yyvsp[0].sval));}
-#line 2393 "y.tab.c" /* yacc.c:1646 */
+#line 247 "Pascal.y" /* yacc.c:1646 */
+ { /*field variable expression*/ (yyval.exp) = A_VarExp(EM_tokPos, A_FieldVar(EM_tokPos, A_SimpleVar(EM_tokPos, (yyvsp[-2].sym)), (yyvsp[0].sym)));}
+#line 2410 "y.tab.c" /* yacc.c:1646 */
break;
case 132:
-#line 249 "Pascal.y" /* yacc.c:1646 */
- {(yyval.sym) = S_Symbol((yyvsp[0].sval));}
-#line 2399 "y.tab.c" /* yacc.c:1646 */
+#line 248 "Pascal.y" /* yacc.c:1646 */
+ {(yyval.explist) = (yyvsp[-2].explist); (yyvsp[-2].explist)->tail = A_ExpList((yyvsp[0].exp), NULL);}
+#line 2416 "y.tab.c" /* yacc.c:1646 */
break;
case 133:
+#line 249 "Pascal.y" /* yacc.c:1646 */
+ {(yyval.explist) = A_ExpList((yyvsp[0].exp), NULL);}
+#line 2422 "y.tab.c" /* yacc.c:1646 */
+ break;
+
+ case 134:
#line 251 "Pascal.y" /* yacc.c:1646 */
+ {(yyval.sym) = S_Symbol((yyvsp[0].sval));}
+#line 2428 "y.tab.c" /* yacc.c:1646 */
+ break;
+
+ case 135:
+#line 252 "Pascal.y" /* yacc.c:1646 */
+ {(yyval.sym) = S_Symbol((yyvsp[0].sval));}
+#line 2434 "y.tab.c" /* yacc.c:1646 */
+ break;
+
+ case 136:
+#line 253 "Pascal.y" /* yacc.c:1646 */
+ {(yyval.sym) = S_Symbol((yyvsp[0].sval));}
+#line 2440 "y.tab.c" /* yacc.c:1646 */
+ break;
+
+ case 137:
+#line 254 "Pascal.y" /* yacc.c:1646 */
+ {(yyval.sym) = S_Symbol((yyvsp[0].sval));}
+#line 2446 "y.tab.c" /* yacc.c:1646 */
+ break;
+
+ case 138:
+#line 255 "Pascal.y" /* yacc.c:1646 */
+ {(yyval.sym) = S_Symbol((yyvsp[0].sval));}
+#line 2452 "y.tab.c" /* yacc.c:1646 */
+ break;
+
+ case 139:
+#line 257 "Pascal.y" /* yacc.c:1646 */
{/*jump to next semi after error */}
-#line 2405 "y.tab.c" /* yacc.c:1646 */
+#line 2458 "y.tab.c" /* yacc.c:1646 */
break;
-#line 2409 "y.tab.c" /* yacc.c:1646 */
+#line 2462 "y.tab.c" /* yacc.c:1646 */
default: break;
}
/* User semantic actions sometimes alter yychar, and that requires
@@ -2633,7 +2686,7 @@ yyparse (void)
#endif
return yyresult;
}
-#line 253 "Pascal.y" /* yacc.c:1906 */
+#line 259 "Pascal.y" /* yacc.c:1906 */
int yyerror(char* msg) {
EM_error(EM_tokPos, "%s", msg);
@@ -2655,7 +2708,7 @@ A_fieldList A_linkFieldList(A_fieldList front, A_fieldList tail) {
A_fieldList A_setFieldListType(A_fieldList fieldList, A_ty ty) {
A_fieldList front = fieldList;
for (;fieldList;fieldList = fieldList->tail) {
- fieldList->head->typ = ty->u.name;
+ fieldList->head->typ = ty;
}
return front;
@@ -2674,7 +2727,7 @@ A_decList A_linkDecList(A_decList front, A_decList tail) {
A_decList A_setDecListType(A_decList decList, A_ty ty) {
A_decList front = decList;
for (;decList;decList = decList->tail) {
- decList->head->u.var.typ = ty->u.name;
+ decList->head->u.var.typ = ty;
}
return front;
diff --git a/src/y.tab.h b/CompilerPascal/y.tab.h
similarity index 100%
rename from src/y.tab.h
rename to CompilerPascal/y.tab.h
diff --git a/README.md b/README.md
index dbc7f3a..e69de29 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +0,0 @@
-# PascalCompiler
-This is the course project for compiler course
\ No newline at end of file
diff --git a/src/PascalCompiler b/src/PascalCompiler
deleted file mode 160000
index 6d1326c..0000000
--- a/src/PascalCompiler
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 6d1326c9d9015ae8aa18efe02ec1d4dbd4ce6766
diff --git a/src/env.c b/src/env.c
deleted file mode 100644
index c3e68dd..0000000
--- a/src/env.c
+++ /dev/null
@@ -1,83 +0,0 @@
-#include
-#include "util.h"
-#include "symbol.h"
-#include "absyn.h"
-#include "types.h"
-#include "temp.h"
-#include "tree.h"
-#include "frame.h"
-#include "translate.h"
-#include "env.h"
-
-Environments Newvarenv(Tr_access acc,Type ty, int isConst)
-{
- Environments tmp=checked_malloc(sizeof(*tmp));
- if(isConst)
- tmp->flag = CONST;
- else
- tmp->flag=VAR;
- tmp->u.var.ty=ty;
- tmp->u.var.acc=acc;
- return tmp;
-}
-Environments Newfunenv(Tr_level l,Temp_label label,Typelist param,Type output)
-{
- Environments tmp=checked_malloc(sizeof(*tmp));
- tmp->flag=FUN;
- tmp->u.fun.param=param;
- tmp->u.fun.output=output;
- tmp->u.fun.lev=l;
- tmp->u.fun.label=label;
- return tmp;
-}
-
-S_table Base_varenv(void) //⣬Ӧǰıͣ
-{
- S_table base=S_empty();
- S_enter(base,S_Symbol("integer"),INT_type());
- S_enter(base,S_Symbol("string"),STRING_type());
- S_enter(base,S_Symbol("real"),REAL_type());
-
- //¼
- S_enter(base,S_Symbol("char"),CHAR_type());
- S_enter(base,S_Symbol("boolean"),BOOLEAN_type());
- return base;
-}
-S_table Base_funenv(void) //ʱ䣬Ժ˵
-{
- S_table base=S_empty();
- S_enter(base,
- S_Symbol("print"),
- Newfunenv(Tr_outermost(),Temp_newlabel(),Newtypelist(STRING_type(),NULL),VOID_type())
- ); //void print(string)
- S_enter(base,S_Symbol("getchar"),
- Newfunenv(Tr_outermost(),Temp_newlabel(),NULL,VOID_type())
- ); //void getchcar(void)
- S_enter(base,S_Symbol("chr"),
- Newfunenv(Tr_outermost(),Temp_newlabel(),Newtypelist(INT_type(),NULL),STRING_type())
- ); //string chr(int)
- S_enter(base,S_Symbol("size"),
- Newfunenv(Tr_outermost(),Temp_newlabel(),Newtypelist(STRING_type(),NULL),INT_type())
- ); //int size(string)
- S_enter(base,S_Symbol("not"),
- Newfunenv(Tr_outermost(),Temp_newlabel(),Newtypelist(INT_type(),NULL),INT_type())
- ); //int not(int)
- S_enter(base,S_Symbol("exit"),
- Newfunenv(Tr_outermost(),Temp_newlabel(),Newtypelist(INT_type(),NULL),VOID_type())
- ); //void exit(int)
- S_enter(base,S_Symbol("substring"),
- Newfunenv(Tr_outermost(),Temp_newlabel(),Newtypelist(STRING_type(),
- Newtypelist(INT_type(),Newtypelist(INT_type(),NULL))),STRING_type())
- ); //string substing(string,int start,int end)
- S_enter(base,S_Symbol("ord"),
- Newfunenv(Tr_outermost(),Temp_newlabel(),Newtypelist(STRING_type(),NULL),INT_type())
- ); //int ord(string)
- S_enter(base,S_Symbol("concat"),
- Newfunenv(Tr_outermost(),Temp_newlabel(),Newtypelist(STRING_type(),
- Newtypelist(STRING_type(),NULL)),STRING_type())
- ); //string concat(string1,string2)
- S_enter(base,S_Symbol("flush"),
- Newfunenv(Tr_outermost(),Temp_newlabel(),NULL,VOID_type())
- ); //void flush(void)
- return base;
-}
\ No newline at end of file
diff --git a/src/escape.c b/src/escape.c
deleted file mode 100644
index e69de29..0000000
diff --git a/src/escape.h b/src/escape.h
deleted file mode 100644
index e69de29..0000000
diff --git a/src/lex.yy.c b/src/lex.yy.c
deleted file mode 100644
index fb27188..0000000
--- a/src/lex.yy.c
+++ /dev/null
@@ -1,2229 +0,0 @@
-
-#line 2 "lex.yy.c"
-
-#define YY_INT_ALIGNED short int
-
-/* A lexical scanner generated by flex */
-
-#define FLEX_SCANNER
-#define YY_FLEX_MAJOR_VERSION 2
-#define YY_FLEX_MINOR_VERSION 6
-#define YY_FLEX_SUBMINOR_VERSION 4
-#if YY_FLEX_SUBMINOR_VERSION > 0
-#define FLEX_BETA
-#endif
-
-/* First, we deal with platform-specific or compiler-specific issues. */
-
-/* begin standard C headers. */
-#include
-#include
-#include
-#include
-
-/* end standard C headers. */
-
-/* flex integer type definitions */
-
-#ifndef FLEXINT_H
-#define FLEXINT_H
-
-/* C99 systems have . Non-C99 systems may or may not. */
-
-#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
-
-/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
- * if you want the limit (max/min) macros for int types.
- */
-#ifndef __STDC_LIMIT_MACROS
-#define __STDC_LIMIT_MACROS 1
-#endif
-
-#include
-typedef int8_t flex_int8_t;
-typedef uint8_t flex_uint8_t;
-typedef int16_t flex_int16_t;
-typedef uint16_t flex_uint16_t;
-typedef int32_t flex_int32_t;
-typedef uint32_t flex_uint32_t;
-#else
-typedef signed char flex_int8_t;
-typedef short int flex_int16_t;
-typedef int flex_int32_t;
-typedef unsigned char flex_uint8_t;
-typedef unsigned short int flex_uint16_t;
-typedef unsigned int flex_uint32_t;
-
-/* Limits of integral types. */
-#ifndef INT8_MIN
-#define INT8_MIN (-128)
-#endif
-#ifndef INT16_MIN
-#define INT16_MIN (-32767-1)
-#endif
-#ifndef INT32_MIN
-#define INT32_MIN (-2147483647-1)
-#endif
-#ifndef INT8_MAX
-#define INT8_MAX (127)
-#endif
-#ifndef INT16_MAX
-#define INT16_MAX (32767)
-#endif
-#ifndef INT32_MAX
-#define INT32_MAX (2147483647)
-#endif
-#ifndef UINT8_MAX
-#define UINT8_MAX (255U)
-#endif
-#ifndef UINT16_MAX
-#define UINT16_MAX (65535U)
-#endif
-#ifndef UINT32_MAX
-#define UINT32_MAX (4294967295U)
-#endif
-
-#ifndef SIZE_MAX
-#define SIZE_MAX (~(size_t)0)
-#endif
-
-#endif /* ! C99 */
-
-#endif /* ! FLEXINT_H */
-
-/* begin standard C++ headers. */
-
-/* TODO: this is always defined, so inline it */
-#define yyconst const
-
-#if defined(__GNUC__) && __GNUC__ >= 3
-#define yynoreturn __attribute__((__noreturn__))
-#else
-#define yynoreturn
-#endif
-
-/* Returned upon end-of-file. */
-#define YY_NULL 0
-
-/* Promotes a possibly negative, possibly signed char to an
- * integer in range [0..255] for use as an array index.
- */
-#define YY_SC_TO_UI(c) ((YY_CHAR) (c))
-
-/* Enter a start condition. This macro really ought to take a parameter,
- * but we do it the disgusting crufty way forced on us by the ()-less
- * definition of BEGIN.
- */
-#define BEGIN (yy_start) = 1 + 2 *
-/* Translate the current start state into a value that can be later handed
- * to BEGIN to return to the state. The YYSTATE alias is for lex
- * compatibility.
- */
-#define YY_START (((yy_start) - 1) / 2)
-#define YYSTATE YY_START
-/* Action number for EOF rule of a given start state. */
-#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
-/* Special action meaning "start processing a new file". */
-#define YY_NEW_FILE yyrestart( yyin )
-#define YY_END_OF_BUFFER_CHAR 0
-
-/* Size of default input buffer. */
-#ifndef YY_BUF_SIZE
-#ifdef __ia64__
-/* On IA-64, the buffer size is 16k, not 8k.
- * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
- * Ditto for the __ia64__ case accordingly.
- */
-#define YY_BUF_SIZE 32768
-#else
-#define YY_BUF_SIZE 16384
-#endif /* __ia64__ */
-#endif
-
-/* The state buf must be large enough to hold one state per character in the main buffer.
- */
-#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
-
-#ifndef YY_TYPEDEF_YY_BUFFER_STATE
-#define YY_TYPEDEF_YY_BUFFER_STATE
-typedef struct yy_buffer_state *YY_BUFFER_STATE;
-#endif
-
-#ifndef YY_TYPEDEF_YY_SIZE_T
-#define YY_TYPEDEF_YY_SIZE_T
-typedef size_t yy_size_t;
-#endif
-
-extern int yyleng;
-
-extern FILE *yyin, *yyout;
-
-#define EOB_ACT_CONTINUE_SCAN 0
-#define EOB_ACT_END_OF_FILE 1
-#define EOB_ACT_LAST_MATCH 2
-
- #define YY_LESS_LINENO(n)
- #define YY_LINENO_REWIND_TO(ptr)
-
-/* Return all but the first "n" matched characters back to the input stream. */
-#define yyless(n) \
- do \
- { \
- /* Undo effects of setting up yytext. */ \
- int yyless_macro_arg = (n); \
- YY_LESS_LINENO(yyless_macro_arg);\
- *yy_cp = (yy_hold_char); \
- YY_RESTORE_YY_MORE_OFFSET \
- (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
- YY_DO_BEFORE_ACTION; /* set up yytext again */ \
- } \
- while ( 0 )
-#define unput(c) yyunput( c, (yytext_ptr) )
-
-#ifndef YY_STRUCT_YY_BUFFER_STATE
-#define YY_STRUCT_YY_BUFFER_STATE
-struct yy_buffer_state
- {
- FILE *yy_input_file;
-
- char *yy_ch_buf; /* input buffer */
- char *yy_buf_pos; /* current position in input buffer */
-
- /* Size of input buffer in bytes, not including room for EOB
- * characters.
- */
- int yy_buf_size;
-
- /* Number of characters read into yy_ch_buf, not including EOB
- * characters.
- */
- int yy_n_chars;
-
- /* Whether we "own" the buffer - i.e., we know we created it,
- * and can realloc() it to grow it, and should free() it to
- * delete it.
- */
- int yy_is_our_buffer;
-
- /* Whether this is an "interactive" input source; if so, and
- * if we're using stdio for input, then we want to use getc()
- * instead of fread(), to make sure we stop fetching input after
- * each newline.
- */
- int yy_is_interactive;
-
- /* Whether we're considered to be at the beginning of a line.
- * If so, '^' rules will be active on the next match, otherwise
- * not.
- */
- int yy_at_bol;
-
- int yy_bs_lineno; /**< The line count. */
- int yy_bs_column; /**< The column count. */
-
- /* Whether to try to fill the input buffer when we reach the
- * end of it.
- */
- int yy_fill_buffer;
-
- int yy_buffer_status;
-
-#define YY_BUFFER_NEW 0
-#define YY_BUFFER_NORMAL 1
- /* When an EOF's been seen but there's still some text to process
- * then we mark the buffer as YY_EOF_PENDING, to indicate that we
- * shouldn't try reading from the input source any more. We might
- * still have a bunch of tokens to match, though, because of
- * possible backing-up.
- *
- * When we actually see the EOF, we change the status to "new"
- * (via yyrestart()), so that the user can continue scanning by
- * just pointing yyin at a new input file.
- */
-#define YY_BUFFER_EOF_PENDING 2
-
- };
-#endif /* !YY_STRUCT_YY_BUFFER_STATE */
-
-/* Stack of input buffers. */
-static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */
-static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */
-static YY_BUFFER_STATE * yy_buffer_stack = NULL; /**< Stack as an array. */
-
-/* We provide macros for accessing buffer states in case in the
- * future we want to put the buffer states in a more general
- * "scanner state".
- *
- * Returns the top of the stack, or NULL.
- */
-#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \
- ? (yy_buffer_stack)[(yy_buffer_stack_top)] \
- : NULL)
-/* Same as previous macro, but useful when we know that the buffer stack is not
- * NULL or when we need an lvalue. For internal use only.
- */
-#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)]
-
-/* yy_hold_char holds the character lost when yytext is formed. */
-static char yy_hold_char;
-static int yy_n_chars; /* number of characters read into yy_ch_buf */
-int yyleng;
-
-/* Points to current character in buffer. */
-static char *yy_c_buf_p = NULL;
-static int yy_init = 0; /* whether we need to initialize */
-static int yy_start = 0; /* start state number */
-
-/* Flag which is used to allow yywrap()'s to do buffer switches
- * instead of setting up a fresh yyin. A bit of a hack ...
- */
-static int yy_did_buffer_switch_on_eof;
-
-void yyrestart ( FILE *input_file );
-void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer );
-YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size );
-void yy_delete_buffer ( YY_BUFFER_STATE b );
-void yy_flush_buffer ( YY_BUFFER_STATE b );
-void yypush_buffer_state ( YY_BUFFER_STATE new_buffer );
-void yypop_buffer_state ( void );
-
-static void yyensure_buffer_stack ( void );
-static void yy_load_buffer_state ( void );
-static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file );
-#define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER )
-
-YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size );
-YY_BUFFER_STATE yy_scan_string ( const char *yy_str );
-YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len );
-
-void *yyalloc ( yy_size_t );
-void *yyrealloc ( void *, yy_size_t );
-void yyfree ( void * );
-
-#define yy_new_buffer yy_create_buffer
-#define yy_set_interactive(is_interactive) \
- { \
- if ( ! YY_CURRENT_BUFFER ){ \
- yyensure_buffer_stack (); \
- YY_CURRENT_BUFFER_LVALUE = \
- yy_create_buffer( yyin, YY_BUF_SIZE ); \
- } \
- YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
- }
-#define yy_set_bol(at_bol) \
- { \
- if ( ! YY_CURRENT_BUFFER ){\
- yyensure_buffer_stack (); \
- YY_CURRENT_BUFFER_LVALUE = \
- yy_create_buffer( yyin, YY_BUF_SIZE ); \
- } \
- YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
- }
-#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
-
-/* Begin user sect3 */
-typedef flex_uint8_t YY_CHAR;
-
-FILE *yyin = NULL, *yyout = NULL;
-
-typedef int yy_state_type;
-
-extern int yylineno;
-int yylineno = 1;
-
-extern char *yytext;
-#ifdef yytext_ptr
-#undef yytext_ptr
-#endif
-#define yytext_ptr yytext
-
-static yy_state_type yy_get_previous_state ( void );
-static yy_state_type yy_try_NUL_trans ( yy_state_type current_state );
-static int yy_get_next_buffer ( void );
-static void yynoreturn yy_fatal_error ( const char* msg );
-
-/* Done after the current pattern has been matched and before the
- * corresponding action - sets up yytext.
- */
-#define YY_DO_BEFORE_ACTION \
- (yytext_ptr) = yy_bp; \
- yyleng = (int) (yy_cp - yy_bp); \
- (yy_hold_char) = *yy_cp; \
- *yy_cp = '\0'; \
- (yy_c_buf_p) = yy_cp;
-#define YY_NUM_RULES 63
-#define YY_END_OF_BUFFER 64
-/* This struct is not used in this scanner,
- but its presence is necessary. */
-struct yy_trans_info
- {
- flex_int32_t yy_verify;
- flex_int32_t yy_nxt;
- };
-static const flex_int16_t yy_accept[196] =
- { 0,
- 0, 0, 64, 62, 61, 59, 62, 53, 53, 1,
- 2, 12, 10, 7, 11, 5, 13, 51, 8, 9,
- 19, 20, 17, 50, 50, 50, 50, 50, 50, 50,
- 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
- 50, 3, 4, 50, 50, 50, 50, 50, 50, 50,
- 50, 50, 50, 50, 50, 60, 0, 6, 0, 51,
- 22, 18, 21, 16, 50, 50, 50, 50, 50, 50,
- 50, 41, 50, 50, 50, 50, 50, 35, 50, 50,
- 28, 48, 50, 50, 50, 43, 50, 50, 50, 50,
- 50, 50, 50, 50, 50, 50, 50, 48, 50, 50,
-
- 50, 50, 50, 50, 0, 52, 47, 50, 50, 50,
- 50, 14, 50, 50, 30, 42, 50, 50, 15, 49,
- 50, 50, 50, 50, 50, 50, 50, 26, 50, 50,
- 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
- 50, 0, 50, 50, 45, 50, 50, 37, 50, 46,
- 50, 50, 34, 50, 50, 36, 25, 50, 50, 50,
- 50, 50, 50, 50, 50, 0, 27, 33, 24, 50,
- 50, 50, 50, 50, 50, 39, 40, 50, 50, 54,
- 44, 50, 50, 50, 29, 38, 50, 50, 50, 23,
- 50, 31, 50, 32, 0
-
- } ;
-
-static const YY_CHAR yy_ec[256] =
- { 0,
- 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
- 1, 1, 4, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 2, 1, 5, 1, 1, 1, 1, 6, 7,
- 8, 9, 10, 11, 12, 13, 14, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 16, 17, 18,
- 19, 20, 1, 1, 21, 22, 23, 24, 25, 26,
- 27, 28, 29, 30, 30, 31, 32, 33, 34, 35,
- 30, 36, 37, 38, 39, 40, 41, 30, 42, 30,
- 43, 6, 44, 6, 6, 6, 45, 46, 47, 48,
-
- 49, 50, 27, 51, 52, 30, 30, 53, 54, 55,
- 56, 57, 58, 59, 60, 61, 62, 40, 63, 64,
- 42, 30, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1
- } ;
-
-static const YY_CHAR yy_meta[65] =
- { 0,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 2, 1, 1, 1, 1, 1,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 1, 1, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2
- } ;
-
-static const flex_int16_t yy_base[197] =
- { 0,
- 0, 0, 341, 342, 342, 342, 337, 292, 342, 342,
- 342, 342, 342, 342, 342, 325, 342, 52, 318, 342,
- 49, 342, 317, 37, 41, 50, 45, 45, 43, 38,
- 0, 54, 47, 51, 76, 50, 62, 80, 55, 68,
- 65, 342, 342, 82, 94, 100, 93, 97, 108, 118,
- 81, 99, 67, 129, 111, 342, 284, 342, 319, 145,
- 342, 342, 342, 342, 0, 135, 110, 306, 124, 132,
- 292, 126, 135, 149, 139, 141, 138, 0, 154, 143,
- 0, 0, 145, 170, 157, 0, 151, 152, 164, 174,
- 271, 274, 133, 276, 267, 263, 278, 277, 173, 189,
-
- 265, 276, 260, 269, 273, 302, 0, 188, 185, 186,
- 179, 0, 185, 194, 0, 0, 197, 191, 0, 0,
- 205, 197, 197, 205, 205, 216, 219, 0, 211, 0,
- 263, 0, 254, 252, 259, 260, 225, 246, 259, 256,
- 242, 243, 259, 217, 0, 213, 218, 0, 219, 0,
- 233, 225, 0, 226, 238, 0, 0, 224, 238, 239,
- 248, 241, 72, 0, 81, 261, 0, 0, 0, 233,
- 239, 245, 249, 251, 243, 0, 0, 59, 38, 342,
- 0, 242, 247, 256, 0, 0, 28, 257, 256, 0,
- 0, 0, 270, 0, 342, 73
-
- } ;
-
-static const flex_int16_t yy_def[197] =
- { 0,
- 195, 1, 195, 195, 195, 195, 195, 195, 195, 195,
- 195, 195, 195, 195, 195, 195, 195, 195, 195, 195,
- 195, 195, 195, 196, 196, 196, 196, 196, 196, 196,
- 196, 196, 196, 196, 196, 196, 196, 196, 196, 196,
- 196, 195, 195, 196, 196, 196, 196, 196, 196, 196,
- 196, 196, 196, 196, 196, 195, 195, 195, 195, 195,
- 195, 195, 195, 195, 196, 196, 196, 196, 196, 196,
- 196, 196, 196, 196, 196, 196, 196, 196, 196, 196,
- 196, 196, 196, 196, 196, 196, 196, 196, 196, 196,
- 196, 196, 196, 196, 196, 196, 196, 196, 196, 196,
-
- 196, 196, 196, 196, 195, 195, 196, 196, 196, 196,
- 196, 196, 196, 196, 196, 196, 196, 196, 196, 196,
- 196, 196, 196, 196, 196, 196, 196, 196, 196, 196,
- 196, 196, 196, 196, 196, 196, 196, 196, 196, 196,
- 196, 195, 196, 196, 196, 196, 196, 196, 196, 196,
- 196, 196, 196, 196, 196, 196, 196, 196, 196, 196,
- 196, 196, 196, 196, 196, 195, 196, 196, 196, 196,
- 196, 196, 196, 196, 196, 196, 196, 196, 196, 195,
- 196, 196, 196, 196, 196, 196, 196, 196, 196, 196,
- 196, 196, 196, 196, 0, 195
-
- } ;
-
-static const flex_int16_t yy_nxt[407] =
- { 0,
- 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
- 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
- 24, 25, 26, 27, 28, 29, 30, 31, 32, 31,
- 31, 33, 34, 35, 36, 37, 31, 38, 39, 40,
- 41, 31, 42, 43, 44, 45, 46, 27, 28, 47,
- 31, 48, 31, 49, 34, 50, 51, 31, 52, 53,
- 54, 39, 55, 31, 59, 68, 60, 62, 63, 66,
- 69, 77, 67, 71, 65, 73, 75, 74, 72, 78,
- 79, 76, 191, 70, 80, 83, 84, 88, 89, 68,
- 187, 66, 90, 77, 69, 67, 71, 73, 75, 74,
-
- 72, 81, 79, 78, 76, 70, 80, 85, 83, 88,
- 84, 82, 89, 86, 66, 90, 83, 67, 68, 164,
- 69, 87, 78, 84, 101, 81, 75, 91, 102, 179,
- 85, 76, 132, 70, 82, 86, 66, 94, 90, 99,
- 67, 79, 68, 81, 69, 108, 78, 100, 75, 92,
- 93, 95, 96, 82, 76, 70, 85, 59, 107, 60,
- 110, 90, 86, 79, 111, 97, 113, 81, 108, 104,
- 87, 114, 115, 117, 116, 118, 98, 119, 121, 85,
- 120, 125, 107, 110, 86, 126, 111, 103, 113, 127,
- 122, 130, 123, 132, 114, 117, 115, 116, 118, 128,
-
- 121, 119, 129, 120, 124, 125, 121, 126, 143, 122,
- 145, 123, 127, 144, 122, 146, 123, 147, 148, 149,
- 153, 136, 128, 124, 150, 129, 124, 151, 121, 155,
- 154, 152, 143, 137, 145, 123, 144, 156, 146, 147,
- 157, 159, 148, 149, 153, 124, 150, 158, 153, 168,
- 169, 151, 154, 155, 176, 170, 171, 172, 175, 156,
- 173, 174, 177, 159, 157, 180, 181, 182, 183, 184,
- 158, 168, 153, 169, 185, 188, 176, 163, 170, 171,
- 186, 172, 175, 173, 174, 189, 177, 190, 181, 192,
- 182, 193, 183, 184, 194, 178, 164, 188, 185, 132,
-
- 167, 166, 165, 186, 164, 130, 130, 130, 189, 190,
- 162, 192, 132, 161, 193, 160, 106, 142, 194, 166,
- 141, 140, 139, 138, 130, 130, 135, 134, 133, 131,
- 130, 112, 109, 106, 105, 64, 61, 58, 57, 56,
- 195, 3, 195, 195, 195, 195, 195, 195, 195, 195,
- 195, 195, 195, 195, 195, 195, 195, 195, 195, 195,
- 195, 195, 195, 195, 195, 195, 195, 195, 195, 195,
- 195, 195, 195, 195, 195, 195, 195, 195, 195, 195,
- 195, 195, 195, 195, 195, 195, 195, 195, 195, 195,
- 195, 195, 195, 195, 195, 195, 195, 195, 195, 195,
-
- 195, 195, 195, 195, 195, 195
- } ;
-
-static const flex_int16_t yy_chk[407] =
- { 0,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 18, 25, 18, 21, 21, 24,
- 26, 30, 24, 27, 196, 28, 29, 28, 27, 32,
- 33, 29, 187, 26, 34, 36, 37, 39, 40, 25,
- 179, 24, 41, 30, 26, 24, 27, 28, 29, 28,
-
- 27, 35, 33, 32, 29, 26, 34, 38, 36, 39,
- 37, 35, 40, 38, 44, 41, 51, 44, 45, 178,
- 46, 38, 48, 52, 53, 35, 47, 44, 53, 165,
- 38, 47, 163, 46, 35, 38, 44, 47, 55, 51,
- 44, 49, 45, 50, 46, 67, 48, 52, 47, 45,
- 46, 48, 49, 50, 47, 46, 54, 60, 66, 60,
- 69, 55, 54, 49, 70, 50, 72, 50, 67, 55,
- 54, 73, 74, 76, 75, 77, 50, 79, 83, 54,
- 80, 85, 66, 69, 54, 87, 70, 54, 72, 88,
- 84, 93, 84, 93, 73, 76, 74, 75, 77, 89,
-
- 83, 79, 90, 80, 84, 85, 99, 87, 108, 100,
- 110, 100, 88, 109, 84, 111, 84, 113, 114, 117,
- 122, 99, 89, 100, 118, 90, 84, 121, 99, 124,
- 123, 121, 108, 100, 110, 100, 109, 125, 111, 113,
- 126, 129, 114, 117, 122, 100, 118, 127, 137, 144,
- 146, 121, 123, 124, 158, 147, 149, 151, 155, 125,
- 152, 154, 159, 129, 126, 166, 170, 171, 172, 173,
- 127, 144, 137, 146, 174, 182, 158, 137, 147, 149,
- 175, 151, 155, 152, 154, 183, 159, 184, 170, 188,
- 171, 189, 172, 173, 193, 162, 161, 182, 174, 160,
-
- 143, 142, 141, 175, 140, 139, 138, 136, 183, 184,
- 135, 188, 134, 133, 189, 131, 106, 105, 193, 166,
- 104, 103, 102, 101, 98, 97, 96, 95, 94, 92,
- 91, 71, 68, 59, 57, 23, 19, 16, 8, 7,
- 3, 195, 195, 195, 195, 195, 195, 195, 195, 195,
- 195, 195, 195, 195, 195, 195, 195, 195, 195, 195,
- 195, 195, 195, 195, 195, 195, 195, 195, 195, 195,
- 195, 195, 195, 195, 195, 195, 195, 195, 195, 195,
- 195, 195, 195, 195, 195, 195, 195, 195, 195, 195,
- 195, 195, 195, 195, 195, 195, 195, 195, 195, 195,
-
- 195, 195, 195, 195, 195, 195
- } ;
-
-static yy_state_type yy_last_accepting_state;
-static char *yy_last_accepting_cpos;
-
-extern int yy_flex_debug;
-int yy_flex_debug = 0;
-
-/* The intent behind this definition is that it'll catch
- * any uses of REJECT which flex missed.
- */
-#define REJECT reject_used_but_not_detected
-#define yymore() yymore_used_but_not_detected
-#define YY_MORE_ADJ 0
-#define YY_RESTORE_YY_MORE_OFFSET
-char *yytext;
-#line 1 "Pascal.l"
-#line 2 "Pascal.l"
-#include
-#include "util.h"
-#include "errormsg.h"
-#include "symbol.h"
-#include "absyn.h"
-#include "y.tab.h"
-
-// update EM_tokPos
-void updatePos(void);
-int charPos;
-#line 608 "lex.yy.c"
-#line 609 "lex.yy.c"
-
-#define INITIAL 0
-
-#ifndef YY_NO_UNISTD_H
-/* Special case for "unistd.h", since it is non-ANSI. We include it way
- * down here because we want the user's section 1 to have been scanned first.
- * The user has a chance to override it with an option.
- */
-#include
-#endif
-
-#ifndef YY_EXTRA_TYPE
-#define YY_EXTRA_TYPE void *
-#endif
-
-static int yy_init_globals ( void );
-
-/* Accessor methods to globals.
- These are made visible to non-reentrant scanners for convenience. */
-
-int yylex_destroy ( void );
-
-int yyget_debug ( void );
-
-void yyset_debug ( int debug_flag );
-
-YY_EXTRA_TYPE yyget_extra ( void );
-
-void yyset_extra ( YY_EXTRA_TYPE user_defined );
-
-FILE *yyget_in ( void );
-
-void yyset_in ( FILE * _in_str );
-
-FILE *yyget_out ( void );
-
-void yyset_out ( FILE * _out_str );
-
- int yyget_leng ( void );
-
-char *yyget_text ( void );
-
-int yyget_lineno ( void );
-
-void yyset_lineno ( int _line_number );
-
-/* Macros after this point can all be overridden by user definitions in
- * section 1.
- */
-
-#ifndef YY_SKIP_YYWRAP
-#ifdef __cplusplus
-extern "C" int yywrap ( void );
-#else
-extern int yywrap ( void );
-#endif
-#endif
-
-#ifndef YY_NO_UNPUT
-
- static void yyunput ( int c, char *buf_ptr );
-
-#endif
-
-#ifndef yytext_ptr
-static void yy_flex_strncpy ( char *, const char *, int );
-#endif
-
-#ifdef YY_NEED_STRLEN
-static int yy_flex_strlen ( const char * );
-#endif
-
-#ifndef YY_NO_INPUT
-#ifdef __cplusplus
-static int yyinput ( void );
-#else
-static int input ( void );
-#endif
-
-#endif
-
-/* Amount of stuff to slurp up with each read. */
-#ifndef YY_READ_BUF_SIZE
-#ifdef __ia64__
-/* On IA-64, the buffer size is 16k, not 8k */
-#define YY_READ_BUF_SIZE 16384
-#else
-#define YY_READ_BUF_SIZE 8192
-#endif /* __ia64__ */
-#endif
-
-/* Copy whatever the last rule matched to the standard output. */
-#ifndef ECHO
-/* This used to be an fputs(), but since the string might contain NUL's,
- * we now use fwrite().
- */
-#define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0)
-#endif
-
-/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
- * is returned in "result".
- */
-#ifndef YY_INPUT
-#define YY_INPUT(buf,result,max_size) \
- if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
- { \
- int c = '*'; \
- int n; \
- for ( n = 0; n < max_size && \
- (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
- buf[n] = (char) c; \
- if ( c == '\n' ) \
- buf[n++] = (char) c; \
- if ( c == EOF && ferror( yyin ) ) \
- YY_FATAL_ERROR( "input in flex scanner failed" ); \
- result = n; \
- } \
- else \
- { \
- errno=0; \
- while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \
- { \
- if( errno != EINTR) \
- { \
- YY_FATAL_ERROR( "input in flex scanner failed" ); \
- break; \
- } \
- errno=0; \
- clearerr(yyin); \
- } \
- }\
-\
-
-#endif
-
-/* No semi-colon after return; correct usage is to write "yyterminate();" -
- * we don't want an extra ';' after the "return" because that will cause
- * some compilers to complain about unreachable statements.
- */
-#ifndef yyterminate
-#define yyterminate() return YY_NULL
-#endif
-
-/* Number of entries by which start-condition stack grows. */
-#ifndef YY_START_STACK_INCR
-#define YY_START_STACK_INCR 25
-#endif
-
-/* Report a fatal error. */
-#ifndef YY_FATAL_ERROR
-#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
-#endif
-
-/* end tables serialization structures and prototypes */
-
-/* Default declaration of generated scanner - a define so the user can
- * easily add parameters.
- */
-#ifndef YY_DECL
-#define YY_DECL_IS_OURS 1
-
-extern int yylex (void);
-
-#define YY_DECL int yylex (void)
-#endif /* !YY_DECL */
-
-/* Code executed at the beginning of each rule, after yytext and yyleng
- * have been set up.
- */
-#ifndef YY_USER_ACTION
-#define YY_USER_ACTION
-#endif
-
-/* Code executed at the end of each rule. */
-#ifndef YY_BREAK
-#define YY_BREAK /*LINTED*/break;
-#endif
-
-#define YY_RULE_SETUP \
- YY_USER_ACTION
-
-/** The main scanner function which does all the work.
- */
-YY_DECL
-{
- yy_state_type yy_current_state;
- char *yy_cp, *yy_bp;
- int yy_act;
-
- if ( !(yy_init) )
- {
- (yy_init) = 1;
-
-#ifdef YY_USER_INIT
- YY_USER_INIT;
-#endif
-
- if ( ! (yy_start) )
- (yy_start) = 1; /* first start state */
-
- if ( ! yyin )
- yyin = stdin;
-
- if ( ! yyout )
- yyout = stdout;
-
- if ( ! YY_CURRENT_BUFFER ) {
- yyensure_buffer_stack ();
- YY_CURRENT_BUFFER_LVALUE =
- yy_create_buffer( yyin, YY_BUF_SIZE );
- }
-
- yy_load_buffer_state( );
- }
-
- {
-#line 67 "Pascal.l"
-
-
-#line 829 "lex.yy.c"
-
- while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */
- {
- yy_cp = (yy_c_buf_p);
-
- /* Support of yytext. */
- *yy_cp = (yy_hold_char);
-
- /* yy_bp points to the position in yy_ch_buf of the start of
- * the current run.
- */
- yy_bp = yy_cp;
-
- yy_current_state = (yy_start);
-yy_match:
- do
- {
- YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ;
- if ( yy_accept[yy_current_state] )
- {
- (yy_last_accepting_state) = yy_current_state;
- (yy_last_accepting_cpos) = yy_cp;
- }
- while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
- {
- yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 196 )
- yy_c = yy_meta[yy_c];
- }
- yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
- ++yy_cp;
- }
- while ( yy_base[yy_current_state] != 342 );
-
-yy_find_action:
- yy_act = yy_accept[yy_current_state];
- if ( yy_act == 0 )
- { /* have to back up */
- yy_cp = (yy_last_accepting_cpos);
- yy_current_state = (yy_last_accepting_state);
- yy_act = yy_accept[yy_current_state];
- }
-
- YY_DO_BEFORE_ACTION;
-
-do_action: /* This label is used only to access EOF actions. */
-
- switch ( yy_act )
- { /* beginning of action switch */
- case 0: /* must back up */
- /* undo the effects of YY_DO_BEFORE_ACTION */
- *yy_cp = (yy_hold_char);
- yy_cp = (yy_last_accepting_cpos);
- yy_current_state = (yy_last_accepting_state);
- goto yy_find_action;
-
-case 1:
-YY_RULE_SETUP
-#line 69 "Pascal.l"
-{updatePos(); return LP;}
- YY_BREAK
-case 2:
-YY_RULE_SETUP
-#line 70 "Pascal.l"
-{updatePos(); return RP;}
- YY_BREAK
-case 3:
-YY_RULE_SETUP
-#line 71 "Pascal.l"
-{updatePos(); return LB;}
- YY_BREAK
-case 4:
-YY_RULE_SETUP
-#line 72 "Pascal.l"
-{updatePos(); return RB;}
- YY_BREAK
-case 5:
-YY_RULE_SETUP
-#line 73 "Pascal.l"
-{updatePos(); return DOT;}
- YY_BREAK
-case 6:
-YY_RULE_SETUP
-#line 74 "Pascal.l"
-{updatePos(); return DOTDOT;}
- YY_BREAK
-case 7:
-YY_RULE_SETUP
-#line 75 "Pascal.l"
-{updatePos(); return COMMA; }
- YY_BREAK
-case 8:
-YY_RULE_SETUP
-#line 76 "Pascal.l"
-{updatePos(); return COLON;} //应该是:SEMI应该是;
- YY_BREAK
-case 9:
-YY_RULE_SETUP
-#line 77 "Pascal.l"
-{updatePos(); return SEMI;} //name == id
- YY_BREAK
-case 10:
-YY_RULE_SETUP
-#line 78 "Pascal.l"
-{updatePos(); return PLUS;}
- YY_BREAK
-case 11:
-YY_RULE_SETUP
-#line 79 "Pascal.l"
-{updatePos(); return MINUS;}
- YY_BREAK
-case 12:
-YY_RULE_SETUP
-#line 80 "Pascal.l"
-{updatePos(); return MUL;}
- YY_BREAK
-case 13:
-YY_RULE_SETUP
-#line 81 "Pascal.l"
-{updatePos(); return REALDIV;}
- YY_BREAK
-case 14:
-YY_RULE_SETUP
-#line 82 "Pascal.l"
-{updatePos(); return INTDIV;}
- YY_BREAK
-case 15:
-YY_RULE_SETUP
-#line 83 "Pascal.l"
-{updatePos(); return MOD; }
- YY_BREAK
-case 16:
-YY_RULE_SETUP
-#line 84 "Pascal.l"
-{updatePos(); return GE;}
- YY_BREAK
-case 17:
-YY_RULE_SETUP
-#line 85 "Pascal.l"
-{updatePos(); return GT;}
- YY_BREAK
-case 18:
-YY_RULE_SETUP
-#line 86 "Pascal.l"
-{updatePos(); return LE;}
- YY_BREAK
-case 19:
-YY_RULE_SETUP
-#line 87 "Pascal.l"
-{updatePos(); return LT;}
- YY_BREAK
-case 20:
-YY_RULE_SETUP
-#line 88 "Pascal.l"
-{updatePos(); return EQUAL;}
- YY_BREAK
-case 21:
-YY_RULE_SETUP
-#line 89 "Pascal.l"
-{updatePos(); return UNEQUAL;}
- YY_BREAK
-case 22:
-YY_RULE_SETUP
-#line 90 "Pascal.l"
-{updatePos(); return ASSIGN;}
- YY_BREAK
-case 23:
-YY_RULE_SETUP
-#line 91 "Pascal.l"
-{updatePos(); return PROGRAM;}
- YY_BREAK
-case 24:
-YY_RULE_SETUP
-#line 92 "Pascal.l"
-{updatePos(); return CONST;}
- YY_BREAK
-case 25:
-YY_RULE_SETUP
-#line 93 "Pascal.l"
-{updatePos(); return TYPE;}
- YY_BREAK
-case 26:
-YY_RULE_SETUP
-#line 94 "Pascal.l"
-{updatePos(); return VAR;}
- YY_BREAK
-case 27:
-YY_RULE_SETUP
-#line 95 "Pascal.l"
-{updatePos(); return ARRAY;}
- YY_BREAK
-case 28:
-YY_RULE_SETUP
-#line 96 "Pascal.l"
-{updatePos(); return OF;}
- YY_BREAK
-case 29:
-YY_RULE_SETUP
-#line 97 "Pascal.l"
-{updatePos(); return RECORD;}
- YY_BREAK
-case 30:
-YY_RULE_SETUP
-#line 98 "Pascal.l"
-{updatePos(); return END;}
- YY_BREAK
-case 31:
-YY_RULE_SETUP
-#line 99 "Pascal.l"
-{updatePos(); return FUNCTION;}
- YY_BREAK
-case 32:
-YY_RULE_SETUP
-#line 100 "Pascal.l"
-{updatePos(); return PROCEDURE;}
- YY_BREAK
-case 33:
-YY_RULE_SETUP
-#line 101 "Pascal.l"
-{updatePos(); return BEGIN_T;}
- YY_BREAK
-case 34:
-YY_RULE_SETUP
-#line 102 "Pascal.l"
-{updatePos(); return READ;}
- YY_BREAK
-case 35:
-YY_RULE_SETUP
-#line 103 "Pascal.l"
-{updatePos(); return IF;}
- YY_BREAK
-case 36:
-YY_RULE_SETUP
-#line 104 "Pascal.l"
-{updatePos(); return THEN;}
- YY_BREAK
-case 37:
-YY_RULE_SETUP
-#line 105 "Pascal.l"
-{updatePos(); return ELSE;}
- YY_BREAK
-case 38:
-YY_RULE_SETUP
-#line 106 "Pascal.l"
-{updatePos(); return REPEAT;}
- YY_BREAK
-case 39:
-YY_RULE_SETUP
-#line 107 "Pascal.l"
-{updatePos(); return UNTIL;}
- YY_BREAK
-case 40:
-YY_RULE_SETUP
-#line 108 "Pascal.l"
-{updatePos(); return WHILE;}
- YY_BREAK
-case 41:
-YY_RULE_SETUP
-#line 109 "Pascal.l"
-{updatePos(); return DO;}
- YY_BREAK
-case 42:
-YY_RULE_SETUP
-#line 110 "Pascal.l"
-{updatePos(); return FOR;}
- YY_BREAK
-case 43:
-YY_RULE_SETUP
-#line 111 "Pascal.l"
-{updatePos(); return TO;}
- YY_BREAK
-case 44:
-YY_RULE_SETUP
-#line 112 "Pascal.l"
-{updatePos(); return DOWNTO;}
- YY_BREAK
-case 45:
-YY_RULE_SETUP
-#line 113 "Pascal.l"
-{updatePos(); return CASE;}
- YY_BREAK
-case 46:
-YY_RULE_SETUP
-#line 114 "Pascal.l"
-{updatePos(); return GOTO;}
- YY_BREAK
-case 47:
-YY_RULE_SETUP
-#line 115 "Pascal.l"
-{updatePos(); return AND;}
- YY_BREAK
-case 48:
-YY_RULE_SETUP
-#line 116 "Pascal.l"
-{updatePos(); return OR;}
- YY_BREAK
-case 49:
-YY_RULE_SETUP
-#line 117 "Pascal.l"
-{updatePos(); return NOT;}
- YY_BREAK
-case 50:
-YY_RULE_SETUP
-#line 118 "Pascal.l"
-{updatePos(); yylval.sval = yytext; return ID;}
- YY_BREAK
-case 51:
-YY_RULE_SETUP
-#line 119 "Pascal.l"
-{
- updatePos();
- int getNum;
- sscanf(yytext, "%d", &getNum);
- yylval.ival = getNum;
- return INTEGER;
-}
- YY_BREAK
-case 52:
-YY_RULE_SETUP
-#line 126 "Pascal.l"
-{
- updatePos();
- double getNum;
- sscanf(yytext, "%lf", &getNum);
- yylval.rval = getNum;
- return REAL;
-}
- YY_BREAK
-case 53:
-YY_RULE_SETUP
-#line 133 "Pascal.l"
-{updatePos(); yylval.cval = yytext[0]; return CHAR; }
- YY_BREAK
-case 54:
-YY_RULE_SETUP
-#line 134 "Pascal.l"
-{updatePos(); yylval.sval = yytext; return STRING; }
- YY_BREAK
-case 55:
-YY_RULE_SETUP
-#line 135 "Pascal.l"
-{updatePos(); return SYS_CON;}
- YY_BREAK
-case 56:
-YY_RULE_SETUP
-#line 136 "Pascal.l"
-{updatePos(); return SYS_FUNCT;}
- YY_BREAK
-case 57:
-YY_RULE_SETUP
-#line 137 "Pascal.l"
-{updatePos(); return SYS_PROC;}
- YY_BREAK
-case 58:
-YY_RULE_SETUP
-#line 138 "Pascal.l"
-{updatePos(); return SYS_TYPE;}
- YY_BREAK
-case 59:
-/* rule 59 can match eol */
-YY_RULE_SETUP
-#line 139 "Pascal.l"
-{updatePos(); EM_newline();}
- YY_BREAK
-case 60:
-/* rule 60 can match eol */
-YY_RULE_SETUP
-#line 140 "Pascal.l"
-{updatePos(); EM_newline();}
- YY_BREAK
-case 61:
-YY_RULE_SETUP
-#line 141 "Pascal.l"
-{updatePos();}
- YY_BREAK
-case 62:
-YY_RULE_SETUP
-#line 142 "Pascal.l"
-{updatePos(); char message[100]; sprintf(message, "illegal token:%s", yytext);EM_error(EM_tokPos, message);}
- YY_BREAK
-case 63:
-YY_RULE_SETUP
-#line 143 "Pascal.l"
-ECHO;
- YY_BREAK
-#line 1215 "lex.yy.c"
-case YY_STATE_EOF(INITIAL):
- yyterminate();
-
- case YY_END_OF_BUFFER:
- {
- /* Amount of text matched not including the EOB char. */
- int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1;
-
- /* Undo the effects of YY_DO_BEFORE_ACTION. */
- *yy_cp = (yy_hold_char);
- YY_RESTORE_YY_MORE_OFFSET
-
- if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
- {
- /* We're scanning a new file or input source. It's
- * possible that this happened because the user
- * just pointed yyin at a new source and called
- * yylex(). If so, then we have to assure
- * consistency between YY_CURRENT_BUFFER and our
- * globals. Here is the right place to do so, because
- * this is the first action (other than possibly a
- * back-up) that will match for the new input source.
- */
- (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
- YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
- YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
- }
-
- /* Note that here we test for yy_c_buf_p "<=" to the position
- * of the first EOB in the buffer, since yy_c_buf_p will
- * already have been incremented past the NUL character
- * (since all states make transitions on EOB to the
- * end-of-buffer state). Contrast this with the test
- * in input().
- */
- if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
- { /* This was really a NUL. */
- yy_state_type yy_next_state;
-
- (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text;
-
- yy_current_state = yy_get_previous_state( );
-
- /* Okay, we're now positioned to make the NUL
- * transition. We couldn't have
- * yy_get_previous_state() go ahead and do it
- * for us because it doesn't know how to deal
- * with the possibility of jamming (and we don't
- * want to build jamming into it because then it
- * will run more slowly).
- */
-
- yy_next_state = yy_try_NUL_trans( yy_current_state );
-
- yy_bp = (yytext_ptr) + YY_MORE_ADJ;
-
- if ( yy_next_state )
- {
- /* Consume the NUL. */
- yy_cp = ++(yy_c_buf_p);
- yy_current_state = yy_next_state;
- goto yy_match;
- }
-
- else
- {
- yy_cp = (yy_c_buf_p);
- goto yy_find_action;
- }
- }
-
- else switch ( yy_get_next_buffer( ) )
- {
- case EOB_ACT_END_OF_FILE:
- {
- (yy_did_buffer_switch_on_eof) = 0;
-
- if ( yywrap( ) )
- {
- /* Note: because we've taken care in
- * yy_get_next_buffer() to have set up
- * yytext, we can now set up
- * yy_c_buf_p so that if some total
- * hoser (like flex itself) wants to
- * call the scanner after we return the
- * YY_NULL, it'll still work - another
- * YY_NULL will get returned.
- */
- (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ;
-
- yy_act = YY_STATE_EOF(YY_START);
- goto do_action;
- }
-
- else
- {
- if ( ! (yy_did_buffer_switch_on_eof) )
- YY_NEW_FILE;
- }
- break;
- }
-
- case EOB_ACT_CONTINUE_SCAN:
- (yy_c_buf_p) =
- (yytext_ptr) + yy_amount_of_matched_text;
-
- yy_current_state = yy_get_previous_state( );
-
- yy_cp = (yy_c_buf_p);
- yy_bp = (yytext_ptr) + YY_MORE_ADJ;
- goto yy_match;
-
- case EOB_ACT_LAST_MATCH:
- (yy_c_buf_p) =
- &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)];
-
- yy_current_state = yy_get_previous_state( );
-
- yy_cp = (yy_c_buf_p);
- yy_bp = (yytext_ptr) + YY_MORE_ADJ;
- goto yy_find_action;
- }
- break;
- }
-
- default:
- YY_FATAL_ERROR(
- "fatal flex scanner internal error--no action found" );
- } /* end of action switch */
- } /* end of scanning one token */
- } /* end of user's declarations */
-} /* end of yylex */
-
-/* yy_get_next_buffer - try to read in a new buffer
- *
- * Returns a code representing an action:
- * EOB_ACT_LAST_MATCH -
- * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
- * EOB_ACT_END_OF_FILE - end of file
- */
-static int yy_get_next_buffer (void)
-{
- char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
- char *source = (yytext_ptr);
- int number_to_move, i;
- int ret_val;
-
- if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] )
- YY_FATAL_ERROR(
- "fatal flex scanner internal error--end of buffer missed" );
-
- if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
- { /* Don't try to fill the buffer, so this is an EOF. */
- if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 )
- {
- /* We matched a single character, the EOB, so
- * treat this as a final EOF.
- */
- return EOB_ACT_END_OF_FILE;
- }
-
- else
- {
- /* We matched some text prior to the EOB, first
- * process it.
- */
- return EOB_ACT_LAST_MATCH;
- }
- }
-
- /* Try to read more data. */
-
- /* First move last chars to start of buffer. */
- number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr) - 1);
-
- for ( i = 0; i < number_to_move; ++i )
- *(dest++) = *(source++);
-
- if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
- /* don't do the read, it's not guaranteed to return an EOF,
- * just force an EOF
- */
- YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0;
-
- else
- {
- int num_to_read =
- YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
-
- while ( num_to_read <= 0 )
- { /* Not enough room in the buffer - grow it. */
-
- /* just a shorter name for the current buffer */
- YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
-
- int yy_c_buf_p_offset =
- (int) ((yy_c_buf_p) - b->yy_ch_buf);
-
- if ( b->yy_is_our_buffer )
- {
- int new_size = b->yy_buf_size * 2;
-
- if ( new_size <= 0 )
- b->yy_buf_size += b->yy_buf_size / 8;
- else
- b->yy_buf_size *= 2;
-
- b->yy_ch_buf = (char *)
- /* Include room in for 2 EOB chars. */
- yyrealloc( (void *) b->yy_ch_buf,
- (yy_size_t) (b->yy_buf_size + 2) );
- }
- else
- /* Can't grow it, we don't own it. */
- b->yy_ch_buf = NULL;
-
- if ( ! b->yy_ch_buf )
- YY_FATAL_ERROR(
- "fatal error - scanner input buffer overflow" );
-
- (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset];
-
- num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
- number_to_move - 1;
-
- }
-
- if ( num_to_read > YY_READ_BUF_SIZE )
- num_to_read = YY_READ_BUF_SIZE;
-
- /* Read in more data. */
- YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
- (yy_n_chars), num_to_read );
-
- YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
- }
-
- if ( (yy_n_chars) == 0 )
- {
- if ( number_to_move == YY_MORE_ADJ )
- {
- ret_val = EOB_ACT_END_OF_FILE;
- yyrestart( yyin );
- }
-
- else
- {
- ret_val = EOB_ACT_LAST_MATCH;
- YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
- YY_BUFFER_EOF_PENDING;
- }
- }
-
- else
- ret_val = EOB_ACT_CONTINUE_SCAN;
-
- if (((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
- /* Extend the array by 50%, plus the number we really need. */
- int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1);
- YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc(
- (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size );
- if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
- YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
- /* "- 2" to take care of EOB's */
- YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2);
- }
-
- (yy_n_chars) += number_to_move;
- YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR;
- YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR;
-
- (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
-
- return ret_val;
-}
-
-/* yy_get_previous_state - get the state just before the EOB char was reached */
-
- static yy_state_type yy_get_previous_state (void)
-{
- yy_state_type yy_current_state;
- char *yy_cp;
-
- yy_current_state = (yy_start);
-
- for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
- {
- YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
- if ( yy_accept[yy_current_state] )
- {
- (yy_last_accepting_state) = yy_current_state;
- (yy_last_accepting_cpos) = yy_cp;
- }
- while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
- {
- yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 196 )
- yy_c = yy_meta[yy_c];
- }
- yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
- }
-
- return yy_current_state;
-}
-
-/* yy_try_NUL_trans - try to make a transition on the NUL character
- *
- * synopsis
- * next_state = yy_try_NUL_trans( current_state );
- */
- static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state )
-{
- int yy_is_jam;
- char *yy_cp = (yy_c_buf_p);
-
- YY_CHAR yy_c = 1;
- if ( yy_accept[yy_current_state] )
- {
- (yy_last_accepting_state) = yy_current_state;
- (yy_last_accepting_cpos) = yy_cp;
- }
- while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
- {
- yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 196 )
- yy_c = yy_meta[yy_c];
- }
- yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
- yy_is_jam = (yy_current_state == 195);
-
- return yy_is_jam ? 0 : yy_current_state;
-}
-
-#ifndef YY_NO_UNPUT
-
- static void yyunput (int c, char * yy_bp )
-{
- char *yy_cp;
-
- yy_cp = (yy_c_buf_p);
-
- /* undo effects of setting up yytext */
- *yy_cp = (yy_hold_char);
-
- if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
- { /* need to shift things up to make room */
- /* +2 for EOB chars. */
- int number_to_move = (yy_n_chars) + 2;
- char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[
- YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2];
- char *source =
- &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move];
-
- while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
- *--dest = *--source;
-
- yy_cp += (int) (dest - source);
- yy_bp += (int) (dest - source);
- YY_CURRENT_BUFFER_LVALUE->yy_n_chars =
- (yy_n_chars) = (int) YY_CURRENT_BUFFER_LVALUE->yy_buf_size;
-
- if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
- YY_FATAL_ERROR( "flex scanner push-back overflow" );
- }
-
- *--yy_cp = (char) c;
-
- (yytext_ptr) = yy_bp;
- (yy_hold_char) = *yy_cp;
- (yy_c_buf_p) = yy_cp;
-}
-
-#endif
-
-#ifndef YY_NO_INPUT
-#ifdef __cplusplus
- static int yyinput (void)
-#else
- static int input (void)
-#endif
-
-{
- int c;
-
- *(yy_c_buf_p) = (yy_hold_char);
-
- if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR )
- {
- /* yy_c_buf_p now points to the character we want to return.
- * If this occurs *before* the EOB characters, then it's a
- * valid NUL; if not, then we've hit the end of the buffer.
- */
- if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
- /* This was really a NUL. */
- *(yy_c_buf_p) = '\0';
-
- else
- { /* need more input */
- int offset = (int) ((yy_c_buf_p) - (yytext_ptr));
- ++(yy_c_buf_p);
-
- switch ( yy_get_next_buffer( ) )
- {
- case EOB_ACT_LAST_MATCH:
- /* This happens because yy_g_n_b()
- * sees that we've accumulated a
- * token and flags that we need to
- * try matching the token before
- * proceeding. But for input(),
- * there's no matching to consider.
- * So convert the EOB_ACT_LAST_MATCH
- * to EOB_ACT_END_OF_FILE.
- */
-
- /* Reset buffer status. */
- yyrestart( yyin );
-
- /*FALLTHROUGH*/
-
- case EOB_ACT_END_OF_FILE:
- {
- if ( yywrap( ) )
- return 0;
-
- if ( ! (yy_did_buffer_switch_on_eof) )
- YY_NEW_FILE;
-#ifdef __cplusplus
- return yyinput();
-#else
- return input();
-#endif
- }
-
- case EOB_ACT_CONTINUE_SCAN:
- (yy_c_buf_p) = (yytext_ptr) + offset;
- break;
- }
- }
- }
-
- c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */
- *(yy_c_buf_p) = '\0'; /* preserve yytext */
- (yy_hold_char) = *++(yy_c_buf_p);
-
- return c;
-}
-#endif /* ifndef YY_NO_INPUT */
-
-/** Immediately switch to a different input stream.
- * @param input_file A readable stream.
- *
- * @note This function does not reset the start condition to @c INITIAL .
- */
- void yyrestart (FILE * input_file )
-{
-
- if ( ! YY_CURRENT_BUFFER ){
- yyensure_buffer_stack ();
- YY_CURRENT_BUFFER_LVALUE =
- yy_create_buffer( yyin, YY_BUF_SIZE );
- }
-
- yy_init_buffer( YY_CURRENT_BUFFER, input_file );
- yy_load_buffer_state( );
-}
-
-/** Switch to a different input buffer.
- * @param new_buffer The new input buffer.
- *
- */
- void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer )
-{
-
- /* TODO. We should be able to replace this entire function body
- * with
- * yypop_buffer_state();
- * yypush_buffer_state(new_buffer);
- */
- yyensure_buffer_stack ();
- if ( YY_CURRENT_BUFFER == new_buffer )
- return;
-
- if ( YY_CURRENT_BUFFER )
- {
- /* Flush out information for old buffer. */
- *(yy_c_buf_p) = (yy_hold_char);
- YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
- YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
- }
-
- YY_CURRENT_BUFFER_LVALUE = new_buffer;
- yy_load_buffer_state( );
-
- /* We don't actually know whether we did this switch during
- * EOF (yywrap()) processing, but the only time this flag
- * is looked at is after yywrap() is called, so it's safe
- * to go ahead and always set it.
- */
- (yy_did_buffer_switch_on_eof) = 1;
-}
-
-static void yy_load_buffer_state (void)
-{
- (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
- (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
- yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
- (yy_hold_char) = *(yy_c_buf_p);
-}
-
-/** Allocate and initialize an input buffer state.
- * @param file A readable stream.
- * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
- *
- * @return the allocated buffer state.
- */
- YY_BUFFER_STATE yy_create_buffer (FILE * file, int size )
-{
- YY_BUFFER_STATE b;
-
- b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) );
- if ( ! b )
- YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
-
- b->yy_buf_size = size;
-
- /* yy_ch_buf has to be 2 characters longer than the size given because
- * we need to put in 2 end-of-buffer characters.
- */
- b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) );
- if ( ! b->yy_ch_buf )
- YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
-
- b->yy_is_our_buffer = 1;
-
- yy_init_buffer( b, file );
-
- return b;
-}
-
-/** Destroy the buffer.
- * @param b a buffer created with yy_create_buffer()
- *
- */
- void yy_delete_buffer (YY_BUFFER_STATE b )
-{
-
- if ( ! b )
- return;
-
- if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
- YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
-
- if ( b->yy_is_our_buffer )
- yyfree( (void *) b->yy_ch_buf );
-
- yyfree( (void *) b );
-}
-
-/* Initializes or reinitializes a buffer.
- * This function is sometimes called more than once on the same buffer,
- * such as during a yyrestart() or at EOF.
- */
- static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file )
-
-{
- int oerrno = errno;
-
- yy_flush_buffer( b );
-
- b->yy_input_file = file;
- b->yy_fill_buffer = 1;
-
- /* If b is the current buffer, then yy_init_buffer was _probably_
- * called from yyrestart() or through yy_get_next_buffer.
- * In that case, we don't want to reset the lineno or column.
- */
- if (b != YY_CURRENT_BUFFER){
- b->yy_bs_lineno = 1;
- b->yy_bs_column = 0;
- }
-
- b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
-
- errno = oerrno;
-}
-
-/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
- * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
- *
- */
- void yy_flush_buffer (YY_BUFFER_STATE b )
-{
- if ( ! b )
- return;
-
- b->yy_n_chars = 0;
-
- /* We always need two end-of-buffer characters. The first causes
- * a transition to the end-of-buffer state. The second causes
- * a jam in that state.
- */
- b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
- b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
-
- b->yy_buf_pos = &b->yy_ch_buf[0];
-
- b->yy_at_bol = 1;
- b->yy_buffer_status = YY_BUFFER_NEW;
-
- if ( b == YY_CURRENT_BUFFER )
- yy_load_buffer_state( );
-}
-
-/** Pushes the new state onto the stack. The new state becomes
- * the current state. This function will allocate the stack
- * if necessary.
- * @param new_buffer The new state.
- *
- */
-void yypush_buffer_state (YY_BUFFER_STATE new_buffer )
-{
- if (new_buffer == NULL)
- return;
-
- yyensure_buffer_stack();
-
- /* This block is copied from yy_switch_to_buffer. */
- if ( YY_CURRENT_BUFFER )
- {
- /* Flush out information for old buffer. */
- *(yy_c_buf_p) = (yy_hold_char);
- YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
- YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
- }
-
- /* Only push if top exists. Otherwise, replace top. */
- if (YY_CURRENT_BUFFER)
- (yy_buffer_stack_top)++;
- YY_CURRENT_BUFFER_LVALUE = new_buffer;
-
- /* copied from yy_switch_to_buffer. */
- yy_load_buffer_state( );
- (yy_did_buffer_switch_on_eof) = 1;
-}
-
-/** Removes and deletes the top of the stack, if present.
- * The next element becomes the new top.
- *
- */
-void yypop_buffer_state (void)
-{
- if (!YY_CURRENT_BUFFER)
- return;
-
- yy_delete_buffer(YY_CURRENT_BUFFER );
- YY_CURRENT_BUFFER_LVALUE = NULL;
- if ((yy_buffer_stack_top) > 0)
- --(yy_buffer_stack_top);
-
- if (YY_CURRENT_BUFFER) {
- yy_load_buffer_state( );
- (yy_did_buffer_switch_on_eof) = 1;
- }
-}
-
-/* Allocates the stack if it does not exist.
- * Guarantees space for at least one push.
- */
-static void yyensure_buffer_stack (void)
-{
- yy_size_t num_to_alloc;
-
- if (!(yy_buffer_stack)) {
-
- /* First allocation is just for 2 elements, since we don't know if this
- * scanner will even need a stack. We use 2 instead of 1 to avoid an
- * immediate realloc on the next call.
- */
- num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */
- (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc
- (num_to_alloc * sizeof(struct yy_buffer_state*)
- );
- if ( ! (yy_buffer_stack) )
- YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
-
- memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
-
- (yy_buffer_stack_max) = num_to_alloc;
- (yy_buffer_stack_top) = 0;
- return;
- }
-
- if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){
-
- /* Increase the buffer to prepare for a possible push. */
- yy_size_t grow_size = 8 /* arbitrary grow size */;
-
- num_to_alloc = (yy_buffer_stack_max) + grow_size;
- (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc
- ((yy_buffer_stack),
- num_to_alloc * sizeof(struct yy_buffer_state*)
- );
- if ( ! (yy_buffer_stack) )
- YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
-
- /* zero only the new slots.*/
- memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*));
- (yy_buffer_stack_max) = num_to_alloc;
- }
-}
-
-/** Setup the input buffer state to scan directly from a user-specified character buffer.
- * @param base the character buffer
- * @param size the size in bytes of the character buffer
- *
- * @return the newly allocated buffer state object.
- */
-YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size )
-{
- YY_BUFFER_STATE b;
-
- if ( size < 2 ||
- base[size-2] != YY_END_OF_BUFFER_CHAR ||
- base[size-1] != YY_END_OF_BUFFER_CHAR )
- /* They forgot to leave room for the EOB's. */
- return NULL;
-
- b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) );
- if ( ! b )
- YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
-
- b->yy_buf_size = (int) (size - 2); /* "- 2" to take care of EOB's */
- b->yy_buf_pos = b->yy_ch_buf = base;
- b->yy_is_our_buffer = 0;
- b->yy_input_file = NULL;
- b->yy_n_chars = b->yy_buf_size;
- b->yy_is_interactive = 0;
- b->yy_at_bol = 1;
- b->yy_fill_buffer = 0;
- b->yy_buffer_status = YY_BUFFER_NEW;
-
- yy_switch_to_buffer( b );
-
- return b;
-}
-
-/** Setup the input buffer state to scan a string. The next call to yylex() will
- * scan from a @e copy of @a str.
- * @param yystr a NUL-terminated string to scan
- *
- * @return the newly allocated buffer state object.
- * @note If you want to scan bytes that may contain NUL values, then use
- * yy_scan_bytes() instead.
- */
-YY_BUFFER_STATE yy_scan_string (const char * yystr )
-{
-
- return yy_scan_bytes( yystr, (int) strlen(yystr) );
-}
-
-/** Setup the input buffer state to scan the given bytes. The next call to yylex() will
- * scan from a @e copy of @a bytes.
- * @param yybytes the byte buffer to scan
- * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
- *
- * @return the newly allocated buffer state object.
- */
-YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len )
-{
- YY_BUFFER_STATE b;
- char *buf;
- yy_size_t n;
- int i;
-
- /* Get memory for full buffer, including space for trailing EOB's. */
- n = (yy_size_t) (_yybytes_len + 2);
- buf = (char *) yyalloc( n );
- if ( ! buf )
- YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
-
- for ( i = 0; i < _yybytes_len; ++i )
- buf[i] = yybytes[i];
-
- buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
-
- b = yy_scan_buffer( buf, n );
- if ( ! b )
- YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
-
- /* It's okay to grow etc. this buffer, and we should throw it
- * away when we're done.
- */
- b->yy_is_our_buffer = 1;
-
- return b;
-}
-
-#ifndef YY_EXIT_FAILURE
-#define YY_EXIT_FAILURE 2
-#endif
-
-static void yynoreturn yy_fatal_error (const char* msg )
-{
- fprintf( stderr, "%s\n", msg );
- exit( YY_EXIT_FAILURE );
-}
-
-/* Redefine yyless() so it works in section 3 code. */
-
-#undef yyless
-#define yyless(n) \
- do \
- { \
- /* Undo effects of setting up yytext. */ \
- int yyless_macro_arg = (n); \
- YY_LESS_LINENO(yyless_macro_arg);\
- yytext[yyleng] = (yy_hold_char); \
- (yy_c_buf_p) = yytext + yyless_macro_arg; \
- (yy_hold_char) = *(yy_c_buf_p); \
- *(yy_c_buf_p) = '\0'; \
- yyleng = yyless_macro_arg; \
- } \
- while ( 0 )
-
-/* Accessor methods (get/set functions) to struct members. */
-
-/** Get the current line number.
- *
- */
-int yyget_lineno (void)
-{
-
- return yylineno;
-}
-
-/** Get the input stream.
- *
- */
-FILE *yyget_in (void)
-{
- return yyin;
-}
-
-/** Get the output stream.
- *
- */
-FILE *yyget_out (void)
-{
- return yyout;
-}
-
-/** Get the length of the current token.
- *
- */
-int yyget_leng (void)
-{
- return yyleng;
-}
-
-/** Get the current token.
- *
- */
-
-char *yyget_text (void)
-{
- return yytext;
-}
-
-/** Set the current line number.
- * @param _line_number line number
- *
- */
-void yyset_lineno (int _line_number )
-{
-
- yylineno = _line_number;
-}
-
-/** Set the input stream. This does not discard the current
- * input buffer.
- * @param _in_str A readable stream.
- *
- * @see yy_switch_to_buffer
- */
-void yyset_in (FILE * _in_str )
-{
- yyin = _in_str ;
-}
-
-void yyset_out (FILE * _out_str )
-{
- yyout = _out_str ;
-}
-
-int yyget_debug (void)
-{
- return yy_flex_debug;
-}
-
-void yyset_debug (int _bdebug )
-{
- yy_flex_debug = _bdebug ;
-}
-
-static int yy_init_globals (void)
-{
- /* Initialization is the same as for the non-reentrant scanner.
- * This function is called from yylex_destroy(), so don't allocate here.
- */
-
- (yy_buffer_stack) = NULL;
- (yy_buffer_stack_top) = 0;
- (yy_buffer_stack_max) = 0;
- (yy_c_buf_p) = NULL;
- (yy_init) = 0;
- (yy_start) = 0;
-
-/* Defined in main.c */
-#ifdef YY_STDINIT
- yyin = stdin;
- yyout = stdout;
-#else
- yyin = NULL;
- yyout = NULL;
-#endif
-
- /* For future reference: Set errno on error, since we are called by
- * yylex_init()
- */
- return 0;
-}
-
-/* yylex_destroy is for both reentrant and non-reentrant scanners. */
-int yylex_destroy (void)
-{
-
- /* Pop the buffer stack, destroying each element. */
- while(YY_CURRENT_BUFFER){
- yy_delete_buffer( YY_CURRENT_BUFFER );
- YY_CURRENT_BUFFER_LVALUE = NULL;
- yypop_buffer_state();
- }
-
- /* Destroy the stack itself. */
- yyfree((yy_buffer_stack) );
- (yy_buffer_stack) = NULL;
-
- /* Reset the globals. This is important in a non-reentrant scanner so the next time
- * yylex() is called, initialization will occur. */
- yy_init_globals( );
-
- return 0;
-}
-
-/*
- * Internal utility routines.
- */
-
-#ifndef yytext_ptr
-static void yy_flex_strncpy (char* s1, const char * s2, int n )
-{
-
- int i;
- for ( i = 0; i < n; ++i )
- s1[i] = s2[i];
-}
-#endif
-
-#ifdef YY_NEED_STRLEN
-static int yy_flex_strlen (const char * s )
-{
- int n;
- for ( n = 0; s[n]; ++n )
- ;
-
- return n;
-}
-#endif
-
-void *yyalloc (yy_size_t size )
-{
- return malloc(size);
-}
-
-void *yyrealloc (void * ptr, yy_size_t size )
-{
-
- /* The cast to (char *) in the following accommodates both
- * implementations that use char* generic pointers, and those
- * that use void* generic pointers. It works with the latter
- * because both ANSI C and C++ allow castless assignment from
- * any pointer type to void*, and deal with argument conversions
- * as though doing an assignment.
- */
- return realloc(ptr, size);
-}
-
-void yyfree (void * ptr )
-{
- free( (char *) ptr ); /* see yyrealloc() for (char *) cast */
-}
-
-#define YYTABLES_NAME "yytables"
-
-#line 143 "Pascal.l"
-
-void updatePos(void) {
- EM_tokPos = charPos;
- charPos += yyleng;
-}
-int yywrap(){
- charPos = 1;
- return 1;
-}
diff --git a/src/main.c b/src/main.c
deleted file mode 100644
index 2afa079..0000000
--- a/src/main.c
+++ /dev/null
@@ -1,27 +0,0 @@
-// tree root from paring
-#include "absyn.h"
-#include "prabsyn.h"
-#include "errormsg.h"
-#include
-
-extern A_exp A_synTreeRoot;
-extern int yyparse(void);
-
-int parse(string fname) {
- // reset filename and line number
- // open given file in the same time
- EM_reset(fname);
- int res = yyparse();
- if (!res) {
- } else {
- printf("Syntax not passed! Please check your syntax.\n");
- }
- // restore stdin
- fclose(stdin);
- return res;
-}
-
-int main(int argc, char* argv[]) {
- parse(argv[1]);
- pr_exp(stdout, A_synTreeRoot, 0);
-}
\ No newline at end of file
diff --git a/src/pascalc.exe b/src/pascalc.exe
deleted file mode 100644
index 2170db3..0000000
Binary files a/src/pascalc.exe and /dev/null differ
diff --git a/src/pascalc.exe.stackdump b/src/pascalc.exe.stackdump
deleted file mode 100644
index 13046e2..0000000
--- a/src/pascalc.exe.stackdump
+++ /dev/null
@@ -1,19 +0,0 @@
-Stack trace:
-Frame Function Args
-000FFFFC380 0018005CF5C (00000000000, 00000000004, 00600000001, 000FFFFDE50)
-000FFFFC420 0018005E56B (00000000064, 00000000000, 00000000000, 00000000000)
-000FFFFC670 0018012132D (00000000000, 00040100080, 00000000000, 000FFFFFE22)
-00180010000 0018011DB0E (00000000080, 00000000000, 00000000000, 00002000000)
-000FFFFCAD0 0018011DFC2 (00000000000, 00000000000, 00000000000, 00000000006)
-000FFFFCAD0 0018011E20A (7FF9826722F2, 00000004048, 0018021F088, 0018012306C)
-000FFFFCAD0 0018011E4CF (0010040C160, 0010040C162, 000000000DA, 0018021F00F)
-000FFFFCAD0 00180041422 (00000000004, 00180201870, 0048018619A, 000FFFFCB30)
-000FFFFCB00 00100403B9C (0060005CBE0, 00100000004, 0018013FF20, 000FFFFCB60)
-000FFFFCB30 00100404100 (0060005CC10, 00100000003, 0018013FF20, 000FFFFCB90)
-000FFFFCB60 00100404138 (0060005C710, 00100000002, 0018011973B, 000FFFFCBC0)
-000FFFFCB90 00100404138 (0060005C760, 00100000001, 000FFFFCC50, 000FFFFCC50)
-000FFFFCBC0 00100403824 (0060005F2D0, 00000000000, 00000000000, 00000000000)
-000FFFFCC50 0010040118D (000FFFFCC50, 30001010000FF00, 00180047941, 00180046980)
-000FFFFCCB0 001800479B2 (00000000000, 00000000000, 00000000000, 00000000000)
-00000000000 00180045653 (00000000000, 00000000000, 00000000000, 00000000000)
-End of stack trace (more stack frames may be present)
diff --git a/src/semant.c b/src/semant.c
deleted file mode 100644
index 8df3424..0000000
--- a/src/semant.c
+++ /dev/null
@@ -1,821 +0,0 @@
-// #include
-// #include
-// #include
-// #include "util.h"
-// #include "errormsg.h"
-// #include "symbol.h"
-// #include "absyn.h"
-// #include "types.h"
-// #include "temp.h"
-// #include "tree.h"
-// #include "frame.h"
-// #include "env.h"
-// #include "semant.h"
-// #include "printtree.h"
-
-// extern bool anyErrors;
-// static A_fundec nowCheckFun = NULL;
-
-// F_fragList transProg(A_exp exp)
-// {
-// struct expty exptype;
-// S_table basefunenv=Base_funenv();
-// S_table basevarenv=Base_varenv();
-// exptype=transExp(Tr_outermost(),NULL,basefunenv,basevarenv,exp);
-// printf("Expression with return type: %d\n",exptype.ty->flag);
-// F_fragList ret=Tr_getResult();
-
-// return ret;
-// }
-
-// struct expty Newexpty(Tr_exp e, Type t)
-// {
-// struct expty et;
-// et.exp = e;
-// et.ty = t;
-// return et;
-// }
-// static U_boolList makeFormals(A_fieldList params)
-// {
-// U_boolList head = NULL, tail = NULL;
-// A_fieldList p = params;
-// for (; p; p = p->tail) {
-// if (head) {
-// tail->tail = U_BoolList(TRUE, NULL);
-// tail = tail->tail;
-// } else {
-// head = U_BoolList(TRUE, NULL);
-// tail = head;
-// }
-// }
-// return head;
-// }
-// static Typelist gettypelist(S_table varenv,A_fieldList list)
-// {
-// Typelist head=NULL;
-// Typelist tail=NULL;
-// A_fieldList ptr=list;
-// Type tmpty;
-
-// while(ptr)
-// {
-// tmpty=S_look(varenv,ptr->head->typ);
-// if(!tmpty)
-// {
-// EM_error(ptr->head->pos,"Type %s undefined\n",S_name(ptr->head->typ));
-// tmpty=INT_type();
-// }
-// if(!head)//head==NULL
-// head=tail=Newtypelist(tmpty,NULL);
-// else
-// {
-// tail->next=Newtypelist(tmpty,NULL);
-// tail=tail->next;
-// }
-// ptr=ptr->tail;
-// }
-// return head;
-// }
-
-// Type gettype(Type ty)
-// {
-// if(!ty)
-// return NULL;
-// else if(ty->flag==NAME)
-// gettype(ty->u.name.ty);
-// else
-// return ty;
-// }
-
-// static Fieldlist getfieldlist(S_table varenv,A_fieldList list)
-// {
-// Fieldlist head=NULL;
-// Fieldlist tail=NULL;
-// A_fieldList ptr=list;
-// Type tmpty;
-// Field tmpfd;
-
-// while(ptr)
-// {
-// tmpty=S_look(varenv,ptr->head->typ);
-// if(!tmpty)
-// EM_error(ptr->head->pos,"Type %s undefined\n",S_name(ptr->head->typ));
-// else
-// {
-// tmpfd=Newfield(ptr->head->name,tmpty);
-// if(!head)
-// head=tail=Newfieldlist(tmpfd,NULL);
-// else
-// {
-// tail->next=Newfieldlist(tmpfd,NULL);
-// tail=tail->next;
-// }
-// }
-// }
-// return head;
-// }
-// static struct expty transVar(Tr_level l,Tr_exp e,S_table funenv,S_table varenv,A_var var)
-// {
-// if(!var)
-// return Newexpty(Tr_NoExp(), VOID_type());
-// Environments env;
-// struct expty pt1,pt2;
-// Fieldlist tmpfl;
-// Tr_exp trans;
-
-// if(var->kind==A_simpleVar)
-// {
-// env= (Environments)S_look(funenv,var->u.simple);
-// trans=Tr_NoExp();
-// //µ±Ç°ÊǼì²éº¯ÊýµÄʱºò,º¯ÊýÃû¶ÔÓ¦ÄÚÈÝÒ²Òª·µ»Ø
-// if(env && (env->flag==VAR||env->flag == CONST))
-// {
-// trans=Tr_SimpleVar(env->u.var.acc,l);
-// struct expty temExp = Newexpty(trans,gettype(env->u.var.ty));
-// if(env->flag == CONST)
-// temExp.isConst = 1;
-// else temExp.isConst = 0;
-// return temExp;
-// }
-// //½öÓÃÓÚº¯Êý·µ»ØÖµÀàÐͼì²é
-// else if(env&&env->flag == FUN&&nowCheckFun&&checkEqSymbol(nowCheckFun->name, var->u.simple))
-// {
-// return Newexpty(NULL, gettype(env->u.fun.output));
-// }
-// else
-// {
-// EM_error(var->pos,"Variable %s undefined\n",S_name(var->u.simple));
-// return Newexpty(trans,INT_type());
-// }
-// }
-// else if(var->kind==A_fieldVar)
-// {
-// //½«x.yÖеÄx°üװһϣ¬x±»¶¨ÒåΪsimpleVar£¬¿ÉÒÔ´Ó·ûºÅ±íÖвéÕÒ³öfieldlist¡£
-// pt1=transVar(l,e,funenv,varenv,var->u.field.var);
-// trans=Tr_NoExp();
-// if(pt1.ty->flag!=RECORD)
-// {
-// EM_error(var->pos,"Expected a record type\n");
-// return Newexpty(trans,INT_type());
-// }
-// else
-// {
-// int i=0;
-// for(tmpfl=pt1.ty->u.record;tmpfl;tmpfl=tmpfl->next,i++)
-// if(tmpfl->head->name==var->u.field.sym)
-// {
-// //有点小问题,等会再查
-// trans=Tr_FieldVar(pt1.exp,i);
-// return Newexpty(trans,gettype(tmpfl->head->ty));
-// }
-// EM_error(var->pos,"Field %s not found\n",S_name(var->u.field.sym)); //not fount in record
-// return Newexpty(trans,INT_type());
-// }
-// }
-// else if(var->kind==A_subscriptVar)
-// {
-// pt1=transVar(l,e,funenv,varenv,var->u.subscript.var);
-// trans=Tr_NoExp();
-// if(pt1.ty->flag!=ARRAY)
-// {
-// EM_error(var->pos,"Expected an array type\n");
-// return Newexpty(trans,INT_type());
-// }
-// else
-// {
-// pt2=transExp(l,e,funenv,varenv,var->u.subscript.exp);
-
-// if(pt2.ty->flag==INT||pt2.ty->flag == CHAR)
-// {
-// trans=Tr_SubscriptVar(pt1.exp,pt2.exp);
-// return Newexpty(trans,gettype(pt1.ty->u.arrayInfo->ty));
-// }
-// else if(pt2.ty->flag == ENUM)
-// {
-// //´¦ÀítransExpºóÔÙд£¨ÐèÒª»ñÈ¡EnumµÄÀàÐÍ£¬»¹Óе±Ç°Êǵڼ¸¸ö£©
-// }
-// else
-// {
-// EM_error(var->pos,"Index must be an interger\n");
-// return Newexpty(trans,INT_type());
-// }
-// }
-// }
-// //else ERROR
-// printf("Transvar inner error!\n");
-// exit(1);
-// }
-
-// static struct expty transExp(Tr_level l,Tr_exp e,S_table funenv,S_table varenv,A_exp exp)
-// {
-// if(!exp)
-// return Newexpty(Tr_NoExp(), VOID_type());
-// if(exp->kind==A_varExp)
-// return transVar(l,e,funenv,varenv,exp->u.var);
-// //有问题,最后在处理
-// // else if(exp->kind==A_nilExp)
-// // return Newexpty(nilExp(),NIL_type());
-// else if(exp->kind==A_stringExp)
-// return Newexpty(Tr_StringExp(255 ,exp->u.stringg),STRING_type());
-// else if(exp->kind==A_intExp)
-// return Newexpty(Tr_IntExp(exp->u.intt),INT_type());
-// else if(exp->kind==A_realExp)
-// return Newexpty(Tr_RealExp(exp->u.real),REAL_type());
-// else if(exp->kind==A_charExp)
-// return Newexpty(Tr_CharExp(exp->u.charr),CHAR_type());
-// else if(exp->kind==A_recordExp)
-// {
-// A_efieldList itemList =exp->u.record.fields;
-// int n = 0;
-// Tr_expList fields = NULL;
-// Type recordTy;
-// recordTy = gettype(S_look(varenv, exp->u.record.typ));
-// if(!recordTy)
-// EM_error(exp->pos,"Type %s undefined\n",S_name(exp->u.record.typ));
-// else{
-// if(recordTy->flag!=RECORD)
-// {
-// EM_error(exp->pos,"Record type expected, get %s\n",S_name(exp->u.record.typ));
-// return Newexpty(Tr_NoExp(),RECORD_type(NULL));
-// }
-// Fieldlist fieldTyList = recordTy->u.record;
-// for(itemList; itemList; itemList = itemList->tail, fieldTyList = fieldTyList->next, n++){
-// struct expty et = transExp(l, e, funenv, varenv, itemList->head->exp);
-// if (itemList->head->name != fieldTyList->head->name)
-// EM_error(exp->pos, "%s not a valid field name", itemList->head->name);
-// if (!type_match(fieldTyList->head->ty, et.ty))
-// EM_error(itemList->head->exp->pos, "Type mismatch");
-
-// //½«Tr_expÁ¬½ÓÆðÀ´
-// // Tr_explistnewhead(et.exp, &fields);
-// fields = Tr_ExpList(et.exp, fields);
-
-// }
-// return Newexpty(Tr_RecordExp(n, fields), recordTy);
-// }
-// return Newexpty(Tr_NoExp(),RECORD_type(NULL));
-// }
-// //Êý×黹ûÓж¨ÒåºÃ£¬µÈ¶¨ÒåºÃÁË£¬ÔÙд
-// //µÈÐ޸ĺÃabsynºóÔÙ´¦Àí
-// // else if(exp->kind==A_booleanExp) ¶ÔbooleanÐ͵ÄÖ§³Ö£¬»¹ÒªÔÙ¿´¿´
-// // return Newexpty(booleanExp(exp->u.charr),CHAR_type());
-// else if(exp->kind==A_breakExp)
-// {
-// if(!e)
-// return Newexpty(Tr_NoExp(),VOID_type());
-// return Newexpty(Tr_BreakExp(e),VOID_type());
-// }
-// else if(exp->kind==A_callExp)
-// {
-// Environments callinfo;
-// A_expList params=NULL;
-// Tr_expList paramlist=NULL;
-// Typelist fmls;
-// callinfo=S_look(funenv,exp->u.call.func);
-// Tr_exp trans=Tr_NoExp();
-// if(callinfo && callinfo->flag==FUN)
-// {
-// fmls=callinfo->u.fun.param;
-// //½«²ÎÊý´¦ÀíºÃºó·ÅÈëµ½Tr_explistÖÐ
-// for(params=exp->u.call.args;params&&fmls;params=params->tail,fmls=fmls->next)
-// {
-// struct expty arg=transExp(l,e,funenv,varenv,params->head);
-// if(!type_match(arg.ty,fmls->head))
-// EM_error(params->head->pos,"Function %s type mismatch\n",S_name(exp->u.call.func));
-// // Tr_explistnewhead(arg.exp,¶mlist);
-// paramlist = Tr_ExpList(arg.exp, paramlist);
-// }
-
-// if(!params&&fmls)
-// EM_error(exp->pos,"Too few parameters");
-// if(params&&!fmls)
-// EM_error(exp->pos,"Too many parameters");
-
-// //°ü×°³ÉT_expµÄÐÎʽ
-// trans=Tr_CallExp(callinfo->u.fun.label,callinfo->u.fun.lev,l,¶mlist);
-// return Newexpty(trans,gettype(callinfo->u.fun.output));
-// }
-// else
-// {
-// EM_error(exp->pos, "Function name %s undefined\n");
-// return Newexpty(trans, INT_type());
-// }
-// }
-// /* ²»ÐèÒªÕâÖÖÓï¾ä
-// else if(exp->kind==A_recordExp)
-// {
-// Type rectp;
-// rectp=gettype(S_look(varenv,exp->u.record.typ));
-// if(!rectp)
-// EM_error(exp->pos,"Type %s undefined\n",S_name(exp->u.record.typ));
-// else
-// {
-// if(rectp->flag!=RECORD)
-// {
-// EM_error(exp->pos,"Record type expected, get %s\n",S_name(exp->u.record.typ));
-// return Newexpty(Tr_NoExp(),RECORD_type(NULL));
-// }
-// Fieldlist fieldTys = rectp->u.record;
-// A_efieldList recList;
-// Tr_explist list = NULL;
-// int n = 0;
-// //±éÀúrecordÖеÄÿһ¸öÔªËØ£¬recListÖаüº¬Ã¿Ò»¸ö±äÁ¿Ãû¼°¸³Öµexp
-// for (recList = exp->u.record.fields; recList; recList = recList->tail, fieldTys = fieldTys->next, n++)
-// {
-// struct expty et = transExp(l,e,funenv,varenv, recList->head->exp);
-// if (recList->head->name != fieldTys->head->name)
-// EM_error(exp->pos, "%s not a valid field name", recList->head->name);
-// if (!type_match(fieldTys->head->ty, et.ty))
-// EM_error(recList->head->exp->pos, "Type mismatch");
-
-// //½«Tr_expÁ¬½ÓÆðÀ´
-// Tr_explistnewhead(et.exp, &list);
-// }
-// return Newexpty(recordExp(n, list), rectp);
-// }
-// return Newexpty(Tr_NoExp(),RECORD_type(NULL));
-// }
-// */
-// //ÐèÒªÐ޸쬵ÈabsynÐ޸ĺÃÖ®ºó£¬ÔÙ´¦Àí
-// else if(exp->kind==A_arrayExp)
-// {
-// Type artp;
-// Type finaltp;
-// artp = S_look(varenv, exp->u.array.typ);
-// printf("\n");
-// if (artp->flag == NAME)
-// finaltp=artp->u.name.ty;
-// else
-// finaltp= artp;
-// //finaltp = gettype(artp);
-// if(!finaltp)
-// {
-// EM_error(exp->pos,"Array type %s undefined\n",S_name(exp->u.array.typ));
-// return Newexpty(Tr_NoExp(),INT_type());
-// }
-// else if(finaltp->flag!=ARRAY)
-// {
-// EM_error(exp->pos,"Array type expected, get %s\n",S_name(exp->u.array.typ));
-// return Newexpty(Tr_NoExp(),INT_type());
-// }
-
-// struct expty size,init;
-// size=transExp(l,e,funenv,varenv,exp->u.array.size);
-// init=transExp(l,e,funenv,varenv,exp->u.array.init);
-// if(size.ty->flag!=INT && size.ty->flag!=CHAR)
-// EM_error(exp->pos,"Array %s size must be an interger or char.\n",exp->u.array.typ);
-// else if(!type_match(init.ty, finaltp))
-// EM_error(exp->pos,"Array %s type mismatch\n",exp->u.array.typ);
-// else
-// return Newexpty(Tr_ArrayExp(size.exp,init.exp),artp);
-// return Newexpty(Tr_NoExp(),INT_type());
-// }
-// else if(exp->kind==A_seqExp)
-// {
-// Tr_expList lis=NULL;
-// A_expList explist;
-// struct expty seq;
-// explist=exp->u.seq;
-// if(!explist)
-// return Newexpty(Tr_NoExp(),VOID_type());
-// while(explist->head)
-// {
-// seq=transExp(l,e,funenv,varenv,explist->head);
-// printf("\n");
-// Tr_explistnewhead(seq.exp,&lis);
-// if (explist->tail == NULL)
-// break;
-// explist=explist->tail;
-// }
-// return Newexpty(Tr_SeqExp(lis),seq.ty);
-// }
-// else if(exp->kind==A_whileExp)
-// {
-// struct expty cond;
-// cond=transExp(l,e,funenv,varenv,exp->u.whilee.test);
-// if(cond.ty->flag!=INT&&cond.ty->flag!=BOOLEAN)
-// {
-// EM_error(exp->pos,"Integer expected in while\n");
-// return Newexpty(Tr_NoExp(),INT_type());
-// }
-// // Tr_exp done=doneExp();
-// struct expty body=transExp(l,e,funenv,varenv,exp->u.whilee.body);
-// return Newexpty(Tr_WhileExp(cond.exp, body.exp),VOID_type());
-// }
-// else if(exp->kind==A_assignExp)
-// {
-// struct expty left,right;
-// left=transVar(l,e,funenv,varenv,exp->u.assign.var);
-// right=transExp(l,e,funenv,varenv,exp->u.assign.exp);
-// if(!type_match(left.ty,right.ty))
-// {
-// if(left.exp == NULL){//ÓÃÓÚº¯Êý·µ»ØÖµÀàÐͼì²é
-// EM_error(nowCheckFun->pos, "incorrect return type in function '%s'", S_name(nowCheckFun->name));
-// }
-// else if(left.isConst)
-// {
-// EM_error(exp->pos, "Don't assign to the const\n");
-// }
-// else
-// EM_error(exp->pos,"Assign type mismatch\n");
-// return Newexpty(Tr_NoExp(),INT_type());
-// }
-// return Newexpty(Tr_AssignExp(left.exp, right.exp),VOID_type());
-// }
-// //Óï·¨·ÖÎö½«forת»¯Îªwhile£¬´Ë´¦²»ÐèÒª´¦Àí
-// else if(exp->kind==A_forExp)
-// {
-
-// struct expty start,end,stm;
-// start=transExp(l,e,funenv,varenv,exp->u.forr.lo);
-// end=transExp(l,e,funenv,varenv,exp->u.forr.hi);
-// if(start.ty!=INT||end.ty!=INT)
-// EM_error(exp->pos,"Expected integer range type");
-// Typeprint(start.ty);
-// Typeprint(end.ty);
-// S_beginScope(funenv);
-// transDec(l,e,funenv,varenv,A_VarDec(exp->pos,exp->u.forr.var, S_Symbol("int"),exp->u.forr.lo));
-// stm=transExp(l,e,funenv,varenv,exp->u.forr.body);
-// S_endScope(funenv);
-
-// return Newexpty(Tr_NoExp(),VOID_type());
-// }
-// else if(exp->kind==A_letExp)
-// {
-// A_decList declist;
-// Tr_expList list = NULL;
-// struct expty body;
-// S_beginScope(funenv);
-// S_beginScope(varenv);
-// for(declist=exp->u.let.decs;declist;declist=declist->tail)
-// Tr_explistnewhead(transDec(l,e,funenv,varenv,declist->head),&list);
-// body=transExp(l,e,funenv,varenv,exp->u.let.body);
-// list = Tr_ExpList(body.exp, list);
-// // Tr_explistnewhead(body.exp,&list);
-// S_endScope(varenv);
-// S_endScope(funenv);
-// return Newexpty(Tr_SeqExp(list),body.ty);
-// }
-
-// else if(exp->kind==A_opExp)
-// {
-// struct expty left,right;
-// A_oper oper;
-// oper=exp->u.op.oper;
-// left=transExp(l,e,funenv,varenv,exp->u.op.left);
-// right=transExp(l,e,funenv,varenv,exp->u.op.right);
-// //¼Ó¼õ³Ë³ý
-// if(oper>=A_plusOp&&oper<=A_divideOp)
-// {
-// if(left.ty->flag!=INT&&left.ty->flag!=REAL)
-// EM_error(exp->u.op.left->pos,"Expected Integer or double left operand\n");
-// if(right.ty->flag!=INT&&right.ty->flag!=REAL)
-// EM_error(exp->u.op.right->pos,"Expected Integer or double right operand\n");
-
-// //³ý·¨È«²¿±äΪdoubleÀàÐÍ
-// if(left.ty->flag==INT&&right.ty->flag==INT&&oper!=A_divideOp)
-// return Newexpty(Tr_OpExp(oper, left.exp, right.exp),INT_type());
-// else
-// return Newexpty(Tr_OpExp(oper, left.exp, right.exp),REAL_type());
-// }
-// //µÈÓÚ²»µÈÓÚ£¬Ð¡ÓÚ£¬Ð¡ÓÚµÈÓÚ£¬´óÓÚ£¬´óÓÚµÈÓÚ
-// else if(oper>=A_eqOp&&oper<=A_geOp)
-// {
-// Tr_exp trans=Tr_NoExp();
-// if(oper==A_eqOp||oper==A_neqOp)
-// {
-// if(left.ty->flag==INT||left.ty->flag==REAL)
-// {
-// if(right.ty->flag == INT || right.ty->flag == REAL)
-// trans = Tr_RelExp(oper, left.exp, right.exp);
-// else
-// EM_error(exp->u.op.right->pos, "unexpected type in comparsion\n");
-// }
-// else if(left.ty->flag == CHAR)
-// {
-// if(type_match(right.ty, left.ty))
-// trans = Tr_RelExp(oper, left.exp, right.exp);
-// else
-// EM_error(exp->u.op.right->pos, "unexpected type in comparsion\n");
-// }
-// else if(left.ty->flag == BOOLEAN)
-// {
-// if(type_match(right.ty, left.ty))
-// trans = Tr_RelExp(oper, left.exp, right.exp);
-// else
-// EM_error(exp->u.op.right->pos, "unexpected type in comparsion\n");
-// }
-// else if(left.ty->flag==STRING)
-// {
-// if(type_match(right.ty, left.ty))
-// trans = Tr_StringRelExp(oper, left.exp, right.exp);
-// else
-// EM_error(exp->u.op.right->pos, "unexpected type in comparsion\n");
-// }
-// /*
-// else if (left.ty->flag == ARRAY)
-// {
-// if(type_match(right.ty, left.ty))
-// trans = eqRef(oper, left.exp, right.exp);
-// else
-// EM_error(exp->u.op.right->pos, "unexpected type in comparsion\n");
-// }
-// else if(left.ty->flag==RECORD)
-// {
-// if(type_match(right.ty, left.ty) || right.ty->flag == NIL)
-// trans = eqRef(oper, left.exp, right.exp);
-// else
-// EM_error(exp->u.op.right->pos, "unexpected type in comparsion\n");
-// }
-// */
-// else
-// EM_error(exp->u.op.right->pos, "unexpected expression in comparsion\n");
-// return Newexpty(trans,BOOLEAN_type());
-// }
-// else
-// {
-// if(left.ty->flag==INT||left.ty->flag==REAL)
-// {
-// if(right.ty->flag == INT || right.ty->flag == REAL)
-// trans = Tr_RelExp(oper, left.exp, right.exp);
-// else
-// EM_error(exp->u.op.right->pos, "unexpected type in comparsion\n");
-// }
-// else if(left.ty->flag==CHAR)
-// {
-// if(right.ty->flag == CHAR)
-// trans = Tr_RelExp(oper, left.exp, right.exp);
-// else
-// EM_error(exp->u.op.right->pos, "unexpected type in comparsion\n");
-// }
-// else if(left.ty->flag==BOOLEAN)
-// {
-// if(right.ty->flag == BOOLEAN)
-// trans = Tr_RelExp(oper, left.exp, right.exp);
-// else
-// EM_error(exp->u.op.right->pos, "unexpected type in comparsion\n");
-// }
-// else if(left.ty->flag==STRING)
-// {
-// if(right.ty->flag == STRING)
-// trans = Tr_StringRelExp(oper, left.exp, right.exp);
-// else
-// EM_error(exp->u.op.right->pos, "unexpected type in comparsion\n");
-// }
-// else
-// EM_error(exp->u.op.right->pos, "unexpected expression in comparsion\n");
-// return Newexpty(trans,BOOLEAN_type());
-// }
-// }
-// else
-// {
-// printf("TransExp inner error!\n");
-// exit(3);
-// }
-// }
-// /*
-// ifÓï¾ä¿ÉÄÜ»áÓзµ»ØÖµ£¬Ò²¿ÉÄÜûÓÐ
-// */
-// else if(exp->kind==A_ifExp)
-// {
-// struct expty condi,ybran,nbran;
-// condi=transExp(l,e,funenv,varenv,exp->u.iff.test);
-// ybran=transExp(l,e,funenv,varenv,exp->u.iff.then);
-// nbran.ty=NULL;
-// nbran.exp=NULL;
-// if(exp->u.iff.elsee)
-// {
-// nbran=transExp(l,e,funenv,varenv,exp->u.iff.elsee);
-// if(condi.ty->flag!=INT&&condi.ty->flag!=BOOLEAN)
-// EM_error(exp->u.iff.test->pos,"Expected integer condition control\n");
-// if(!type_match(ybran.ty,nbran.ty))
-// EM_error(exp->pos,"Branches return type must correspond\n");
-// }
-// return Newexpty(Tr_IfExp(condi.exp, ybran.exp, nbran.exp),ybran.ty);
-// }
-// else if(exp->kind == A_gotoExp)
-// {
-// if(!e)
-// return Newexpty(Tr_NoExp(),VOID_type());
-// return Newexpty(Tr_GotoExp(e),VOID_type());
-// }
-// else if(exp->kind == A_repeatExp)
-// {
-// struct expty num;
-// num = transExp(l, e, funenv, varenv, exp->u.repeatt.test);
-// if(num.ty->flag!=INT)
-// EM_error(exp->pos,"Integer expected in repeat\n");
-// // Tr_exp done=doneExp();
-// struct expty body = transExp(l, e, funenv, varenv, exp->u.repeatt.body);
-// return Newexpty(Tr_RepeatExp(num.exp, body.exp), VOID_type());
-// }
-// /*
-// caseÓï¾äûÓзµ»ØÖµ
-// */
-// else if(exp->kind == A_caseExp)
-// {
-// A_expList items = exp->u.casee.valList;
-// struct expty test = transExp(l, e, funenv, varenv, exp->u.casee.exp);
-// if(test.ty->flag!=INT && test.ty->flag!=CHAR&&
-// test.ty->flag!=STRING&&test.ty->flag!=BOOLEAN)
-// EM_error(exp->pos,"Integer, char, string or boolean expected in case\n");
-// Tr_expList caseList = NULL;
-// for(items; items; items = items->tail)
-// {
-// A_exp val = items->head->u.caseval.val;
-// A_exp action = items->head->u.caseval.action;
-// struct expty valItem = transExp(l, e, funenv, varenv, val);
-// Tr_explistnewhead(valItem,&caseList);
-// if(!type_match(test.ty,valItem.ty))
-// EM_error(exp->pos,"Case items' value type must correspond\n");
-// struct expty actionItem = transExp(l, e, funenv, varenv, action);
-// Tr_explistnewhead(actionItem,&caseList);
-// }
-// //有问题,查查在处理
-// return Newexpty(test, caseList);
-// }
-// else
-// {
-// printf("TransExp inner error!\n");
-// exit(2);
-// }
-// }
-// static Tr_exp transDec(Tr_level l,Tr_exp e,S_table funenv,S_table varenv,A_dec dec)
-// {
-// if(dec->kind==A_varDec)
-// {
-// struct expty tmp;
-// Type tmptp;
-// Tr_access acc;
-// tmp=transExp(l,e,funenv,varenv,dec->u.var.init);
-// acc=Tr_allocLocal(l,dec->u.var.escape);
-// if(dec->u.var.typ)
-// {
-// tmptp=S_look(varenv,dec->u.var.typ);
-// if(tmptp)
-// {
-// if(!dec->u.var.init)
-// {
-// S_enter(funenv,dec->u.var.var,Newvarenv(acc,tmptp, 0));
-// }
-// else if(type_match(tmptp,tmp.ty))
-// S_enter(funenv,dec->u.var.var,Newvarenv(acc,tmptp, 0));
-// else
-// {
-// EM_error(dec->pos,"Type %s mismatch\n",S_name(dec->u.var.typ));
-// //S_enter(funenv,dec->u.var.var,Newvarenv(acc,tmptp));
-// }
-// }
-// else
-// EM_error(dec->pos,"Type %s undefined\n",S_name(dec->u.var.typ));
-// }
-// else
-// {
-// /*
-// if(tmp.ty->flag==NIL||tmp.ty->flag==VOID)
-// {
-// EM_error(dec->pos,"Type %s initial must have a type\n",S_name(dec->u.var.var));
-// //S_enter(funenv,dec->u.var.var,Newvarenv(acc,INT_type()));
-// }
-// else
-// S_enter(funenv,dec->u.var.var,Newvarenv(acc,tmp.ty));
-// */
-// EM_error(dec->pos,"Type %s must be inited\n",S_name(dec->u.var.var));
-// }
-// return Tr_AssignExp(Tr_SimpleVar(acc, l), tmp.exp);
-// }
-// else if(dec->kind == A_constDec)
-// {
-// struct expty getExp;
-// Type tmpty;
-// Tr_access acc;
-// getExp = transExp(l,e,funenv, varenv, dec->u.constt.init);
-// acc = Tr_allocLocal(l, dec->u.constt.escape);
-// if(!dec->u.var.init)
-// {
-// EM_error(dec->pos,"Const is not inited\n");
-// }
-// else
-// {
-// S_enter(funenv, dec->u.constt.constt, Newvarenv(acc, getExp.ty, 1));
-// }
-// return Tr_AssignExp(Tr_SimpleVar(acc, l), getExp.exp);
-// }
-// else if(dec->kind==A_functionDec)
-// {
-// struct expty final;
-// A_fundecList fcl;
-// A_fieldList list;
-// Type resTy;
-// Typelist formalTys;
-// A_fundec f;
-// Environments fun;
-// Typelist s;
-// for (fcl = dec->u.function; fcl; fcl = fcl->tail)
-// {
-// if (fcl->head->result)
-// {
-// resTy = S_look(varenv, fcl->head->result);
-// if (!resTy)
-// {
-// EM_error(fcl->head->pos, "undefined type for return type");
-// resTy = VOID_type();
-// }
-// }
-// else
-// resTy = VOID_type();
-// formalTys = gettypelist(varenv, fcl->head->params);
-// Temp_label funLabel = Temp_newlabel();
-// Tr_level lev = Tr_newLevel(l, funLabel, makeFormals(fcl->head->params));/* create a new level */
-// Environments value = Newfunenv(lev, funLabel, formalTys, resTy);
-// S_enter(funenv, fcl->head->name, value);
-// }
-// //»ñÈ¡·ûºÅ£¬½«·ûºÅ£¬¼ÓÈëµ½»·¾³ÖÐ
-// for (fcl = dec->u.function; fcl; fcl = fcl->tail)
-// {
-// f = fcl->head;
-// Environments funEntry = (Environments)S_look(funenv, f->name); /*get fun-info*/
-// S_beginScope(funenv); //ʵÏÖÄڲ㺯Êý·ÃÎÊÍâ²ã±äÁ¿
-// formalTys = funEntry->u.fun.param;
-// Tr_accessList acls = Tr_formals(funEntry->u.fun.lev);
-// for (list = f->params, s = formalTys; list && s && acls; list = list->tail, s = s->next, acls = acls->tail)
-// S_enter(funenv, list->head->name, Newvarenv(acls->head, s->head, 0));
-// nowCheckFun = f;
-// transExp(funEntry->u.fun.lev, e, funenv, varenv, f->body);
-// nowCheckFun = NULL;
-// Tr_procEntryExit(funEntry->u.fun.lev, final.exp, acls);
-// S_endScope(funenv);
-// }
-// return Tr_NoExp();
-// }
-// else if(dec->kind==A_typeDec)
-// {
-// A_nametyList nl;
-// Type resTy;
-// Type namety;
-// bool iscyl;
-// for (nl = dec->u.type; nl; nl = nl->tail)
-// S_enter(varenv, nl->head->name, NAME_type(nl->head->name, nl->head->ty));
-// iscyl = TRUE;
-// for (nl = dec->u.type; nl; nl = nl->tail) {//ËùÓеͼÏòÉϲéÕÒÒ»¸ö£¬×îºóÒ»¸ö»á²éÕÒµ½Êµ¼ÊÀàÐÍ
-// resTy = transType(varenv, nl->head->ty);
-// if (iscyl)
-// if (resTy->flag != NAME)
-// iscyl = FALSE;
-// namety = S_look(varenv, nl->head->name);
-// namety->u.name.ty = resTy;
-// }
-// if (iscyl) EM_error(dec->pos,"illegal type cycle: cycle must contain record, array");
-// return Tr_NoExp();
-// }
-// else
-// {
-// printf("TransDec inner error!\n");
-// exit(4);
-// }
-// }
-// static Type transType(S_table varenv,A_ty ty)
-// {
-// Type tmptp=NULL;
-// Fieldlist list=NULL;
-
-// if(ty->kind==A_nameTy)
-// {
-// tmptp=S_look(varenv,ty->u.name);
-// if(tmptp)
-// return tmptp;
-// else
-// {
-// EM_error(ty->pos,"Type %s undefined\n",S_name(ty->u.name));
-// return INT_type();
-// }
-// }
-// else if(ty->kind==A_recordTy)
-// {
-// list=getfieldlist(varenv,ty->u.record);
-// return RECORD_type(list);
-// }
-// else if(ty->kind==A_arrayTy)
-// {
-// tmptp=S_look(varenv,ty->u.arrayy.element);
-// if(tmptp)
-// return ARRAY_type(tmptp);
-// else
-// EM_error(ty->pos,"Type %s undefined\n",S_name(ty->u.arrayy.element));
-// }
-
-// else
-// {
-// printf("TransType inner error!\n");
-// exit(5);
-// }
-// }
-// static bool type_match(Type ty1,Type ty2)
-// {
-// Type t1=gettype(ty1);
-// Type t2=gettype(ty2);
-// return (((t1->flag == RECORD || t1->flag == ARRAY) && t1 == t2) ||
-// (t1->flag == RECORD && t2->flag == NIL) ||
-// (t2->flag == RECORD && t1->flag == NIL) ||
-// (t1->flag != RECORD && t1->flag != ARRAY && t1->flag == t2->flag));
-// }
\ No newline at end of file
diff --git a/src/test/1.pas b/src/test/1.pas
deleted file mode 100644
index 6e2d680..0000000
--- a/src/test/1.pas
+++ /dev/null
@@ -1,62 +0,0 @@
- Program ex11;
- const a = 1;
- b = 2;
- c = 1.0;
- type
- Temperatures = array [1..24] of Integer;
- Date = record
- Month: Byte;
- Day: Byte;
- Year: Integer;
- end;
- var a, b, c:real;
- x, y:integer;
- Procedure Swap (var x,y: integer);
- Var t : integer;
- Begin
- x := 2;
- y := 3;
- End;
- Function max(x1,x2 : integer) : integer;
- Begin
- x1 := 2;
- x2 := 3;
- End;
- Begin
- Temperatures[2] := 2;
- Date.Month := 1;
-
- Swap(a,b);
- c := max(1,2);
-
- if x and (y < 0) then
- Begin
- x := 1;
- End
- else inc(y);
-
- For a := 1 to 100 do
- Begin
- S := S+a;
- End;
-
- while d mod b = 0 do
- Begin
- inc(d,a);
- S := 1;
- End;
-
- repeat
- Begin
- x := 1;
- End
- until x > 1;
-
- case nn of
- 1: dm:=a;
- 2: dm:=b;
- y: dm:=c;
- end;
-
- x := 1;
- End.
\ No newline at end of file
diff --git a/src/test/2.pas b/src/test/2.pas
deleted file mode 100644
index 2d86571..0000000
--- a/src/test/2.pas
+++ /dev/null
@@ -1,11 +0,0 @@
-Program ex11;
- Begin
- case nn of
- 1: dm:=a;
- 2: dm:=b;
- 3: dm:=c;
- end;
- a := 1
- b := 2
- c := 4;
- End.
\ No newline at end of file
diff --git a/src/y.output b/src/y.output
deleted file mode 100644
index fb742a2..0000000
--- a/src/y.output
+++ /dev/null
@@ -1,3811 +0,0 @@
-状态 141conflicts: 1 shift/reduce
-
-
-语法
-
- 0 $accept: program $end
-
- 1 program: program_head routine DOT
-
- 2 program_head: PROGRAM id SEMI
-
- 3 routine: routine_head routine_body
-
- 4 routine_head: label_part const_part type_part var_part routine_part
-
- 5 label_part: %empty
-
- 6 const_part: CONST const_expr_list
- 7 | %empty
-
- 8 const_expr_list: id EQUAL const_value SEMI const_expr_list
- 9 | id EQUAL const_value SEMI
-
- 10 const_value: INTEGER
- 11 | REAL
- 12 | CHAR
- 13 | STRING
- 14 | sys_con
-
- 15 type_part: TYPE type_decl_list
- 16 | %empty
-
- 17 type_decl_list: type_definition type_decl_list
- 18 | type_definition
-
- 19 type_definition: id EQUAL type_decl SEMI
-
- 20 type_decl: simple_type_decl
- 21 | array_type_decl
- 22 | record_type_decl
-
- 23 simple_type_decl: sys_type
- 24 | id
- 25 | LP name_list RP
- 26 | const_value DOTDOT const_value
- 27 | MINUS const_value DOTDOT const_value
- 28 | MINUS const_value DOTDOT MINUS const_value
- 29 | id DOTDOT id
-
- 30 array_type_decl: ARRAY LB simple_type_decl RB OF type_decl
-
- 31 record_type_decl: RECORD field_decl_list END
-
- 32 field_decl_list: field_decl field_decl_list
- 33 | field_decl
-
- 34 field_decl: name_list COLON type_decl SEMI
-
- 35 name_list: name_list COMMA id
- 36 | id
-
- 37 var_part: VAR var_decl_list
- 38 | %empty
-
- 39 var_decl_list: var_decl var_decl_list
- 40 | var_decl
-
- 41 var_decl: name_list COLON type_decl SEMI
-
- 42 routine_part: function_decl routine_part
- 43 | procedure_decl routine_part
- 44 | %empty
-
- 45 function_decl: function_head SEMI sub_routine SEMI
-
- 46 function_head: FUNCTION id parameters COLON simple_type_decl
-
- 47 procedure_decl: procedure_head SEMI sub_routine SEMI
-
- 48 procedure_head: PROCEDURE id parameters
-
- 49 sub_routine: routine_head routine_body
-
- 50 parameters: LP para_decl_list RP
- 51 | %empty
-
- 52 para_decl_list: para_decl_list SEMI para_type_list
- 53 | para_type_list
-
- 54 para_type_list: var_para_list COLON simple_type_decl
- 55 | val_para_list COLON simple_type_decl
-
- 56 var_para_list: VAR name_list
-
- 57 val_para_list: name_list
-
- 58 routine_body: compound_stmt
-
- 59 compound_stmt: BEGIN_T stmt_list END
-
- 60 stmt_list: stmt SEMI stmt_list
- 61 | %empty
- 62 | stat
-
- 63 stmt: INTEGER COLON non_label_stmt
- 64 | non_label_stmt
-
- 65 non_label_stmt: assign_stmt
- 66 | proc_stmt
- 67 | compound_stmt
- 68 | if_stmt
- 69 | repeat_stmt
- 70 | while_stmt
- 71 | for_stmt
- 72 | case_stmt
- 73 | goto_stmt
-
- 74 assign_stmt: id ASSIGN expression
- 75 | id LB expression RB ASSIGN expression
- 76 | id DOT id ASSIGN expression
-
- 77 proc_stmt: id
- 78 | id LP args_list RP
- 79 | sys_proc
- 80 | sys_proc LP expression_list RP
- 81 | READ LP factor RP
-
- 82 if_stmt: IF expression THEN stmt else_clause
-
- 83 else_clause: ELSE stmt
- 84 | %empty
-
- 85 repeat_stmt: REPEAT stmt UNTIL expression
-
- 86 while_stmt: WHILE expression DO stmt
-
- 87 for_stmt: FOR id ASSIGN expression direction expression DO stmt
-
- 88 direction: TO
- 89 | DOWNTO
-
- 90 case_stmt: CASE expression OF case_expr_list END
-
- 91 case_expr_list: case_expr case_expr_list
- 92 | case_expr
-
- 93 case_expr: const_value COLON stmt SEMI
- 94 | id COLON stmt SEMI
-
- 95 goto_stmt: GOTO INTEGER
-
- 96 expression_list: expression COMMA expression_list
- 97 | expression
-
- 98 expression: expression GE expr
- 99 | expression GT expr
- 100 | expression LE expr
- 101 | expression LT expr
- 102 | expression EQUAL expr
- 103 | expression UNEQUAL expr
- 104 | expr
-
- 105 expr: expr PLUS term
- 106 | expr MINUS term
- 107 | expr OR term
- 108 | term
-
- 109 term: term MUL factor
- 110 | term INTDIV factor
- 111 | term REALDIV factor
- 112 | term MOD factor
- 113 | term AND factor
- 114 | factor
-
- 115 factor: id
- 116 | id LP args_list RP
- 117 | sys_funct
- 118 | sys_funct LP args_list RP
- 119 | const_value
- 120 | LP expression RP
- 121 | NOT factor
- 122 | MINUS factor
- 123 | id LB expression RB
- 124 | id DOT id
-
- 125 args_list: args_list COMMA expression
- 126 | expression
-
- 127 id: ID
-
- 128 sys_con: SYS_CON
-
- 129 sys_funct: SYS_FUNCT
-
- 130 sys_proc: SYS_PROC
-
- 131 sys_type: SYS_TYPE
-
- 132 stat: error SEMI
-
-
-Terminals, with rules where they appear
-
-$end (0) 0
-error (256) 132
-LP (258) 25 50 78 80 81 116 118 120
-RP (259) 25 50 78 80 81 116 118 120
-LB (260) 30 75 123
-RB (261) 30 75 123
-DOT (262) 1 76 124
-COMMA (263) 35 96 125
-COLON (264) 34 41 46 54 55 63 93 94
-SEMI (265) 2 8 9 19 34 41 45 47 52 60 93 94 132
-PLUS (266) 105
-MINUS (267) 27 28 106 122
-MUL (268) 109
-REALDIV (269) 111
-INTDIV (270) 110
-MOD (271) 112
-AND (272) 113
-OR (273) 107
-NOT (274) 121
-GE (275) 98
-GT (276) 99
-LE (277) 100
-LT (278) 101
-EQUAL (279) 8 9 19 102
-UNEQUAL (280) 103
-ASSIGN (281) 74 75 76 87
-PROGRAM (282) 2
-FUNCTION (283) 46
-PROCEDURE (284) 48
-BEGIN_T (285) 59
-END (286) 31 59 90
-TYPE (287) 15
-ARRAY (288) 30
-OF (289) 30 90
-RECORD (290) 31
-VAR (291) 37 56
-IF (292) 82
-THEN (293) 82
-ELSE (294) 83
-REPEAT (295) 85
-TO (296) 88
-DOWNTO (297) 89
-UNTIL (298) 85
-WHILE (299) 86
-DO (300) 86 87
-FOR (301) 87
-CASE (302) 90
-GOTO (303) 95
-READ (304) 81
-CONST (305) 6
-DOTDOT (306) 26 27 28 29
-INTEGER (307) 10 63 95
-REAL (308) 11
-CHAR (309) 12
-ID (310) 127
-STRING (311) 13
-SYS_CON (312) 128
-SYS_FUNCT (313) 129
-SYS_PROC (314) 130
-SYS_TYPE (315) 131
-
-
-Nonterminals, with rules where they appear
-
-$accept (61)
- on left: 0
-program (62)
- on left: 1, on right: 0
-program_head (63)
- on left: 2, on right: 1
-routine (64)
- on left: 3, on right: 1
-routine_head (65)
- on left: 4, on right: 3 49
-label_part (66)
- on left: 5, on right: 4
-const_part (67)
- on left: 6 7, on right: 4
-const_expr_list (68)
- on left: 8 9, on right: 6 8
-const_value (69)
- on left: 10 11 12 13 14, on right: 8 9 26 27 28 93 119
-type_part (70)
- on left: 15 16, on right: 4
-type_decl_list (71)
- on left: 17 18, on right: 15 17
-type_definition (72)
- on left: 19, on right: 17 18
-type_decl (73)
- on left: 20 21 22, on right: 19 30 34 41
-simple_type_decl (74)
- on left: 23 24 25 26 27 28 29, on right: 20 30 46 54 55
-array_type_decl (75)
- on left: 30, on right: 21
-record_type_decl (76)
- on left: 31, on right: 22
-field_decl_list (77)
- on left: 32 33, on right: 31 32
-field_decl (78)
- on left: 34, on right: 32 33
-name_list (79)
- on left: 35 36, on right: 25 34 35 41 56 57
-var_part (80)
- on left: 37 38, on right: 4
-var_decl_list (81)
- on left: 39 40, on right: 37 39
-var_decl (82)
- on left: 41, on right: 39 40
-routine_part (83)
- on left: 42 43 44, on right: 4 42 43
-function_decl (84)
- on left: 45, on right: 42
-function_head (85)
- on left: 46, on right: 45
-procedure_decl (86)
- on left: 47, on right: 43
-procedure_head (87)
- on left: 48, on right: 47
-sub_routine (88)
- on left: 49, on right: 45 47
-parameters (89)
- on left: 50 51, on right: 46 48
-para_decl_list (90)
- on left: 52 53, on right: 50 52
-para_type_list (91)
- on left: 54 55, on right: 52 53
-var_para_list (92)
- on left: 56, on right: 54
-val_para_list (93)
- on left: 57, on right: 55
-routine_body (94)
- on left: 58, on right: 3 49
-compound_stmt (95)
- on left: 59, on right: 58 67
-stmt_list (96)
- on left: 60 61 62, on right: 59 60
-stmt (97)
- on left: 63 64, on right: 60 82 83 85 86 87 93 94
-non_label_stmt (98)
- on left: 65 66 67 68 69 70 71 72 73, on right: 63 64
-assign_stmt (99)
- on left: 74 75 76, on right: 65
-proc_stmt (100)
- on left: 77 78 79 80 81, on right: 66
-if_stmt (101)
- on left: 82, on right: 68
-else_clause (102)
- on left: 83 84, on right: 82
-repeat_stmt (103)
- on left: 85, on right: 69
-while_stmt (104)
- on left: 86, on right: 70
-for_stmt (105)
- on left: 87, on right: 71
-direction (106)
- on left: 88 89, on right: 87
-case_stmt (107)
- on left: 90, on right: 72
-case_expr_list (108)
- on left: 91 92, on right: 90 91
-case_expr (109)
- on left: 93 94, on right: 91 92
-goto_stmt (110)
- on left: 95, on right: 73
-expression_list (111)
- on left: 96 97, on right: 80 96
-expression (112)
- on left: 98 99 100 101 102 103 104, on right: 74 75 76 82 85 86
- 87 90 96 97 98 99 100 101 102 103 120 123 125 126
-expr (113)
- on left: 105 106 107 108, on right: 98 99 100 101 102 103 104 105
- 106 107
-term (114)
- on left: 109 110 111 112 113 114, on right: 105 106 107 108 109
- 110 111 112 113
-factor (115)
- on left: 115 116 117 118 119 120 121 122 123 124, on right: 81
- 109 110 111 112 113 114 121 122
-args_list (116)
- on left: 125 126, on right: 78 116 118 125
-id (117)
- on left: 127, on right: 2 8 9 19 24 29 35 36 46 48 74 75 76 77
- 78 87 94 115 116 123 124
-sys_con (118)
- on left: 128, on right: 14
-sys_funct (119)
- on left: 129, on right: 117 118
-sys_proc (120)
- on left: 130, on right: 79 80
-sys_type (121)
- on left: 131, on right: 23
-stat (122)
- on left: 132, on right: 62
-
-
-State 0
-
- 0 $accept: . program $end
-
- PROGRAM shift, and go to state 1
-
- program 转到状态 2
- program_head 转到状态 3
-
-
-State 1
-
- 2 program_head: PROGRAM . id SEMI
-
- ID shift, and go to state 4
-
- id 转到状态 5
-
-
-State 2
-
- 0 $accept: program . $end
-
- $end shift, and go to state 6
-
-
-State 3
-
- 1 program: program_head . routine DOT
-
- $default reduce using rule 5 (label_part)
-
- routine 转到状态 7
- routine_head 转到状态 8
- label_part 转到状态 9
-
-
-State 4
-
- 127 id: ID .
-
- $default reduce using rule 127 (id)
-
-
-State 5
-
- 2 program_head: PROGRAM id . SEMI
-
- SEMI shift, and go to state 10
-
-
-State 6
-
- 0 $accept: program $end .
-
- $default 接受
-
-
-State 7
-
- 1 program: program_head routine . DOT
-
- DOT shift, and go to state 11
-
-
-State 8
-
- 3 routine: routine_head . routine_body
-
- BEGIN_T shift, and go to state 12
-
- routine_body 转到状态 13
- compound_stmt 转到状态 14
-
-
-State 9
-
- 4 routine_head: label_part . const_part type_part var_part routine_part
-
- CONST shift, and go to state 15
-
- $default reduce using rule 7 (const_part)
-
- const_part 转到状态 16
-
-
-State 10
-
- 2 program_head: PROGRAM id SEMI .
-
- $default reduce using rule 2 (program_head)
-
-
-State 11
-
- 1 program: program_head routine DOT .
-
- $default reduce using rule 1 (program)
-
-
-State 12
-
- 59 compound_stmt: BEGIN_T . stmt_list END
-
- error shift, and go to state 17
- BEGIN_T shift, and go to state 12
- IF shift, and go to state 18
- REPEAT shift, and go to state 19
- WHILE shift, and go to state 20
- FOR shift, and go to state 21
- CASE shift, and go to state 22
- GOTO shift, and go to state 23
- READ shift, and go to state 24
- INTEGER shift, and go to state 25
- ID shift, and go to state 4
- SYS_PROC shift, and go to state 26
-
- END reduce using rule 61 (stmt_list)
-
- compound_stmt 转到状态 27
- stmt_list 转到状态 28
- stmt 转到状态 29
- non_label_stmt 转到状态 30
- assign_stmt 转到状态 31
- proc_stmt 转到状态 32
- if_stmt 转到状态 33
- repeat_stmt 转到状态 34
- while_stmt 转到状态 35
- for_stmt 转到状态 36
- case_stmt 转到状态 37
- goto_stmt 转到状态 38
- id 转到状态 39
- sys_proc 转到状态 40
- stat 转到状态 41
-
-
-State 13
-
- 3 routine: routine_head routine_body .
-
- $default reduce using rule 3 (routine)
-
-
-State 14
-
- 58 routine_body: compound_stmt .
-
- $default reduce using rule 58 (routine_body)
-
-
-State 15
-
- 6 const_part: CONST . const_expr_list
-
- ID shift, and go to state 4
-
- const_expr_list 转到状态 42
- id 转到状态 43
-
-
-State 16
-
- 4 routine_head: label_part const_part . type_part var_part routine_part
-
- TYPE shift, and go to state 44
-
- $default reduce using rule 16 (type_part)
-
- type_part 转到状态 45
-
-
-State 17
-
- 132 stat: error . SEMI
-
- SEMI shift, and go to state 46
-
-
-State 18
-
- 82 if_stmt: IF . expression THEN stmt else_clause
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- expression 转到状态 57
- expr 转到状态 58
- term 转到状态 59
- factor 转到状态 60
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 19
-
- 85 repeat_stmt: REPEAT . stmt UNTIL expression
-
- BEGIN_T shift, and go to state 12
- IF shift, and go to state 18
- REPEAT shift, and go to state 19
- WHILE shift, and go to state 20
- FOR shift, and go to state 21
- CASE shift, and go to state 22
- GOTO shift, and go to state 23
- READ shift, and go to state 24
- INTEGER shift, and go to state 25
- ID shift, and go to state 4
- SYS_PROC shift, and go to state 26
-
- compound_stmt 转到状态 27
- stmt 转到状态 64
- non_label_stmt 转到状态 30
- assign_stmt 转到状态 31
- proc_stmt 转到状态 32
- if_stmt 转到状态 33
- repeat_stmt 转到状态 34
- while_stmt 转到状态 35
- for_stmt 转到状态 36
- case_stmt 转到状态 37
- goto_stmt 转到状态 38
- id 转到状态 39
- sys_proc 转到状态 40
-
-
-State 20
-
- 86 while_stmt: WHILE . expression DO stmt
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- expression 转到状态 65
- expr 转到状态 58
- term 转到状态 59
- factor 转到状态 60
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 21
-
- 87 for_stmt: FOR . id ASSIGN expression direction expression DO stmt
-
- ID shift, and go to state 4
-
- id 转到状态 66
-
-
-State 22
-
- 90 case_stmt: CASE . expression OF case_expr_list END
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- expression 转到状态 67
- expr 转到状态 58
- term 转到状态 59
- factor 转到状态 60
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 23
-
- 95 goto_stmt: GOTO . INTEGER
-
- INTEGER shift, and go to state 68
-
-
-State 24
-
- 81 proc_stmt: READ . LP factor RP
-
- LP shift, and go to state 69
-
-
-State 25
-
- 63 stmt: INTEGER . COLON non_label_stmt
-
- COLON shift, and go to state 70
-
-
-State 26
-
- 130 sys_proc: SYS_PROC .
-
- $default reduce using rule 130 (sys_proc)
-
-
-State 27
-
- 67 non_label_stmt: compound_stmt .
-
- $default reduce using rule 67 (non_label_stmt)
-
-
-State 28
-
- 59 compound_stmt: BEGIN_T stmt_list . END
-
- END shift, and go to state 71
-
-
-State 29
-
- 60 stmt_list: stmt . SEMI stmt_list
-
- SEMI shift, and go to state 72
-
-
-State 30
-
- 64 stmt: non_label_stmt .
-
- $default reduce using rule 64 (stmt)
-
-
-State 31
-
- 65 non_label_stmt: assign_stmt .
-
- $default reduce using rule 65 (non_label_stmt)
-
-
-State 32
-
- 66 non_label_stmt: proc_stmt .
-
- $default reduce using rule 66 (non_label_stmt)
-
-
-State 33
-
- 68 non_label_stmt: if_stmt .
-
- $default reduce using rule 68 (non_label_stmt)
-
-
-State 34
-
- 69 non_label_stmt: repeat_stmt .
-
- $default reduce using rule 69 (non_label_stmt)
-
-
-State 35
-
- 70 non_label_stmt: while_stmt .
-
- $default reduce using rule 70 (non_label_stmt)
-
-
-State 36
-
- 71 non_label_stmt: for_stmt .
-
- $default reduce using rule 71 (non_label_stmt)
-
-
-State 37
-
- 72 non_label_stmt: case_stmt .
-
- $default reduce using rule 72 (non_label_stmt)
-
-
-State 38
-
- 73 non_label_stmt: goto_stmt .
-
- $default reduce using rule 73 (non_label_stmt)
-
-
-State 39
-
- 74 assign_stmt: id . ASSIGN expression
- 75 | id . LB expression RB ASSIGN expression
- 76 | id . DOT id ASSIGN expression
- 77 proc_stmt: id .
- 78 | id . LP args_list RP
-
- LP shift, and go to state 73
- LB shift, and go to state 74
- DOT shift, and go to state 75
- ASSIGN shift, and go to state 76
-
- $default reduce using rule 77 (proc_stmt)
-
-
-State 40
-
- 79 proc_stmt: sys_proc .
- 80 | sys_proc . LP expression_list RP
-
- LP shift, and go to state 77
-
- $default reduce using rule 79 (proc_stmt)
-
-
-State 41
-
- 62 stmt_list: stat .
-
- $default reduce using rule 62 (stmt_list)
-
-
-State 42
-
- 6 const_part: CONST const_expr_list .
-
- $default reduce using rule 6 (const_part)
-
-
-State 43
-
- 8 const_expr_list: id . EQUAL const_value SEMI const_expr_list
- 9 | id . EQUAL const_value SEMI
-
- EQUAL shift, and go to state 78
-
-
-State 44
-
- 15 type_part: TYPE . type_decl_list
-
- ID shift, and go to state 4
-
- type_decl_list 转到状态 79
- type_definition 转到状态 80
- id 转到状态 81
-
-
-State 45
-
- 4 routine_head: label_part const_part type_part . var_part routine_part
-
- VAR shift, and go to state 82
-
- $default reduce using rule 38 (var_part)
-
- var_part 转到状态 83
-
-
-State 46
-
- 132 stat: error SEMI .
-
- $default reduce using rule 132 (stat)
-
-
-State 47
-
- 120 factor: LP . expression RP
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- expression 转到状态 84
- expr 转到状态 58
- term 转到状态 59
- factor 转到状态 60
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 48
-
- 122 factor: MINUS . factor
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- factor 转到状态 85
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 49
-
- 121 factor: NOT . factor
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- factor 转到状态 86
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 50
-
- 10 const_value: INTEGER .
-
- $default reduce using rule 10 (const_value)
-
-
-State 51
-
- 11 const_value: REAL .
-
- $default reduce using rule 11 (const_value)
-
-
-State 52
-
- 12 const_value: CHAR .
-
- $default reduce using rule 12 (const_value)
-
-
-State 53
-
- 13 const_value: STRING .
-
- $default reduce using rule 13 (const_value)
-
-
-State 54
-
- 128 sys_con: SYS_CON .
-
- $default reduce using rule 128 (sys_con)
-
-
-State 55
-
- 129 sys_funct: SYS_FUNCT .
-
- $default reduce using rule 129 (sys_funct)
-
-
-State 56
-
- 119 factor: const_value .
-
- $default reduce using rule 119 (factor)
-
-
-State 57
-
- 82 if_stmt: IF expression . THEN stmt else_clause
- 98 expression: expression . GE expr
- 99 | expression . GT expr
- 100 | expression . LE expr
- 101 | expression . LT expr
- 102 | expression . EQUAL expr
- 103 | expression . UNEQUAL expr
-
- GE shift, and go to state 87
- GT shift, and go to state 88
- LE shift, and go to state 89
- LT shift, and go to state 90
- EQUAL shift, and go to state 91
- UNEQUAL shift, and go to state 92
- THEN shift, and go to state 93
-
-
-State 58
-
- 104 expression: expr .
- 105 expr: expr . PLUS term
- 106 | expr . MINUS term
- 107 | expr . OR term
-
- PLUS shift, and go to state 94
- MINUS shift, and go to state 95
- OR shift, and go to state 96
-
- $default reduce using rule 104 (expression)
-
-
-State 59
-
- 108 expr: term .
- 109 term: term . MUL factor
- 110 | term . INTDIV factor
- 111 | term . REALDIV factor
- 112 | term . MOD factor
- 113 | term . AND factor
-
- MUL shift, and go to state 97
- REALDIV shift, and go to state 98
- INTDIV shift, and go to state 99
- MOD shift, and go to state 100
- AND shift, and go to state 101
-
- $default reduce using rule 108 (expr)
-
-
-State 60
-
- 114 term: factor .
-
- $default reduce using rule 114 (term)
-
-
-State 61
-
- 115 factor: id .
- 116 | id . LP args_list RP
- 123 | id . LB expression RB
- 124 | id . DOT id
-
- LP shift, and go to state 102
- LB shift, and go to state 103
- DOT shift, and go to state 104
-
- $default reduce using rule 115 (factor)
-
-
-State 62
-
- 14 const_value: sys_con .
-
- $default reduce using rule 14 (const_value)
-
-
-State 63
-
- 117 factor: sys_funct .
- 118 | sys_funct . LP args_list RP
-
- LP shift, and go to state 105
-
- $default reduce using rule 117 (factor)
-
-
-State 64
-
- 85 repeat_stmt: REPEAT stmt . UNTIL expression
-
- UNTIL shift, and go to state 106
-
-
-State 65
-
- 86 while_stmt: WHILE expression . DO stmt
- 98 expression: expression . GE expr
- 99 | expression . GT expr
- 100 | expression . LE expr
- 101 | expression . LT expr
- 102 | expression . EQUAL expr
- 103 | expression . UNEQUAL expr
-
- GE shift, and go to state 87
- GT shift, and go to state 88
- LE shift, and go to state 89
- LT shift, and go to state 90
- EQUAL shift, and go to state 91
- UNEQUAL shift, and go to state 92
- DO shift, and go to state 107
-
-
-State 66
-
- 87 for_stmt: FOR id . ASSIGN expression direction expression DO stmt
-
- ASSIGN shift, and go to state 108
-
-
-State 67
-
- 90 case_stmt: CASE expression . OF case_expr_list END
- 98 expression: expression . GE expr
- 99 | expression . GT expr
- 100 | expression . LE expr
- 101 | expression . LT expr
- 102 | expression . EQUAL expr
- 103 | expression . UNEQUAL expr
-
- GE shift, and go to state 87
- GT shift, and go to state 88
- LE shift, and go to state 89
- LT shift, and go to state 90
- EQUAL shift, and go to state 91
- UNEQUAL shift, and go to state 92
- OF shift, and go to state 109
-
-
-State 68
-
- 95 goto_stmt: GOTO INTEGER .
-
- $default reduce using rule 95 (goto_stmt)
-
-
-State 69
-
- 81 proc_stmt: READ LP . factor RP
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- factor 转到状态 110
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 70
-
- 63 stmt: INTEGER COLON . non_label_stmt
-
- BEGIN_T shift, and go to state 12
- IF shift, and go to state 18
- REPEAT shift, and go to state 19
- WHILE shift, and go to state 20
- FOR shift, and go to state 21
- CASE shift, and go to state 22
- GOTO shift, and go to state 23
- READ shift, and go to state 24
- ID shift, and go to state 4
- SYS_PROC shift, and go to state 26
-
- compound_stmt 转到状态 27
- non_label_stmt 转到状态 111
- assign_stmt 转到状态 31
- proc_stmt 转到状态 32
- if_stmt 转到状态 33
- repeat_stmt 转到状态 34
- while_stmt 转到状态 35
- for_stmt 转到状态 36
- case_stmt 转到状态 37
- goto_stmt 转到状态 38
- id 转到状态 39
- sys_proc 转到状态 40
-
-
-State 71
-
- 59 compound_stmt: BEGIN_T stmt_list END .
-
- $default reduce using rule 59 (compound_stmt)
-
-
-State 72
-
- 60 stmt_list: stmt SEMI . stmt_list
-
- error shift, and go to state 17
- BEGIN_T shift, and go to state 12
- IF shift, and go to state 18
- REPEAT shift, and go to state 19
- WHILE shift, and go to state 20
- FOR shift, and go to state 21
- CASE shift, and go to state 22
- GOTO shift, and go to state 23
- READ shift, and go to state 24
- INTEGER shift, and go to state 25
- ID shift, and go to state 4
- SYS_PROC shift, and go to state 26
-
- END reduce using rule 61 (stmt_list)
-
- compound_stmt 转到状态 27
- stmt_list 转到状态 112
- stmt 转到状态 29
- non_label_stmt 转到状态 30
- assign_stmt 转到状态 31
- proc_stmt 转到状态 32
- if_stmt 转到状态 33
- repeat_stmt 转到状态 34
- while_stmt 转到状态 35
- for_stmt 转到状态 36
- case_stmt 转到状态 37
- goto_stmt 转到状态 38
- id 转到状态 39
- sys_proc 转到状态 40
- stat 转到状态 41
-
-
-State 73
-
- 78 proc_stmt: id LP . args_list RP
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- expression 转到状态 113
- expr 转到状态 58
- term 转到状态 59
- factor 转到状态 60
- args_list 转到状态 114
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 74
-
- 75 assign_stmt: id LB . expression RB ASSIGN expression
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- expression 转到状态 115
- expr 转到状态 58
- term 转到状态 59
- factor 转到状态 60
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 75
-
- 76 assign_stmt: id DOT . id ASSIGN expression
-
- ID shift, and go to state 4
-
- id 转到状态 116
-
-
-State 76
-
- 74 assign_stmt: id ASSIGN . expression
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- expression 转到状态 117
- expr 转到状态 58
- term 转到状态 59
- factor 转到状态 60
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 77
-
- 80 proc_stmt: sys_proc LP . expression_list RP
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- expression_list 转到状态 118
- expression 转到状态 119
- expr 转到状态 58
- term 转到状态 59
- factor 转到状态 60
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 78
-
- 8 const_expr_list: id EQUAL . const_value SEMI const_expr_list
- 9 | id EQUAL . const_value SEMI
-
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
-
- const_value 转到状态 120
- sys_con 转到状态 62
-
-
-State 79
-
- 15 type_part: TYPE type_decl_list .
-
- $default reduce using rule 15 (type_part)
-
-
-State 80
-
- 17 type_decl_list: type_definition . type_decl_list
- 18 | type_definition .
-
- ID shift, and go to state 4
-
- $default reduce using rule 18 (type_decl_list)
-
- type_decl_list 转到状态 121
- type_definition 转到状态 80
- id 转到状态 81
-
-
-State 81
-
- 19 type_definition: id . EQUAL type_decl SEMI
-
- EQUAL shift, and go to state 122
-
-
-State 82
-
- 37 var_part: VAR . var_decl_list
-
- ID shift, and go to state 4
-
- name_list 转到状态 123
- var_decl_list 转到状态 124
- var_decl 转到状态 125
- id 转到状态 126
-
-
-State 83
-
- 4 routine_head: label_part const_part type_part var_part . routine_part
-
- FUNCTION shift, and go to state 127
- PROCEDURE shift, and go to state 128
-
- $default reduce using rule 44 (routine_part)
-
- routine_part 转到状态 129
- function_decl 转到状态 130
- function_head 转到状态 131
- procedure_decl 转到状态 132
- procedure_head 转到状态 133
-
-
-State 84
-
- 98 expression: expression . GE expr
- 99 | expression . GT expr
- 100 | expression . LE expr
- 101 | expression . LT expr
- 102 | expression . EQUAL expr
- 103 | expression . UNEQUAL expr
- 120 factor: LP expression . RP
-
- RP shift, and go to state 134
- GE shift, and go to state 87
- GT shift, and go to state 88
- LE shift, and go to state 89
- LT shift, and go to state 90
- EQUAL shift, and go to state 91
- UNEQUAL shift, and go to state 92
-
-
-State 85
-
- 122 factor: MINUS factor .
-
- $default reduce using rule 122 (factor)
-
-
-State 86
-
- 121 factor: NOT factor .
-
- $default reduce using rule 121 (factor)
-
-
-State 87
-
- 98 expression: expression GE . expr
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- expr 转到状态 135
- term 转到状态 59
- factor 转到状态 60
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 88
-
- 99 expression: expression GT . expr
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- expr 转到状态 136
- term 转到状态 59
- factor 转到状态 60
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 89
-
- 100 expression: expression LE . expr
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- expr 转到状态 137
- term 转到状态 59
- factor 转到状态 60
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 90
-
- 101 expression: expression LT . expr
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- expr 转到状态 138
- term 转到状态 59
- factor 转到状态 60
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 91
-
- 102 expression: expression EQUAL . expr
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- expr 转到状态 139
- term 转到状态 59
- factor 转到状态 60
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 92
-
- 103 expression: expression UNEQUAL . expr
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- expr 转到状态 140
- term 转到状态 59
- factor 转到状态 60
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 93
-
- 82 if_stmt: IF expression THEN . stmt else_clause
-
- BEGIN_T shift, and go to state 12
- IF shift, and go to state 18
- REPEAT shift, and go to state 19
- WHILE shift, and go to state 20
- FOR shift, and go to state 21
- CASE shift, and go to state 22
- GOTO shift, and go to state 23
- READ shift, and go to state 24
- INTEGER shift, and go to state 25
- ID shift, and go to state 4
- SYS_PROC shift, and go to state 26
-
- compound_stmt 转到状态 27
- stmt 转到状态 141
- non_label_stmt 转到状态 30
- assign_stmt 转到状态 31
- proc_stmt 转到状态 32
- if_stmt 转到状态 33
- repeat_stmt 转到状态 34
- while_stmt 转到状态 35
- for_stmt 转到状态 36
- case_stmt 转到状态 37
- goto_stmt 转到状态 38
- id 转到状态 39
- sys_proc 转到状态 40
-
-
-State 94
-
- 105 expr: expr PLUS . term
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- term 转到状态 142
- factor 转到状态 60
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 95
-
- 106 expr: expr MINUS . term
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- term 转到状态 143
- factor 转到状态 60
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 96
-
- 107 expr: expr OR . term
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- term 转到状态 144
- factor 转到状态 60
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 97
-
- 109 term: term MUL . factor
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- factor 转到状态 145
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 98
-
- 111 term: term REALDIV . factor
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- factor 转到状态 146
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 99
-
- 110 term: term INTDIV . factor
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- factor 转到状态 147
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 100
-
- 112 term: term MOD . factor
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- factor 转到状态 148
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 101
-
- 113 term: term AND . factor
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- factor 转到状态 149
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 102
-
- 116 factor: id LP . args_list RP
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- expression 转到状态 113
- expr 转到状态 58
- term 转到状态 59
- factor 转到状态 60
- args_list 转到状态 150
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 103
-
- 123 factor: id LB . expression RB
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- expression 转到状态 151
- expr 转到状态 58
- term 转到状态 59
- factor 转到状态 60
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 104
-
- 124 factor: id DOT . id
-
- ID shift, and go to state 4
-
- id 转到状态 152
-
-
-State 105
-
- 118 factor: sys_funct LP . args_list RP
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- expression 转到状态 113
- expr 转到状态 58
- term 转到状态 59
- factor 转到状态 60
- args_list 转到状态 153
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 106
-
- 85 repeat_stmt: REPEAT stmt UNTIL . expression
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- expression 转到状态 154
- expr 转到状态 58
- term 转到状态 59
- factor 转到状态 60
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 107
-
- 86 while_stmt: WHILE expression DO . stmt
-
- BEGIN_T shift, and go to state 12
- IF shift, and go to state 18
- REPEAT shift, and go to state 19
- WHILE shift, and go to state 20
- FOR shift, and go to state 21
- CASE shift, and go to state 22
- GOTO shift, and go to state 23
- READ shift, and go to state 24
- INTEGER shift, and go to state 25
- ID shift, and go to state 4
- SYS_PROC shift, and go to state 26
-
- compound_stmt 转到状态 27
- stmt 转到状态 155
- non_label_stmt 转到状态 30
- assign_stmt 转到状态 31
- proc_stmt 转到状态 32
- if_stmt 转到状态 33
- repeat_stmt 转到状态 34
- while_stmt 转到状态 35
- for_stmt 转到状态 36
- case_stmt 转到状态 37
- goto_stmt 转到状态 38
- id 转到状态 39
- sys_proc 转到状态 40
-
-
-State 108
-
- 87 for_stmt: FOR id ASSIGN . expression direction expression DO stmt
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- expression 转到状态 156
- expr 转到状态 58
- term 转到状态 59
- factor 转到状态 60
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 109
-
- 90 case_stmt: CASE expression OF . case_expr_list END
-
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
-
- const_value 转到状态 157
- case_expr_list 转到状态 158
- case_expr 转到状态 159
- id 转到状态 160
- sys_con 转到状态 62
-
-
-State 110
-
- 81 proc_stmt: READ LP factor . RP
-
- RP shift, and go to state 161
-
-
-State 111
-
- 63 stmt: INTEGER COLON non_label_stmt .
-
- $default reduce using rule 63 (stmt)
-
-
-State 112
-
- 60 stmt_list: stmt SEMI stmt_list .
-
- $default reduce using rule 60 (stmt_list)
-
-
-State 113
-
- 98 expression: expression . GE expr
- 99 | expression . GT expr
- 100 | expression . LE expr
- 101 | expression . LT expr
- 102 | expression . EQUAL expr
- 103 | expression . UNEQUAL expr
- 126 args_list: expression .
-
- GE shift, and go to state 87
- GT shift, and go to state 88
- LE shift, and go to state 89
- LT shift, and go to state 90
- EQUAL shift, and go to state 91
- UNEQUAL shift, and go to state 92
-
- $default reduce using rule 126 (args_list)
-
-
-State 114
-
- 78 proc_stmt: id LP args_list . RP
- 125 args_list: args_list . COMMA expression
-
- RP shift, and go to state 162
- COMMA shift, and go to state 163
-
-
-State 115
-
- 75 assign_stmt: id LB expression . RB ASSIGN expression
- 98 expression: expression . GE expr
- 99 | expression . GT expr
- 100 | expression . LE expr
- 101 | expression . LT expr
- 102 | expression . EQUAL expr
- 103 | expression . UNEQUAL expr
-
- RB shift, and go to state 164
- GE shift, and go to state 87
- GT shift, and go to state 88
- LE shift, and go to state 89
- LT shift, and go to state 90
- EQUAL shift, and go to state 91
- UNEQUAL shift, and go to state 92
-
-
-State 116
-
- 76 assign_stmt: id DOT id . ASSIGN expression
-
- ASSIGN shift, and go to state 165
-
-
-State 117
-
- 74 assign_stmt: id ASSIGN expression .
- 98 expression: expression . GE expr
- 99 | expression . GT expr
- 100 | expression . LE expr
- 101 | expression . LT expr
- 102 | expression . EQUAL expr
- 103 | expression . UNEQUAL expr
-
- GE shift, and go to state 87
- GT shift, and go to state 88
- LE shift, and go to state 89
- LT shift, and go to state 90
- EQUAL shift, and go to state 91
- UNEQUAL shift, and go to state 92
-
- $default reduce using rule 74 (assign_stmt)
-
-
-State 118
-
- 80 proc_stmt: sys_proc LP expression_list . RP
-
- RP shift, and go to state 166
-
-
-State 119
-
- 96 expression_list: expression . COMMA expression_list
- 97 | expression .
- 98 expression: expression . GE expr
- 99 | expression . GT expr
- 100 | expression . LE expr
- 101 | expression . LT expr
- 102 | expression . EQUAL expr
- 103 | expression . UNEQUAL expr
-
- COMMA shift, and go to state 167
- GE shift, and go to state 87
- GT shift, and go to state 88
- LE shift, and go to state 89
- LT shift, and go to state 90
- EQUAL shift, and go to state 91
- UNEQUAL shift, and go to state 92
-
- $default reduce using rule 97 (expression_list)
-
-
-State 120
-
- 8 const_expr_list: id EQUAL const_value . SEMI const_expr_list
- 9 | id EQUAL const_value . SEMI
-
- SEMI shift, and go to state 168
-
-
-State 121
-
- 17 type_decl_list: type_definition type_decl_list .
-
- $default reduce using rule 17 (type_decl_list)
-
-
-State 122
-
- 19 type_definition: id EQUAL . type_decl SEMI
-
- LP shift, and go to state 169
- MINUS shift, and go to state 170
- ARRAY shift, and go to state 171
- RECORD shift, and go to state 172
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_TYPE shift, and go to state 173
-
- const_value 转到状态 174
- type_decl 转到状态 175
- simple_type_decl 转到状态 176
- array_type_decl 转到状态 177
- record_type_decl 转到状态 178
- id 转到状态 179
- sys_con 转到状态 62
- sys_type 转到状态 180
-
-
-State 123
-
- 35 name_list: name_list . COMMA id
- 41 var_decl: name_list . COLON type_decl SEMI
-
- COMMA shift, and go to state 181
- COLON shift, and go to state 182
-
-
-State 124
-
- 37 var_part: VAR var_decl_list .
-
- $default reduce using rule 37 (var_part)
-
-
-State 125
-
- 39 var_decl_list: var_decl . var_decl_list
- 40 | var_decl .
-
- ID shift, and go to state 4
-
- $default reduce using rule 40 (var_decl_list)
-
- name_list 转到状态 123
- var_decl_list 转到状态 183
- var_decl 转到状态 125
- id 转到状态 126
-
-
-State 126
-
- 36 name_list: id .
-
- $default reduce using rule 36 (name_list)
-
-
-State 127
-
- 46 function_head: FUNCTION . id parameters COLON simple_type_decl
-
- ID shift, and go to state 4
-
- id 转到状态 184
-
-
-State 128
-
- 48 procedure_head: PROCEDURE . id parameters
-
- ID shift, and go to state 4
-
- id 转到状态 185
-
-
-State 129
-
- 4 routine_head: label_part const_part type_part var_part routine_part .
-
- $default reduce using rule 4 (routine_head)
-
-
-State 130
-
- 42 routine_part: function_decl . routine_part
-
- FUNCTION shift, and go to state 127
- PROCEDURE shift, and go to state 128
-
- $default reduce using rule 44 (routine_part)
-
- routine_part 转到状态 186
- function_decl 转到状态 130
- function_head 转到状态 131
- procedure_decl 转到状态 132
- procedure_head 转到状态 133
-
-
-State 131
-
- 45 function_decl: function_head . SEMI sub_routine SEMI
-
- SEMI shift, and go to state 187
-
-
-State 132
-
- 43 routine_part: procedure_decl . routine_part
-
- FUNCTION shift, and go to state 127
- PROCEDURE shift, and go to state 128
-
- $default reduce using rule 44 (routine_part)
-
- routine_part 转到状态 188
- function_decl 转到状态 130
- function_head 转到状态 131
- procedure_decl 转到状态 132
- procedure_head 转到状态 133
-
-
-State 133
-
- 47 procedure_decl: procedure_head . SEMI sub_routine SEMI
-
- SEMI shift, and go to state 189
-
-
-State 134
-
- 120 factor: LP expression RP .
-
- $default reduce using rule 120 (factor)
-
-
-State 135
-
- 98 expression: expression GE expr .
- 105 expr: expr . PLUS term
- 106 | expr . MINUS term
- 107 | expr . OR term
-
- PLUS shift, and go to state 94
- MINUS shift, and go to state 95
- OR shift, and go to state 96
-
- $default reduce using rule 98 (expression)
-
-
-State 136
-
- 99 expression: expression GT expr .
- 105 expr: expr . PLUS term
- 106 | expr . MINUS term
- 107 | expr . OR term
-
- PLUS shift, and go to state 94
- MINUS shift, and go to state 95
- OR shift, and go to state 96
-
- $default reduce using rule 99 (expression)
-
-
-State 137
-
- 100 expression: expression LE expr .
- 105 expr: expr . PLUS term
- 106 | expr . MINUS term
- 107 | expr . OR term
-
- PLUS shift, and go to state 94
- MINUS shift, and go to state 95
- OR shift, and go to state 96
-
- $default reduce using rule 100 (expression)
-
-
-State 138
-
- 101 expression: expression LT expr .
- 105 expr: expr . PLUS term
- 106 | expr . MINUS term
- 107 | expr . OR term
-
- PLUS shift, and go to state 94
- MINUS shift, and go to state 95
- OR shift, and go to state 96
-
- $default reduce using rule 101 (expression)
-
-
-State 139
-
- 102 expression: expression EQUAL expr .
- 105 expr: expr . PLUS term
- 106 | expr . MINUS term
- 107 | expr . OR term
-
- PLUS shift, and go to state 94
- MINUS shift, and go to state 95
- OR shift, and go to state 96
-
- $default reduce using rule 102 (expression)
-
-
-State 140
-
- 103 expression: expression UNEQUAL expr .
- 105 expr: expr . PLUS term
- 106 | expr . MINUS term
- 107 | expr . OR term
-
- PLUS shift, and go to state 94
- MINUS shift, and go to state 95
- OR shift, and go to state 96
-
- $default reduce using rule 103 (expression)
-
-
-State 141
-
- 82 if_stmt: IF expression THEN stmt . else_clause
-
- ELSE shift, and go to state 190
-
- ELSE [reduce using rule 84 (else_clause)]
- $default reduce using rule 84 (else_clause)
-
- else_clause 转到状态 191
-
-
-State 142
-
- 105 expr: expr PLUS term .
- 109 term: term . MUL factor
- 110 | term . INTDIV factor
- 111 | term . REALDIV factor
- 112 | term . MOD factor
- 113 | term . AND factor
-
- MUL shift, and go to state 97
- REALDIV shift, and go to state 98
- INTDIV shift, and go to state 99
- MOD shift, and go to state 100
- AND shift, and go to state 101
-
- $default reduce using rule 105 (expr)
-
-
-State 143
-
- 106 expr: expr MINUS term .
- 109 term: term . MUL factor
- 110 | term . INTDIV factor
- 111 | term . REALDIV factor
- 112 | term . MOD factor
- 113 | term . AND factor
-
- MUL shift, and go to state 97
- REALDIV shift, and go to state 98
- INTDIV shift, and go to state 99
- MOD shift, and go to state 100
- AND shift, and go to state 101
-
- $default reduce using rule 106 (expr)
-
-
-State 144
-
- 107 expr: expr OR term .
- 109 term: term . MUL factor
- 110 | term . INTDIV factor
- 111 | term . REALDIV factor
- 112 | term . MOD factor
- 113 | term . AND factor
-
- MUL shift, and go to state 97
- REALDIV shift, and go to state 98
- INTDIV shift, and go to state 99
- MOD shift, and go to state 100
- AND shift, and go to state 101
-
- $default reduce using rule 107 (expr)
-
-
-State 145
-
- 109 term: term MUL factor .
-
- $default reduce using rule 109 (term)
-
-
-State 146
-
- 111 term: term REALDIV factor .
-
- $default reduce using rule 111 (term)
-
-
-State 147
-
- 110 term: term INTDIV factor .
-
- $default reduce using rule 110 (term)
-
-
-State 148
-
- 112 term: term MOD factor .
-
- $default reduce using rule 112 (term)
-
-
-State 149
-
- 113 term: term AND factor .
-
- $default reduce using rule 113 (term)
-
-
-State 150
-
- 116 factor: id LP args_list . RP
- 125 args_list: args_list . COMMA expression
-
- RP shift, and go to state 192
- COMMA shift, and go to state 163
-
-
-State 151
-
- 98 expression: expression . GE expr
- 99 | expression . GT expr
- 100 | expression . LE expr
- 101 | expression . LT expr
- 102 | expression . EQUAL expr
- 103 | expression . UNEQUAL expr
- 123 factor: id LB expression . RB
-
- RB shift, and go to state 193
- GE shift, and go to state 87
- GT shift, and go to state 88
- LE shift, and go to state 89
- LT shift, and go to state 90
- EQUAL shift, and go to state 91
- UNEQUAL shift, and go to state 92
-
-
-State 152
-
- 124 factor: id DOT id .
-
- $default reduce using rule 124 (factor)
-
-
-State 153
-
- 118 factor: sys_funct LP args_list . RP
- 125 args_list: args_list . COMMA expression
-
- RP shift, and go to state 194
- COMMA shift, and go to state 163
-
-
-State 154
-
- 85 repeat_stmt: REPEAT stmt UNTIL expression .
- 98 expression: expression . GE expr
- 99 | expression . GT expr
- 100 | expression . LE expr
- 101 | expression . LT expr
- 102 | expression . EQUAL expr
- 103 | expression . UNEQUAL expr
-
- GE shift, and go to state 87
- GT shift, and go to state 88
- LE shift, and go to state 89
- LT shift, and go to state 90
- EQUAL shift, and go to state 91
- UNEQUAL shift, and go to state 92
-
- $default reduce using rule 85 (repeat_stmt)
-
-
-State 155
-
- 86 while_stmt: WHILE expression DO stmt .
-
- $default reduce using rule 86 (while_stmt)
-
-
-State 156
-
- 87 for_stmt: FOR id ASSIGN expression . direction expression DO stmt
- 98 expression: expression . GE expr
- 99 | expression . GT expr
- 100 | expression . LE expr
- 101 | expression . LT expr
- 102 | expression . EQUAL expr
- 103 | expression . UNEQUAL expr
-
- GE shift, and go to state 87
- GT shift, and go to state 88
- LE shift, and go to state 89
- LT shift, and go to state 90
- EQUAL shift, and go to state 91
- UNEQUAL shift, and go to state 92
- TO shift, and go to state 195
- DOWNTO shift, and go to state 196
-
- direction 转到状态 197
-
-
-State 157
-
- 93 case_expr: const_value . COLON stmt SEMI
-
- COLON shift, and go to state 198
-
-
-State 158
-
- 90 case_stmt: CASE expression OF case_expr_list . END
-
- END shift, and go to state 199
-
-
-State 159
-
- 91 case_expr_list: case_expr . case_expr_list
- 92 | case_expr .
-
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
-
- $default reduce using rule 92 (case_expr_list)
-
- const_value 转到状态 157
- case_expr_list 转到状态 200
- case_expr 转到状态 159
- id 转到状态 160
- sys_con 转到状态 62
-
-
-State 160
-
- 94 case_expr: id . COLON stmt SEMI
-
- COLON shift, and go to state 201
-
-
-State 161
-
- 81 proc_stmt: READ LP factor RP .
-
- $default reduce using rule 81 (proc_stmt)
-
-
-State 162
-
- 78 proc_stmt: id LP args_list RP .
-
- $default reduce using rule 78 (proc_stmt)
-
-
-State 163
-
- 125 args_list: args_list COMMA . expression
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- expression 转到状态 202
- expr 转到状态 58
- term 转到状态 59
- factor 转到状态 60
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 164
-
- 75 assign_stmt: id LB expression RB . ASSIGN expression
-
- ASSIGN shift, and go to state 203
-
-
-State 165
-
- 76 assign_stmt: id DOT id ASSIGN . expression
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- expression 转到状态 204
- expr 转到状态 58
- term 转到状态 59
- factor 转到状态 60
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 166
-
- 80 proc_stmt: sys_proc LP expression_list RP .
-
- $default reduce using rule 80 (proc_stmt)
-
-
-State 167
-
- 96 expression_list: expression COMMA . expression_list
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- expression_list 转到状态 205
- expression 转到状态 119
- expr 转到状态 58
- term 转到状态 59
- factor 转到状态 60
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 168
-
- 8 const_expr_list: id EQUAL const_value SEMI . const_expr_list
- 9 | id EQUAL const_value SEMI .
-
- ID shift, and go to state 4
-
- $default reduce using rule 9 (const_expr_list)
-
- const_expr_list 转到状态 206
- id 转到状态 43
-
-
-State 169
-
- 25 simple_type_decl: LP . name_list RP
-
- ID shift, and go to state 4
-
- name_list 转到状态 207
- id 转到状态 126
-
-
-State 170
-
- 27 simple_type_decl: MINUS . const_value DOTDOT const_value
- 28 | MINUS . const_value DOTDOT MINUS const_value
-
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
-
- const_value 转到状态 208
- sys_con 转到状态 62
-
-
-State 171
-
- 30 array_type_decl: ARRAY . LB simple_type_decl RB OF type_decl
-
- LB shift, and go to state 209
-
-
-State 172
-
- 31 record_type_decl: RECORD . field_decl_list END
-
- ID shift, and go to state 4
-
- field_decl_list 转到状态 210
- field_decl 转到状态 211
- name_list 转到状态 212
- id 转到状态 126
-
-
-State 173
-
- 131 sys_type: SYS_TYPE .
-
- $default reduce using rule 131 (sys_type)
-
-
-State 174
-
- 26 simple_type_decl: const_value . DOTDOT const_value
-
- DOTDOT shift, and go to state 213
-
-
-State 175
-
- 19 type_definition: id EQUAL type_decl . SEMI
-
- SEMI shift, and go to state 214
-
-
-State 176
-
- 20 type_decl: simple_type_decl .
-
- $default reduce using rule 20 (type_decl)
-
-
-State 177
-
- 21 type_decl: array_type_decl .
-
- $default reduce using rule 21 (type_decl)
-
-
-State 178
-
- 22 type_decl: record_type_decl .
-
- $default reduce using rule 22 (type_decl)
-
-
-State 179
-
- 24 simple_type_decl: id .
- 29 | id . DOTDOT id
-
- DOTDOT shift, and go to state 215
-
- $default reduce using rule 24 (simple_type_decl)
-
-
-State 180
-
- 23 simple_type_decl: sys_type .
-
- $default reduce using rule 23 (simple_type_decl)
-
-
-State 181
-
- 35 name_list: name_list COMMA . id
-
- ID shift, and go to state 4
-
- id 转到状态 216
-
-
-State 182
-
- 41 var_decl: name_list COLON . type_decl SEMI
-
- LP shift, and go to state 169
- MINUS shift, and go to state 170
- ARRAY shift, and go to state 171
- RECORD shift, and go to state 172
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_TYPE shift, and go to state 173
-
- const_value 转到状态 174
- type_decl 转到状态 217
- simple_type_decl 转到状态 176
- array_type_decl 转到状态 177
- record_type_decl 转到状态 178
- id 转到状态 179
- sys_con 转到状态 62
- sys_type 转到状态 180
-
-
-State 183
-
- 39 var_decl_list: var_decl var_decl_list .
-
- $default reduce using rule 39 (var_decl_list)
-
-
-State 184
-
- 46 function_head: FUNCTION id . parameters COLON simple_type_decl
-
- LP shift, and go to state 218
-
- $default reduce using rule 51 (parameters)
-
- parameters 转到状态 219
-
-
-State 185
-
- 48 procedure_head: PROCEDURE id . parameters
-
- LP shift, and go to state 218
-
- $default reduce using rule 51 (parameters)
-
- parameters 转到状态 220
-
-
-State 186
-
- 42 routine_part: function_decl routine_part .
-
- $default reduce using rule 42 (routine_part)
-
-
-State 187
-
- 45 function_decl: function_head SEMI . sub_routine SEMI
-
- $default reduce using rule 5 (label_part)
-
- routine_head 转到状态 221
- label_part 转到状态 9
- sub_routine 转到状态 222
-
-
-State 188
-
- 43 routine_part: procedure_decl routine_part .
-
- $default reduce using rule 43 (routine_part)
-
-
-State 189
-
- 47 procedure_decl: procedure_head SEMI . sub_routine SEMI
-
- $default reduce using rule 5 (label_part)
-
- routine_head 转到状态 221
- label_part 转到状态 9
- sub_routine 转到状态 223
-
-
-State 190
-
- 83 else_clause: ELSE . stmt
-
- BEGIN_T shift, and go to state 12
- IF shift, and go to state 18
- REPEAT shift, and go to state 19
- WHILE shift, and go to state 20
- FOR shift, and go to state 21
- CASE shift, and go to state 22
- GOTO shift, and go to state 23
- READ shift, and go to state 24
- INTEGER shift, and go to state 25
- ID shift, and go to state 4
- SYS_PROC shift, and go to state 26
-
- compound_stmt 转到状态 27
- stmt 转到状态 224
- non_label_stmt 转到状态 30
- assign_stmt 转到状态 31
- proc_stmt 转到状态 32
- if_stmt 转到状态 33
- repeat_stmt 转到状态 34
- while_stmt 转到状态 35
- for_stmt 转到状态 36
- case_stmt 转到状态 37
- goto_stmt 转到状态 38
- id 转到状态 39
- sys_proc 转到状态 40
-
-
-State 191
-
- 82 if_stmt: IF expression THEN stmt else_clause .
-
- $default reduce using rule 82 (if_stmt)
-
-
-State 192
-
- 116 factor: id LP args_list RP .
-
- $default reduce using rule 116 (factor)
-
-
-State 193
-
- 123 factor: id LB expression RB .
-
- $default reduce using rule 123 (factor)
-
-
-State 194
-
- 118 factor: sys_funct LP args_list RP .
-
- $default reduce using rule 118 (factor)
-
-
-State 195
-
- 88 direction: TO .
-
- $default reduce using rule 88 (direction)
-
-
-State 196
-
- 89 direction: DOWNTO .
-
- $default reduce using rule 89 (direction)
-
-
-State 197
-
- 87 for_stmt: FOR id ASSIGN expression direction . expression DO stmt
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- expression 转到状态 225
- expr 转到状态 58
- term 转到状态 59
- factor 转到状态 60
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 198
-
- 93 case_expr: const_value COLON . stmt SEMI
-
- BEGIN_T shift, and go to state 12
- IF shift, and go to state 18
- REPEAT shift, and go to state 19
- WHILE shift, and go to state 20
- FOR shift, and go to state 21
- CASE shift, and go to state 22
- GOTO shift, and go to state 23
- READ shift, and go to state 24
- INTEGER shift, and go to state 25
- ID shift, and go to state 4
- SYS_PROC shift, and go to state 26
-
- compound_stmt 转到状态 27
- stmt 转到状态 226
- non_label_stmt 转到状态 30
- assign_stmt 转到状态 31
- proc_stmt 转到状态 32
- if_stmt 转到状态 33
- repeat_stmt 转到状态 34
- while_stmt 转到状态 35
- for_stmt 转到状态 36
- case_stmt 转到状态 37
- goto_stmt 转到状态 38
- id 转到状态 39
- sys_proc 转到状态 40
-
-
-State 199
-
- 90 case_stmt: CASE expression OF case_expr_list END .
-
- $default reduce using rule 90 (case_stmt)
-
-
-State 200
-
- 91 case_expr_list: case_expr case_expr_list .
-
- $default reduce using rule 91 (case_expr_list)
-
-
-State 201
-
- 94 case_expr: id COLON . stmt SEMI
-
- BEGIN_T shift, and go to state 12
- IF shift, and go to state 18
- REPEAT shift, and go to state 19
- WHILE shift, and go to state 20
- FOR shift, and go to state 21
- CASE shift, and go to state 22
- GOTO shift, and go to state 23
- READ shift, and go to state 24
- INTEGER shift, and go to state 25
- ID shift, and go to state 4
- SYS_PROC shift, and go to state 26
-
- compound_stmt 转到状态 27
- stmt 转到状态 227
- non_label_stmt 转到状态 30
- assign_stmt 转到状态 31
- proc_stmt 转到状态 32
- if_stmt 转到状态 33
- repeat_stmt 转到状态 34
- while_stmt 转到状态 35
- for_stmt 转到状态 36
- case_stmt 转到状态 37
- goto_stmt 转到状态 38
- id 转到状态 39
- sys_proc 转到状态 40
-
-
-State 202
-
- 98 expression: expression . GE expr
- 99 | expression . GT expr
- 100 | expression . LE expr
- 101 | expression . LT expr
- 102 | expression . EQUAL expr
- 103 | expression . UNEQUAL expr
- 125 args_list: args_list COMMA expression .
-
- GE shift, and go to state 87
- GT shift, and go to state 88
- LE shift, and go to state 89
- LT shift, and go to state 90
- EQUAL shift, and go to state 91
- UNEQUAL shift, and go to state 92
-
- $default reduce using rule 125 (args_list)
-
-
-State 203
-
- 75 assign_stmt: id LB expression RB ASSIGN . expression
-
- LP shift, and go to state 47
- MINUS shift, and go to state 48
- NOT shift, and go to state 49
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_FUNCT shift, and go to state 55
-
- const_value 转到状态 56
- expression 转到状态 228
- expr 转到状态 58
- term 转到状态 59
- factor 转到状态 60
- id 转到状态 61
- sys_con 转到状态 62
- sys_funct 转到状态 63
-
-
-State 204
-
- 76 assign_stmt: id DOT id ASSIGN expression .
- 98 expression: expression . GE expr
- 99 | expression . GT expr
- 100 | expression . LE expr
- 101 | expression . LT expr
- 102 | expression . EQUAL expr
- 103 | expression . UNEQUAL expr
-
- GE shift, and go to state 87
- GT shift, and go to state 88
- LE shift, and go to state 89
- LT shift, and go to state 90
- EQUAL shift, and go to state 91
- UNEQUAL shift, and go to state 92
-
- $default reduce using rule 76 (assign_stmt)
-
-
-State 205
-
- 96 expression_list: expression COMMA expression_list .
-
- $default reduce using rule 96 (expression_list)
-
-
-State 206
-
- 8 const_expr_list: id EQUAL const_value SEMI const_expr_list .
-
- $default reduce using rule 8 (const_expr_list)
-
-
-State 207
-
- 25 simple_type_decl: LP name_list . RP
- 35 name_list: name_list . COMMA id
-
- RP shift, and go to state 229
- COMMA shift, and go to state 181
-
-
-State 208
-
- 27 simple_type_decl: MINUS const_value . DOTDOT const_value
- 28 | MINUS const_value . DOTDOT MINUS const_value
-
- DOTDOT shift, and go to state 230
-
-
-State 209
-
- 30 array_type_decl: ARRAY LB . simple_type_decl RB OF type_decl
-
- LP shift, and go to state 169
- MINUS shift, and go to state 170
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_TYPE shift, and go to state 173
-
- const_value 转到状态 174
- simple_type_decl 转到状态 231
- id 转到状态 179
- sys_con 转到状态 62
- sys_type 转到状态 180
-
-
-State 210
-
- 31 record_type_decl: RECORD field_decl_list . END
-
- END shift, and go to state 232
-
-
-State 211
-
- 32 field_decl_list: field_decl . field_decl_list
- 33 | field_decl .
-
- ID shift, and go to state 4
-
- $default reduce using rule 33 (field_decl_list)
-
- field_decl_list 转到状态 233
- field_decl 转到状态 211
- name_list 转到状态 212
- id 转到状态 126
-
-
-State 212
-
- 34 field_decl: name_list . COLON type_decl SEMI
- 35 name_list: name_list . COMMA id
-
- COMMA shift, and go to state 181
- COLON shift, and go to state 234
-
-
-State 213
-
- 26 simple_type_decl: const_value DOTDOT . const_value
-
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
-
- const_value 转到状态 235
- sys_con 转到状态 62
-
-
-State 214
-
- 19 type_definition: id EQUAL type_decl SEMI .
-
- $default reduce using rule 19 (type_definition)
-
-
-State 215
-
- 29 simple_type_decl: id DOTDOT . id
-
- ID shift, and go to state 4
-
- id 转到状态 236
-
-
-State 216
-
- 35 name_list: name_list COMMA id .
-
- $default reduce using rule 35 (name_list)
-
-
-State 217
-
- 41 var_decl: name_list COLON type_decl . SEMI
-
- SEMI shift, and go to state 237
-
-
-State 218
-
- 50 parameters: LP . para_decl_list RP
-
- VAR shift, and go to state 238
- ID shift, and go to state 4
-
- name_list 转到状态 239
- para_decl_list 转到状态 240
- para_type_list 转到状态 241
- var_para_list 转到状态 242
- val_para_list 转到状态 243
- id 转到状态 126
-
-
-State 219
-
- 46 function_head: FUNCTION id parameters . COLON simple_type_decl
-
- COLON shift, and go to state 244
-
-
-State 220
-
- 48 procedure_head: PROCEDURE id parameters .
-
- $default reduce using rule 48 (procedure_head)
-
-
-State 221
-
- 49 sub_routine: routine_head . routine_body
-
- BEGIN_T shift, and go to state 12
-
- routine_body 转到状态 245
- compound_stmt 转到状态 14
-
-
-State 222
-
- 45 function_decl: function_head SEMI sub_routine . SEMI
-
- SEMI shift, and go to state 246
-
-
-State 223
-
- 47 procedure_decl: procedure_head SEMI sub_routine . SEMI
-
- SEMI shift, and go to state 247
-
-
-State 224
-
- 83 else_clause: ELSE stmt .
-
- $default reduce using rule 83 (else_clause)
-
-
-State 225
-
- 87 for_stmt: FOR id ASSIGN expression direction expression . DO stmt
- 98 expression: expression . GE expr
- 99 | expression . GT expr
- 100 | expression . LE expr
- 101 | expression . LT expr
- 102 | expression . EQUAL expr
- 103 | expression . UNEQUAL expr
-
- GE shift, and go to state 87
- GT shift, and go to state 88
- LE shift, and go to state 89
- LT shift, and go to state 90
- EQUAL shift, and go to state 91
- UNEQUAL shift, and go to state 92
- DO shift, and go to state 248
-
-
-State 226
-
- 93 case_expr: const_value COLON stmt . SEMI
-
- SEMI shift, and go to state 249
-
-
-State 227
-
- 94 case_expr: id COLON stmt . SEMI
-
- SEMI shift, and go to state 250
-
-
-State 228
-
- 75 assign_stmt: id LB expression RB ASSIGN expression .
- 98 expression: expression . GE expr
- 99 | expression . GT expr
- 100 | expression . LE expr
- 101 | expression . LT expr
- 102 | expression . EQUAL expr
- 103 | expression . UNEQUAL expr
-
- GE shift, and go to state 87
- GT shift, and go to state 88
- LE shift, and go to state 89
- LT shift, and go to state 90
- EQUAL shift, and go to state 91
- UNEQUAL shift, and go to state 92
-
- $default reduce using rule 75 (assign_stmt)
-
-
-State 229
-
- 25 simple_type_decl: LP name_list RP .
-
- $default reduce using rule 25 (simple_type_decl)
-
-
-State 230
-
- 27 simple_type_decl: MINUS const_value DOTDOT . const_value
- 28 | MINUS const_value DOTDOT . MINUS const_value
-
- MINUS shift, and go to state 251
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
-
- const_value 转到状态 252
- sys_con 转到状态 62
-
-
-State 231
-
- 30 array_type_decl: ARRAY LB simple_type_decl . RB OF type_decl
-
- RB shift, and go to state 253
-
-
-State 232
-
- 31 record_type_decl: RECORD field_decl_list END .
-
- $default reduce using rule 31 (record_type_decl)
-
-
-State 233
-
- 32 field_decl_list: field_decl field_decl_list .
-
- $default reduce using rule 32 (field_decl_list)
-
-
-State 234
-
- 34 field_decl: name_list COLON . type_decl SEMI
-
- LP shift, and go to state 169
- MINUS shift, and go to state 170
- ARRAY shift, and go to state 171
- RECORD shift, and go to state 172
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_TYPE shift, and go to state 173
-
- const_value 转到状态 174
- type_decl 转到状态 254
- simple_type_decl 转到状态 176
- array_type_decl 转到状态 177
- record_type_decl 转到状态 178
- id 转到状态 179
- sys_con 转到状态 62
- sys_type 转到状态 180
-
-
-State 235
-
- 26 simple_type_decl: const_value DOTDOT const_value .
-
- $default reduce using rule 26 (simple_type_decl)
-
-
-State 236
-
- 29 simple_type_decl: id DOTDOT id .
-
- $default reduce using rule 29 (simple_type_decl)
-
-
-State 237
-
- 41 var_decl: name_list COLON type_decl SEMI .
-
- $default reduce using rule 41 (var_decl)
-
-
-State 238
-
- 56 var_para_list: VAR . name_list
-
- ID shift, and go to state 4
-
- name_list 转到状态 255
- id 转到状态 126
-
-
-State 239
-
- 35 name_list: name_list . COMMA id
- 57 val_para_list: name_list .
-
- COMMA shift, and go to state 181
-
- $default reduce using rule 57 (val_para_list)
-
-
-State 240
-
- 50 parameters: LP para_decl_list . RP
- 52 para_decl_list: para_decl_list . SEMI para_type_list
-
- RP shift, and go to state 256
- SEMI shift, and go to state 257
-
-
-State 241
-
- 53 para_decl_list: para_type_list .
-
- $default reduce using rule 53 (para_decl_list)
-
-
-State 242
-
- 54 para_type_list: var_para_list . COLON simple_type_decl
-
- COLON shift, and go to state 258
-
-
-State 243
-
- 55 para_type_list: val_para_list . COLON simple_type_decl
-
- COLON shift, and go to state 259
-
-
-State 244
-
- 46 function_head: FUNCTION id parameters COLON . simple_type_decl
-
- LP shift, and go to state 169
- MINUS shift, and go to state 170
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_TYPE shift, and go to state 173
-
- const_value 转到状态 174
- simple_type_decl 转到状态 260
- id 转到状态 179
- sys_con 转到状态 62
- sys_type 转到状态 180
-
-
-State 245
-
- 49 sub_routine: routine_head routine_body .
-
- $default reduce using rule 49 (sub_routine)
-
-
-State 246
-
- 45 function_decl: function_head SEMI sub_routine SEMI .
-
- $default reduce using rule 45 (function_decl)
-
-
-State 247
-
- 47 procedure_decl: procedure_head SEMI sub_routine SEMI .
-
- $default reduce using rule 47 (procedure_decl)
-
-
-State 248
-
- 87 for_stmt: FOR id ASSIGN expression direction expression DO . stmt
-
- BEGIN_T shift, and go to state 12
- IF shift, and go to state 18
- REPEAT shift, and go to state 19
- WHILE shift, and go to state 20
- FOR shift, and go to state 21
- CASE shift, and go to state 22
- GOTO shift, and go to state 23
- READ shift, and go to state 24
- INTEGER shift, and go to state 25
- ID shift, and go to state 4
- SYS_PROC shift, and go to state 26
-
- compound_stmt 转到状态 27
- stmt 转到状态 261
- non_label_stmt 转到状态 30
- assign_stmt 转到状态 31
- proc_stmt 转到状态 32
- if_stmt 转到状态 33
- repeat_stmt 转到状态 34
- while_stmt 转到状态 35
- for_stmt 转到状态 36
- case_stmt 转到状态 37
- goto_stmt 转到状态 38
- id 转到状态 39
- sys_proc 转到状态 40
-
-
-State 249
-
- 93 case_expr: const_value COLON stmt SEMI .
-
- $default reduce using rule 93 (case_expr)
-
-
-State 250
-
- 94 case_expr: id COLON stmt SEMI .
-
- $default reduce using rule 94 (case_expr)
-
-
-State 251
-
- 28 simple_type_decl: MINUS const_value DOTDOT MINUS . const_value
-
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
-
- const_value 转到状态 262
- sys_con 转到状态 62
-
-
-State 252
-
- 27 simple_type_decl: MINUS const_value DOTDOT const_value .
-
- $default reduce using rule 27 (simple_type_decl)
-
-
-State 253
-
- 30 array_type_decl: ARRAY LB simple_type_decl RB . OF type_decl
-
- OF shift, and go to state 263
-
-
-State 254
-
- 34 field_decl: name_list COLON type_decl . SEMI
-
- SEMI shift, and go to state 264
-
-
-State 255
-
- 35 name_list: name_list . COMMA id
- 56 var_para_list: VAR name_list .
-
- COMMA shift, and go to state 181
-
- $default reduce using rule 56 (var_para_list)
-
-
-State 256
-
- 50 parameters: LP para_decl_list RP .
-
- $default reduce using rule 50 (parameters)
-
-
-State 257
-
- 52 para_decl_list: para_decl_list SEMI . para_type_list
-
- VAR shift, and go to state 238
- ID shift, and go to state 4
-
- name_list 转到状态 239
- para_type_list 转到状态 265
- var_para_list 转到状态 242
- val_para_list 转到状态 243
- id 转到状态 126
-
-
-State 258
-
- 54 para_type_list: var_para_list COLON . simple_type_decl
-
- LP shift, and go to state 169
- MINUS shift, and go to state 170
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_TYPE shift, and go to state 173
-
- const_value 转到状态 174
- simple_type_decl 转到状态 266
- id 转到状态 179
- sys_con 转到状态 62
- sys_type 转到状态 180
-
-
-State 259
-
- 55 para_type_list: val_para_list COLON . simple_type_decl
-
- LP shift, and go to state 169
- MINUS shift, and go to state 170
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_TYPE shift, and go to state 173
-
- const_value 转到状态 174
- simple_type_decl 转到状态 267
- id 转到状态 179
- sys_con 转到状态 62
- sys_type 转到状态 180
-
-
-State 260
-
- 46 function_head: FUNCTION id parameters COLON simple_type_decl .
-
- $default reduce using rule 46 (function_head)
-
-
-State 261
-
- 87 for_stmt: FOR id ASSIGN expression direction expression DO stmt .
-
- $default reduce using rule 87 (for_stmt)
-
-
-State 262
-
- 28 simple_type_decl: MINUS const_value DOTDOT MINUS const_value .
-
- $default reduce using rule 28 (simple_type_decl)
-
-
-State 263
-
- 30 array_type_decl: ARRAY LB simple_type_decl RB OF . type_decl
-
- LP shift, and go to state 169
- MINUS shift, and go to state 170
- ARRAY shift, and go to state 171
- RECORD shift, and go to state 172
- INTEGER shift, and go to state 50
- REAL shift, and go to state 51
- CHAR shift, and go to state 52
- ID shift, and go to state 4
- STRING shift, and go to state 53
- SYS_CON shift, and go to state 54
- SYS_TYPE shift, and go to state 173
-
- const_value 转到状态 174
- type_decl 转到状态 268
- simple_type_decl 转到状态 176
- array_type_decl 转到状态 177
- record_type_decl 转到状态 178
- id 转到状态 179
- sys_con 转到状态 62
- sys_type 转到状态 180
-
-
-State 264
-
- 34 field_decl: name_list COLON type_decl SEMI .
-
- $default reduce using rule 34 (field_decl)
-
-
-State 265
-
- 52 para_decl_list: para_decl_list SEMI para_type_list .
-
- $default reduce using rule 52 (para_decl_list)
-
-
-State 266
-
- 54 para_type_list: var_para_list COLON simple_type_decl .
-
- $default reduce using rule 54 (para_type_list)
-
-
-State 267
-
- 55 para_type_list: val_para_list COLON simple_type_decl .
-
- $default reduce using rule 55 (para_type_list)
-
-
-State 268
-
- 30 array_type_decl: ARRAY LB simple_type_decl RB OF type_decl .
-
- $default reduce using rule 30 (array_type_decl)