";
80 | }
81 | }
82 | }
83 |
84 | @Override
85 | @Deprecated
86 | public String[] getTokenNames() {
87 | return tokenNames;
88 | }
89 |
90 | @Override
91 |
92 | public Vocabulary getVocabulary() {
93 | return VOCABULARY;
94 | }
95 |
96 |
97 | public SysYLexer(CharStream input) {
98 | super(input);
99 | _interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
100 | }
101 |
102 | @Override
103 | public String getGrammarFileName() { return "SysYLexer.g4"; }
104 |
105 | @Override
106 | public String[] getRuleNames() { return ruleNames; }
107 |
108 | @Override
109 | public String getSerializedATN() { return _serializedATN; }
110 |
111 | @Override
112 | public String[] getChannelNames() { return channelNames; }
113 |
114 | @Override
115 | public String[] getModeNames() { return modeNames; }
116 |
117 | @Override
118 | public ATN getATN() { return _ATN; }
119 |
120 | public static final String _serializedATN =
121 | "\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2\'\u0111\b\1\4\2\t"+
122 | "\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13"+
123 | "\t\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\4\20\t\20\4\21\t\21\4\22\t\22"+
124 | "\4\23\t\23\4\24\t\24\4\25\t\25\4\26\t\26\4\27\t\27\4\30\t\30\4\31\t\31"+
125 | "\4\32\t\32\4\33\t\33\4\34\t\34\4\35\t\35\4\36\t\36\4\37\t\37\4 \t \4!"+
126 | "\t!\4\"\t\"\4#\t#\4$\t$\4%\t%\4&\t&\4\'\t\'\4(\t(\4)\t)\4*\t*\4+\t+\3"+
127 | "\2\3\2\3\2\3\2\3\2\3\2\3\3\3\3\3\3\3\3\3\4\3\4\3\4\3\4\3\4\3\5\3\5\3\5"+
128 | "\3\6\3\6\3\6\3\6\3\6\3\7\3\7\3\7\3\7\3\7\3\7\3\b\3\b\3\b\3\b\3\b\3\b\3"+
129 | "\t\3\t\3\t\3\t\3\t\3\t\3\t\3\t\3\t\3\n\3\n\3\n\3\n\3\n\3\n\3\n\3\13\3"+
130 | "\13\3\f\3\f\3\r\3\r\3\16\3\16\3\17\3\17\3\20\3\20\3\21\3\21\3\21\3\22"+
131 | "\3\22\3\22\3\23\3\23\3\24\3\24\3\25\3\25\3\25\3\26\3\26\3\26\3\27\3\27"+
132 | "\3\30\3\30\3\30\3\31\3\31\3\31\3\32\3\32\3\33\3\33\3\34\3\34\3\35\3\35"+
133 | "\3\36\3\36\3\37\3\37\3 \3 \3!\3!\3\"\3\"\5\"\u00c1\n\"\3\"\3\"\3\"\7\""+
134 | "\u00c6\n\"\f\"\16\"\u00c9\13\"\3#\3#\3#\5#\u00ce\n#\3$\3$\3$\7$\u00d3"+
135 | "\n$\f$\16$\u00d6\13$\5$\u00d8\n$\3%\3%\6%\u00dc\n%\r%\16%\u00dd\3&\3&"+
136 | "\3&\3&\5&\u00e4\n&\3&\3&\6&\u00e8\n&\r&\16&\u00e9\3\'\6\'\u00ed\n\'\r"+
137 | "\'\16\'\u00ee\3\'\3\'\3(\3(\3(\3(\7(\u00f7\n(\f(\16(\u00fa\13(\3(\3(\3"+
138 | "(\3(\3)\3)\3)\3)\7)\u0104\n)\f)\16)\u0107\13)\3)\3)\3)\3)\3)\3*\3*\3+"+
139 | "\3+\4\u00f8\u0105\2,\3\3\5\4\7\5\t\6\13\7\r\b\17\t\21\n\23\13\25\f\27"+
140 | "\r\31\16\33\17\35\20\37\21!\22#\23%\24\'\25)\26+\27-\30/\31\61\32\63\33"+
141 | "\65\34\67\359\36;\37= ?!A\"C#E$G\2I\2K\2M%O&Q\'S\2U\2\3\2\b\3\2\63;\3"+
142 | "\2\62;\3\2\629\4\2CHch\5\2\13\f\17\17\"\"\4\2C\\c|\2\u011a\2\3\3\2\2\2"+
143 | "\2\5\3\2\2\2\2\7\3\2\2\2\2\t\3\2\2\2\2\13\3\2\2\2\2\r\3\2\2\2\2\17\3\2"+
144 | "\2\2\2\21\3\2\2\2\2\23\3\2\2\2\2\25\3\2\2\2\2\27\3\2\2\2\2\31\3\2\2\2"+
145 | "\2\33\3\2\2\2\2\35\3\2\2\2\2\37\3\2\2\2\2!\3\2\2\2\2#\3\2\2\2\2%\3\2\2"+
146 | "\2\2\'\3\2\2\2\2)\3\2\2\2\2+\3\2\2\2\2-\3\2\2\2\2/\3\2\2\2\2\61\3\2\2"+
147 | "\2\2\63\3\2\2\2\2\65\3\2\2\2\2\67\3\2\2\2\29\3\2\2\2\2;\3\2\2\2\2=\3\2"+
148 | "\2\2\2?\3\2\2\2\2A\3\2\2\2\2C\3\2\2\2\2E\3\2\2\2\2M\3\2\2\2\2O\3\2\2\2"+
149 | "\2Q\3\2\2\2\3W\3\2\2\2\5]\3\2\2\2\7a\3\2\2\2\tf\3\2\2\2\13i\3\2\2\2\r"+
150 | "n\3\2\2\2\17t\3\2\2\2\21z\3\2\2\2\23\u0083\3\2\2\2\25\u008a\3\2\2\2\27"+
151 | "\u008c\3\2\2\2\31\u008e\3\2\2\2\33\u0090\3\2\2\2\35\u0092\3\2\2\2\37\u0094"+
152 | "\3\2\2\2!\u0096\3\2\2\2#\u0099\3\2\2\2%\u009c\3\2\2\2\'\u009e\3\2\2\2"+
153 | ")\u00a0\3\2\2\2+\u00a3\3\2\2\2-\u00a6\3\2\2\2/\u00a8\3\2\2\2\61\u00ab"+
154 | "\3\2\2\2\63\u00ae\3\2\2\2\65\u00b0\3\2\2\2\67\u00b2\3\2\2\29\u00b4\3\2"+
155 | "\2\2;\u00b6\3\2\2\2=\u00b8\3\2\2\2?\u00ba\3\2\2\2A\u00bc\3\2\2\2C\u00c0"+
156 | "\3\2\2\2E\u00cd\3\2\2\2G\u00d7\3\2\2\2I\u00d9\3\2\2\2K\u00e3\3\2\2\2M"+
157 | "\u00ec\3\2\2\2O\u00f2\3\2\2\2Q\u00ff\3\2\2\2S\u010d\3\2\2\2U\u010f\3\2"+
158 | "\2\2WX\7e\2\2XY\7q\2\2YZ\7p\2\2Z[\7u\2\2[\\\7v\2\2\\\4\3\2\2\2]^\7k\2"+
159 | "\2^_\7p\2\2_`\7v\2\2`\6\3\2\2\2ab\7x\2\2bc\7q\2\2cd\7k\2\2de\7f\2\2e\b"+
160 | "\3\2\2\2fg\7k\2\2gh\7h\2\2h\n\3\2\2\2ij\7g\2\2jk\7n\2\2kl\7u\2\2lm\7g"+
161 | "\2\2m\f\3\2\2\2no\7y\2\2op\7j\2\2pq\7k\2\2qr\7n\2\2rs\7g\2\2s\16\3\2\2"+
162 | "\2tu\7d\2\2uv\7t\2\2vw\7g\2\2wx\7c\2\2xy\7m\2\2y\20\3\2\2\2z{\7e\2\2{"+
163 | "|\7q\2\2|}\7p\2\2}~\7v\2\2~\177\7k\2\2\177\u0080\7p\2\2\u0080\u0081\7"+
164 | "w\2\2\u0081\u0082\7g\2\2\u0082\22\3\2\2\2\u0083\u0084\7t\2\2\u0084\u0085"+
165 | "\7g\2\2\u0085\u0086\7v\2\2\u0086\u0087\7w\2\2\u0087\u0088\7t\2\2\u0088"+
166 | "\u0089\7p\2\2\u0089\24\3\2\2\2\u008a\u008b\7-\2\2\u008b\26\3\2\2\2\u008c"+
167 | "\u008d\7/\2\2\u008d\30\3\2\2\2\u008e\u008f\7,\2\2\u008f\32\3\2\2\2\u0090"+
168 | "\u0091\7\61\2\2\u0091\34\3\2\2\2\u0092\u0093\7\'\2\2\u0093\36\3\2\2\2"+
169 | "\u0094\u0095\7?\2\2\u0095 \3\2\2\2\u0096\u0097\7?\2\2\u0097\u0098\7?\2"+
170 | "\2\u0098\"\3\2\2\2\u0099\u009a\7#\2\2\u009a\u009b\7?\2\2\u009b$\3\2\2"+
171 | "\2\u009c\u009d\7>\2\2\u009d&\3\2\2\2\u009e\u009f\7@\2\2\u009f(\3\2\2\2"+
172 | "\u00a0\u00a1\7>\2\2\u00a1\u00a2\7?\2\2\u00a2*\3\2\2\2\u00a3\u00a4\7@\2"+
173 | "\2\u00a4\u00a5\7?\2\2\u00a5,\3\2\2\2\u00a6\u00a7\7#\2\2\u00a7.\3\2\2\2"+
174 | "\u00a8\u00a9\7(\2\2\u00a9\u00aa\7(\2\2\u00aa\60\3\2\2\2\u00ab\u00ac\7"+
175 | "~\2\2\u00ac\u00ad\7~\2\2\u00ad\62\3\2\2\2\u00ae\u00af\7*\2\2\u00af\64"+
176 | "\3\2\2\2\u00b0\u00b1\7+\2\2\u00b1\66\3\2\2\2\u00b2\u00b3\7}\2\2\u00b3"+
177 | "8\3\2\2\2\u00b4\u00b5\7\177\2\2\u00b5:\3\2\2\2\u00b6\u00b7\7]\2\2\u00b7"+
178 | "<\3\2\2\2\u00b8\u00b9\7_\2\2\u00b9>\3\2\2\2\u00ba\u00bb\7.\2\2\u00bb@"+
179 | "\3\2\2\2\u00bc\u00bd\7=\2\2\u00bdB\3\2\2\2\u00be\u00c1\5S*\2\u00bf\u00c1"+
180 | "\7a\2\2\u00c0\u00be\3\2\2\2\u00c0\u00bf\3\2\2\2\u00c1\u00c7\3\2\2\2\u00c2"+
181 | "\u00c6\5S*\2\u00c3\u00c6\5U+\2\u00c4\u00c6\7a\2\2\u00c5\u00c2\3\2\2\2"+
182 | "\u00c5\u00c3\3\2\2\2\u00c5\u00c4\3\2\2\2\u00c6\u00c9\3\2\2\2\u00c7\u00c5"+
183 | "\3\2\2\2\u00c7\u00c8\3\2\2\2\u00c8D\3\2\2\2\u00c9\u00c7\3\2\2\2\u00ca"+
184 | "\u00ce\5I%\2\u00cb\u00ce\5K&\2\u00cc\u00ce\5G$\2\u00cd\u00ca\3\2\2\2\u00cd"+
185 | "\u00cb\3\2\2\2\u00cd\u00cc\3\2\2\2\u00ceF\3\2\2\2\u00cf\u00d8\7\62\2\2"+
186 | "\u00d0\u00d4\t\2\2\2\u00d1\u00d3\t\3\2\2\u00d2\u00d1\3\2\2\2\u00d3\u00d6"+
187 | "\3\2\2\2\u00d4\u00d2\3\2\2\2\u00d4\u00d5\3\2\2\2\u00d5\u00d8\3\2\2\2\u00d6"+
188 | "\u00d4\3\2\2\2\u00d7\u00cf\3\2\2\2\u00d7\u00d0\3\2\2\2\u00d8H\3\2\2\2"+
189 | "\u00d9\u00db\7\62\2\2\u00da\u00dc\t\4\2\2\u00db\u00da\3\2\2\2\u00dc\u00dd"+
190 | "\3\2\2\2\u00dd\u00db\3\2\2\2\u00dd\u00de\3\2\2\2\u00deJ\3\2\2\2\u00df"+
191 | "\u00e0\7\62\2\2\u00e0\u00e4\7z\2\2\u00e1\u00e2\7\62\2\2\u00e2\u00e4\7"+
192 | "Z\2\2\u00e3\u00df\3\2\2\2\u00e3\u00e1\3\2\2\2\u00e4\u00e7\3\2\2\2\u00e5"+
193 | "\u00e8\5U+\2\u00e6\u00e8\t\5\2\2\u00e7\u00e5\3\2\2\2\u00e7\u00e6\3\2\2"+
194 | "\2\u00e8\u00e9\3\2\2\2\u00e9\u00e7\3\2\2\2\u00e9\u00ea\3\2\2\2\u00eaL"+
195 | "\3\2\2\2\u00eb\u00ed\t\6\2\2\u00ec\u00eb\3\2\2\2\u00ed\u00ee\3\2\2\2\u00ee"+
196 | "\u00ec\3\2\2\2\u00ee\u00ef\3\2\2\2\u00ef\u00f0\3\2\2\2\u00f0\u00f1\b\'"+
197 | "\2\2\u00f1N\3\2\2\2\u00f2\u00f3\7\61\2\2\u00f3\u00f4\7\61\2\2\u00f4\u00f8"+
198 | "\3\2\2\2\u00f5\u00f7\13\2\2\2\u00f6\u00f5\3\2\2\2\u00f7\u00fa\3\2\2\2"+
199 | "\u00f8\u00f9\3\2\2\2\u00f8\u00f6\3\2\2\2\u00f9\u00fb\3\2\2\2\u00fa\u00f8"+
200 | "\3\2\2\2\u00fb\u00fc\7\f\2\2\u00fc\u00fd\3\2\2\2\u00fd\u00fe\b(\2\2\u00fe"+
201 | "P\3\2\2\2\u00ff\u0100\7\61\2\2\u0100\u0101\7,\2\2\u0101\u0105\3\2\2\2"+
202 | "\u0102\u0104\13\2\2\2\u0103\u0102\3\2\2\2\u0104\u0107\3\2\2\2\u0105\u0106"+
203 | "\3\2\2\2\u0105\u0103\3\2\2\2\u0106\u0108\3\2\2\2\u0107\u0105\3\2\2\2\u0108"+
204 | "\u0109\7,\2\2\u0109\u010a\7\61\2\2\u010a\u010b\3\2\2\2\u010b\u010c\b)"+
205 | "\2\2\u010cR\3\2\2\2\u010d\u010e\t\7\2\2\u010eT\3\2\2\2\u010f\u0110\t\3"+
206 | "\2\2\u0110V\3\2\2\2\20\2\u00c0\u00c5\u00c7\u00cd\u00d4\u00d7\u00dd\u00e3"+
207 | "\u00e7\u00e9\u00ee\u00f8\u0105\3\b\2\2";
208 | public static final ATN _ATN =
209 | new ATNDeserializer().deserialize(_serializedATN.toCharArray());
210 | static {
211 | _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
212 | for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
213 | _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
214 | }
215 | }
216 | }
--------------------------------------------------------------------------------
/src/SysYLexer.tokens:
--------------------------------------------------------------------------------
1 | CONST=1
2 | INT=2
3 | VOID=3
4 | IF=4
5 | ELSE=5
6 | WHILE=6
7 | BREAK=7
8 | CONTINUE=8
9 | RETURN=9
10 | PLUS=10
11 | MINUS=11
12 | MUL=12
13 | DIV=13
14 | MOD=14
15 | ASSIGN=15
16 | EQ=16
17 | NEQ=17
18 | LT=18
19 | GT=19
20 | LE=20
21 | GE=21
22 | NOT=22
23 | AND=23
24 | OR=24
25 | L_PAREN=25
26 | R_PAREN=26
27 | L_BRACE=27
28 | R_BRACE=28
29 | L_BRACKT=29
30 | R_BRACKT=30
31 | COMMA=31
32 | SEMICOLON=32
33 | IDENT=33
34 | INTEGR_CONST=34
35 | WS=35
36 | SL_COMMENT=36
37 | ML_COMMENT=37
38 | 'const'=1
39 | 'int'=2
40 | 'void'=3
41 | 'if'=4
42 | 'else'=5
43 | 'while'=6
44 | 'break'=7
45 | 'continue'=8
46 | 'return'=9
47 | '+'=10
48 | '-'=11
49 | '*'=12
50 | '/'=13
51 | '%'=14
52 | '='=15
53 | '=='=16
54 | '!='=17
55 | '<'=18
56 | '>'=19
57 | '<='=20
58 | '>='=21
59 | '!'=22
60 | '&&'=23
61 | '||'=24
62 | '('=25
63 | ')'=26
64 | '{'=27
65 | '}'=28
66 | '['=29
67 | ']'=30
68 | ','=31
69 | ';'=32
70 |
--------------------------------------------------------------------------------
/src/SysYParser.g4:
--------------------------------------------------------------------------------
1 | parser grammar SysYParser;
2 |
3 | options {
4 | tokenVocab = SysYLexer;
5 | }
6 |
7 | program : compUnit;
8 |
9 | // 编译单元
10 | compUnit : (funcDef | decl)+ EOF;
11 |
12 | // 下面是其他的语法单元定义
13 |
14 | // 声明
15 | decl : constDecl | varDecl;
16 |
17 | // 常量声明
18 | constDecl : CONST bType constDef (COMMA constDef)* SEMICOLON;
19 |
20 | // 基本类型
21 | bType : INT;
22 |
23 | // 常数定义
24 | constDef : IDENT (L_BRACKT constExp R_BRACKT)* ASSIGN constInitVal;
25 |
26 | // 常量初值
27 | constInitVal : constExp | L_BRACE (constInitVal (COMMA constInitVal)*)? R_BRACE;
28 |
29 | // 变量声明
30 | varDecl : bType varDef (COMMA varDef)* SEMICOLON;
31 |
32 | // 变量定义
33 | varDef : IDENT (L_BRACKT constExp R_BRACKT)* (ASSIGN initVal)?;
34 |
35 | // 变量初值
36 | initVal : exp | L_BRACE (initVal (COMMA initVal)*)? R_BRACE;
37 |
38 | // 函数定义
39 | funcDef : funcType IDENT L_PAREN (funcFParams)? R_PAREN block;
40 |
41 | // 函数类型
42 | funcType : VOID | INT;
43 |
44 | // 函数形参表
45 | funcFParams : funcFParam (COMMA funcFParam)*;
46 |
47 | // 函数形参
48 | funcFParam : bType IDENT (L_BRACKT R_BRACKT (L_BRACKT exp R_BRACKT)*)?;
49 |
50 | // 语句块
51 | block : L_BRACE (blockItem)* R_BRACE;
52 |
53 | // 语句块项
54 | blockItem : decl | stmt;
55 |
56 | // 语句
57 | stmt : lVal ASSIGN exp SEMICOLON # assignment
58 | | (exp)? SEMICOLON # possibleExp
59 | | block # blockStmt
60 | | IF L_PAREN cond R_PAREN stmt (ELSE stmt)? # ifStmt
61 | | WHILE L_PAREN cond R_PAREN stmt # whileStmt
62 | | BREAK SEMICOLON # breakStmt
63 | | CONTINUE SEMICOLON # continueStmt
64 | | RETURN (exp)? SEMICOLON # returnStmt
65 | ;
66 |
67 | // 表达式
68 | exp: L_PAREN exp R_PAREN # parenExp
69 | | lVal # lValExp
70 | | number # numExp
71 | | IDENT L_PAREN funcRParams? R_PAREN # funcCallExp
72 | | unaryOp exp # unaryExp
73 | | exp (MUL | DIV | MOD) exp # mulExp
74 | | exp (PLUS | MINUS) exp # addExp
75 | ;
76 |
77 |
78 | // 条件表达式
79 | cond: exp # condExp
80 | | cond (LT | GT | LE | GE) cond # compareExp
81 | | cond (EQ | NEQ) cond # relationExp
82 | | cond AND cond # andExp
83 | | cond OR cond # orExp
84 | ;
85 |
86 |
87 | // 左值表达式
88 | lVal : IDENT (L_BRACKT exp R_BRACKT)*;
89 |
90 | // 基本表达式
91 | // primaryExp : L_PAREN exp R_PAREN | lVal | number;
92 |
93 | // 数值
94 | number : INTEGR_CONST;
95 |
96 | // 一元表达式
97 | //unaryExp : primaryExp | IDENT L_PAREN (funcRParams)? R_PAREN | unaryOp unaryExp;
98 |
99 | // 单目运算符
100 | unaryOp : PLUS | MINUS | NOT;
101 |
102 | // 函数实参表, from TA
103 | funcRParams : param (COMMA param)*;
104 |
105 | // from TA
106 | param : exp;
107 |
108 | //// 乘除模表达式
109 | //mulExp : unaryOp | mulExp (MUL | DIV | MOD) unaryExp;
110 | //
111 | //// 加减表达式
112 | //addExp : mulExp | addExp (PLUS | MINUS) mulExp;
113 | //
114 | //// 关系表达式
115 | //relExp : addExp | relExp (LT | GT | LE | GE) addExp;
116 | //
117 | //// 相等性表达式
118 | //eqExp : relExp | eqExp (EQ | NEQ) relExp;
119 | //
120 | //// 逻辑与表达式
121 | //lAndExp : eqExp | lAndExp LAND eqExp;
122 | //
123 | //// 逻辑或表达式
124 | //lOrExp : lAndExp | lOrExp LOR lAndExp;
125 |
126 | // 常量表达式
127 | constExp : exp;
--------------------------------------------------------------------------------
/src/SysYParser.interp:
--------------------------------------------------------------------------------
1 | token literal names:
2 | null
3 | 'const'
4 | 'int'
5 | 'void'
6 | 'if'
7 | 'else'
8 | 'while'
9 | 'break'
10 | 'continue'
11 | 'return'
12 | '+'
13 | '-'
14 | '*'
15 | '/'
16 | '%'
17 | '='
18 | '=='
19 | '!='
20 | '<'
21 | '>'
22 | '<='
23 | '>='
24 | '!'
25 | '&&'
26 | '||'
27 | '('
28 | ')'
29 | '{'
30 | '}'
31 | '['
32 | ']'
33 | ','
34 | ';'
35 | null
36 | null
37 | null
38 | null
39 | null
40 |
41 | token symbolic names:
42 | null
43 | CONST
44 | INT
45 | VOID
46 | IF
47 | ELSE
48 | WHILE
49 | BREAK
50 | CONTINUE
51 | RETURN
52 | PLUS
53 | MINUS
54 | MUL
55 | DIV
56 | MOD
57 | ASSIGN
58 | EQ
59 | NEQ
60 | LT
61 | GT
62 | LE
63 | GE
64 | NOT
65 | AND
66 | OR
67 | L_PAREN
68 | R_PAREN
69 | L_BRACE
70 | R_BRACE
71 | L_BRACKT
72 | R_BRACKT
73 | COMMA
74 | SEMICOLON
75 | IDENT
76 | INTEGR_CONST
77 | WS
78 | SL_COMMENT
79 | ML_COMMENT
80 |
81 | rule names:
82 | program
83 | compUnit
84 | decl
85 | constDecl
86 | bType
87 | constDef
88 | constInitVal
89 | varDecl
90 | varDef
91 | initVal
92 | funcDef
93 | funcType
94 | funcFParams
95 | funcFParam
96 | block
97 | blockItem
98 | stmt
99 | exp
100 | cond
101 | lVal
102 | number
103 | unaryOp
104 | funcRParams
105 | param
106 | constExp
107 |
108 |
109 | atn:
110 | [3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 3, 39, 307, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 4, 12, 9, 12, 4, 13, 9, 13, 4, 14, 9, 14, 4, 15, 9, 15, 4, 16, 9, 16, 4, 17, 9, 17, 4, 18, 9, 18, 4, 19, 9, 19, 4, 20, 9, 20, 4, 21, 9, 21, 4, 22, 9, 22, 4, 23, 9, 23, 4, 24, 9, 24, 4, 25, 9, 25, 4, 26, 9, 26, 3, 2, 3, 2, 3, 3, 3, 3, 6, 3, 57, 10, 3, 13, 3, 14, 3, 58, 3, 3, 3, 3, 3, 4, 3, 4, 5, 4, 65, 10, 4, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 7, 5, 72, 10, 5, 12, 5, 14, 5, 75, 11, 5, 3, 5, 3, 5, 3, 6, 3, 6, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 7, 7, 86, 10, 7, 12, 7, 14, 7, 89, 11, 7, 3, 7, 3, 7, 3, 7, 3, 8, 3, 8, 3, 8, 3, 8, 3, 8, 7, 8, 99, 10, 8, 12, 8, 14, 8, 102, 11, 8, 5, 8, 104, 10, 8, 3, 8, 5, 8, 107, 10, 8, 3, 9, 3, 9, 3, 9, 3, 9, 7, 9, 113, 10, 9, 12, 9, 14, 9, 116, 11, 9, 3, 9, 3, 9, 3, 10, 3, 10, 3, 10, 3, 10, 3, 10, 7, 10, 125, 10, 10, 12, 10, 14, 10, 128, 11, 10, 3, 10, 3, 10, 5, 10, 132, 10, 10, 3, 11, 3, 11, 3, 11, 3, 11, 3, 11, 7, 11, 139, 10, 11, 12, 11, 14, 11, 142, 11, 11, 5, 11, 144, 10, 11, 3, 11, 5, 11, 147, 10, 11, 3, 12, 3, 12, 3, 12, 3, 12, 5, 12, 153, 10, 12, 3, 12, 3, 12, 3, 12, 3, 13, 3, 13, 3, 14, 3, 14, 3, 14, 7, 14, 163, 10, 14, 12, 14, 14, 14, 166, 11, 14, 3, 15, 3, 15, 3, 15, 3, 15, 3, 15, 3, 15, 3, 15, 3, 15, 7, 15, 176, 10, 15, 12, 15, 14, 15, 179, 11, 15, 5, 15, 181, 10, 15, 3, 16, 3, 16, 7, 16, 185, 10, 16, 12, 16, 14, 16, 188, 11, 16, 3, 16, 3, 16, 3, 17, 3, 17, 5, 17, 194, 10, 17, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 5, 18, 202, 10, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 5, 18, 213, 10, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 5, 18, 227, 10, 18, 3, 18, 5, 18, 230, 10, 18, 3, 19, 3, 19, 3, 19, 3, 19, 3, 19, 3, 19, 3, 19, 3, 19, 3, 19, 3, 19, 5, 19, 242, 10, 19, 3, 19, 3, 19, 3, 19, 3, 19, 5, 19, 248, 10, 19, 3, 19, 3, 19, 3, 19, 3, 19, 3, 19, 3, 19, 7, 19, 256, 10, 19, 12, 19, 14, 19, 259, 11, 19, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 7, 20, 276, 10, 20, 12, 20, 14, 20, 279, 11, 20, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 7, 21, 286, 10, 21, 12, 21, 14, 21, 289, 11, 21, 3, 22, 3, 22, 3, 23, 3, 23, 3, 24, 3, 24, 3, 24, 7, 24, 298, 10, 24, 12, 24, 14, 24, 301, 11, 24, 3, 25, 3, 25, 3, 26, 3, 26, 3, 26, 2, 4, 36, 38, 27, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 2, 8, 3, 2, 4, 5, 3, 2, 14, 16, 3, 2, 12, 13, 3, 2, 20, 23, 3, 2, 18, 19, 4, 2, 12, 13, 24, 24, 2, 324, 2, 52, 3, 2, 2, 2, 4, 56, 3, 2, 2, 2, 6, 64, 3, 2, 2, 2, 8, 66, 3, 2, 2, 2, 10, 78, 3, 2, 2, 2, 12, 80, 3, 2, 2, 2, 14, 106, 3, 2, 2, 2, 16, 108, 3, 2, 2, 2, 18, 119, 3, 2, 2, 2, 20, 146, 3, 2, 2, 2, 22, 148, 3, 2, 2, 2, 24, 157, 3, 2, 2, 2, 26, 159, 3, 2, 2, 2, 28, 167, 3, 2, 2, 2, 30, 182, 3, 2, 2, 2, 32, 193, 3, 2, 2, 2, 34, 229, 3, 2, 2, 2, 36, 247, 3, 2, 2, 2, 38, 260, 3, 2, 2, 2, 40, 280, 3, 2, 2, 2, 42, 290, 3, 2, 2, 2, 44, 292, 3, 2, 2, 2, 46, 294, 3, 2, 2, 2, 48, 302, 3, 2, 2, 2, 50, 304, 3, 2, 2, 2, 52, 53, 5, 4, 3, 2, 53, 3, 3, 2, 2, 2, 54, 57, 5, 22, 12, 2, 55, 57, 5, 6, 4, 2, 56, 54, 3, 2, 2, 2, 56, 55, 3, 2, 2, 2, 57, 58, 3, 2, 2, 2, 58, 56, 3, 2, 2, 2, 58, 59, 3, 2, 2, 2, 59, 60, 3, 2, 2, 2, 60, 61, 7, 2, 2, 3, 61, 5, 3, 2, 2, 2, 62, 65, 5, 8, 5, 2, 63, 65, 5, 16, 9, 2, 64, 62, 3, 2, 2, 2, 64, 63, 3, 2, 2, 2, 65, 7, 3, 2, 2, 2, 66, 67, 7, 3, 2, 2, 67, 68, 5, 10, 6, 2, 68, 73, 5, 12, 7, 2, 69, 70, 7, 33, 2, 2, 70, 72, 5, 12, 7, 2, 71, 69, 3, 2, 2, 2, 72, 75, 3, 2, 2, 2, 73, 71, 3, 2, 2, 2, 73, 74, 3, 2, 2, 2, 74, 76, 3, 2, 2, 2, 75, 73, 3, 2, 2, 2, 76, 77, 7, 34, 2, 2, 77, 9, 3, 2, 2, 2, 78, 79, 7, 4, 2, 2, 79, 11, 3, 2, 2, 2, 80, 87, 7, 35, 2, 2, 81, 82, 7, 31, 2, 2, 82, 83, 5, 50, 26, 2, 83, 84, 7, 32, 2, 2, 84, 86, 3, 2, 2, 2, 85, 81, 3, 2, 2, 2, 86, 89, 3, 2, 2, 2, 87, 85, 3, 2, 2, 2, 87, 88, 3, 2, 2, 2, 88, 90, 3, 2, 2, 2, 89, 87, 3, 2, 2, 2, 90, 91, 7, 17, 2, 2, 91, 92, 5, 14, 8, 2, 92, 13, 3, 2, 2, 2, 93, 107, 5, 50, 26, 2, 94, 103, 7, 29, 2, 2, 95, 100, 5, 14, 8, 2, 96, 97, 7, 33, 2, 2, 97, 99, 5, 14, 8, 2, 98, 96, 3, 2, 2, 2, 99, 102, 3, 2, 2, 2, 100, 98, 3, 2, 2, 2, 100, 101, 3, 2, 2, 2, 101, 104, 3, 2, 2, 2, 102, 100, 3, 2, 2, 2, 103, 95, 3, 2, 2, 2, 103, 104, 3, 2, 2, 2, 104, 105, 3, 2, 2, 2, 105, 107, 7, 30, 2, 2, 106, 93, 3, 2, 2, 2, 106, 94, 3, 2, 2, 2, 107, 15, 3, 2, 2, 2, 108, 109, 5, 10, 6, 2, 109, 114, 5, 18, 10, 2, 110, 111, 7, 33, 2, 2, 111, 113, 5, 18, 10, 2, 112, 110, 3, 2, 2, 2, 113, 116, 3, 2, 2, 2, 114, 112, 3, 2, 2, 2, 114, 115, 3, 2, 2, 2, 115, 117, 3, 2, 2, 2, 116, 114, 3, 2, 2, 2, 117, 118, 7, 34, 2, 2, 118, 17, 3, 2, 2, 2, 119, 126, 7, 35, 2, 2, 120, 121, 7, 31, 2, 2, 121, 122, 5, 50, 26, 2, 122, 123, 7, 32, 2, 2, 123, 125, 3, 2, 2, 2, 124, 120, 3, 2, 2, 2, 125, 128, 3, 2, 2, 2, 126, 124, 3, 2, 2, 2, 126, 127, 3, 2, 2, 2, 127, 131, 3, 2, 2, 2, 128, 126, 3, 2, 2, 2, 129, 130, 7, 17, 2, 2, 130, 132, 5, 20, 11, 2, 131, 129, 3, 2, 2, 2, 131, 132, 3, 2, 2, 2, 132, 19, 3, 2, 2, 2, 133, 147, 5, 36, 19, 2, 134, 143, 7, 29, 2, 2, 135, 140, 5, 20, 11, 2, 136, 137, 7, 33, 2, 2, 137, 139, 5, 20, 11, 2, 138, 136, 3, 2, 2, 2, 139, 142, 3, 2, 2, 2, 140, 138, 3, 2, 2, 2, 140, 141, 3, 2, 2, 2, 141, 144, 3, 2, 2, 2, 142, 140, 3, 2, 2, 2, 143, 135, 3, 2, 2, 2, 143, 144, 3, 2, 2, 2, 144, 145, 3, 2, 2, 2, 145, 147, 7, 30, 2, 2, 146, 133, 3, 2, 2, 2, 146, 134, 3, 2, 2, 2, 147, 21, 3, 2, 2, 2, 148, 149, 5, 24, 13, 2, 149, 150, 7, 35, 2, 2, 150, 152, 7, 27, 2, 2, 151, 153, 5, 26, 14, 2, 152, 151, 3, 2, 2, 2, 152, 153, 3, 2, 2, 2, 153, 154, 3, 2, 2, 2, 154, 155, 7, 28, 2, 2, 155, 156, 5, 30, 16, 2, 156, 23, 3, 2, 2, 2, 157, 158, 9, 2, 2, 2, 158, 25, 3, 2, 2, 2, 159, 164, 5, 28, 15, 2, 160, 161, 7, 33, 2, 2, 161, 163, 5, 28, 15, 2, 162, 160, 3, 2, 2, 2, 163, 166, 3, 2, 2, 2, 164, 162, 3, 2, 2, 2, 164, 165, 3, 2, 2, 2, 165, 27, 3, 2, 2, 2, 166, 164, 3, 2, 2, 2, 167, 168, 5, 10, 6, 2, 168, 180, 7, 35, 2, 2, 169, 170, 7, 31, 2, 2, 170, 177, 7, 32, 2, 2, 171, 172, 7, 31, 2, 2, 172, 173, 5, 36, 19, 2, 173, 174, 7, 32, 2, 2, 174, 176, 3, 2, 2, 2, 175, 171, 3, 2, 2, 2, 176, 179, 3, 2, 2, 2, 177, 175, 3, 2, 2, 2, 177, 178, 3, 2, 2, 2, 178, 181, 3, 2, 2, 2, 179, 177, 3, 2, 2, 2, 180, 169, 3, 2, 2, 2, 180, 181, 3, 2, 2, 2, 181, 29, 3, 2, 2, 2, 182, 186, 7, 29, 2, 2, 183, 185, 5, 32, 17, 2, 184, 183, 3, 2, 2, 2, 185, 188, 3, 2, 2, 2, 186, 184, 3, 2, 2, 2, 186, 187, 3, 2, 2, 2, 187, 189, 3, 2, 2, 2, 188, 186, 3, 2, 2, 2, 189, 190, 7, 30, 2, 2, 190, 31, 3, 2, 2, 2, 191, 194, 5, 6, 4, 2, 192, 194, 5, 34, 18, 2, 193, 191, 3, 2, 2, 2, 193, 192, 3, 2, 2, 2, 194, 33, 3, 2, 2, 2, 195, 196, 5, 40, 21, 2, 196, 197, 7, 17, 2, 2, 197, 198, 5, 36, 19, 2, 198, 199, 7, 34, 2, 2, 199, 230, 3, 2, 2, 2, 200, 202, 5, 36, 19, 2, 201, 200, 3, 2, 2, 2, 201, 202, 3, 2, 2, 2, 202, 203, 3, 2, 2, 2, 203, 230, 7, 34, 2, 2, 204, 230, 5, 30, 16, 2, 205, 206, 7, 6, 2, 2, 206, 207, 7, 27, 2, 2, 207, 208, 5, 38, 20, 2, 208, 209, 7, 28, 2, 2, 209, 212, 5, 34, 18, 2, 210, 211, 7, 7, 2, 2, 211, 213, 5, 34, 18, 2, 212, 210, 3, 2, 2, 2, 212, 213, 3, 2, 2, 2, 213, 230, 3, 2, 2, 2, 214, 215, 7, 8, 2, 2, 215, 216, 7, 27, 2, 2, 216, 217, 5, 38, 20, 2, 217, 218, 7, 28, 2, 2, 218, 219, 5, 34, 18, 2, 219, 230, 3, 2, 2, 2, 220, 221, 7, 9, 2, 2, 221, 230, 7, 34, 2, 2, 222, 223, 7, 10, 2, 2, 223, 230, 7, 34, 2, 2, 224, 226, 7, 11, 2, 2, 225, 227, 5, 36, 19, 2, 226, 225, 3, 2, 2, 2, 226, 227, 3, 2, 2, 2, 227, 228, 3, 2, 2, 2, 228, 230, 7, 34, 2, 2, 229, 195, 3, 2, 2, 2, 229, 201, 3, 2, 2, 2, 229, 204, 3, 2, 2, 2, 229, 205, 3, 2, 2, 2, 229, 214, 3, 2, 2, 2, 229, 220, 3, 2, 2, 2, 229, 222, 3, 2, 2, 2, 229, 224, 3, 2, 2, 2, 230, 35, 3, 2, 2, 2, 231, 232, 8, 19, 1, 2, 232, 233, 7, 27, 2, 2, 233, 234, 5, 36, 19, 2, 234, 235, 7, 28, 2, 2, 235, 248, 3, 2, 2, 2, 236, 248, 5, 40, 21, 2, 237, 248, 5, 42, 22, 2, 238, 239, 7, 35, 2, 2, 239, 241, 7, 27, 2, 2, 240, 242, 5, 46, 24, 2, 241, 240, 3, 2, 2, 2, 241, 242, 3, 2, 2, 2, 242, 243, 3, 2, 2, 2, 243, 248, 7, 28, 2, 2, 244, 245, 5, 44, 23, 2, 245, 246, 5, 36, 19, 5, 246, 248, 3, 2, 2, 2, 247, 231, 3, 2, 2, 2, 247, 236, 3, 2, 2, 2, 247, 237, 3, 2, 2, 2, 247, 238, 3, 2, 2, 2, 247, 244, 3, 2, 2, 2, 248, 257, 3, 2, 2, 2, 249, 250, 12, 4, 2, 2, 250, 251, 9, 3, 2, 2, 251, 256, 5, 36, 19, 5, 252, 253, 12, 3, 2, 2, 253, 254, 9, 4, 2, 2, 254, 256, 5, 36, 19, 4, 255, 249, 3, 2, 2, 2, 255, 252, 3, 2, 2, 2, 256, 259, 3, 2, 2, 2, 257, 255, 3, 2, 2, 2, 257, 258, 3, 2, 2, 2, 258, 37, 3, 2, 2, 2, 259, 257, 3, 2, 2, 2, 260, 261, 8, 20, 1, 2, 261, 262, 5, 36, 19, 2, 262, 277, 3, 2, 2, 2, 263, 264, 12, 6, 2, 2, 264, 265, 9, 5, 2, 2, 265, 276, 5, 38, 20, 7, 266, 267, 12, 5, 2, 2, 267, 268, 9, 6, 2, 2, 268, 276, 5, 38, 20, 6, 269, 270, 12, 4, 2, 2, 270, 271, 7, 25, 2, 2, 271, 276, 5, 38, 20, 5, 272, 273, 12, 3, 2, 2, 273, 274, 7, 26, 2, 2, 274, 276, 5, 38, 20, 4, 275, 263, 3, 2, 2, 2, 275, 266, 3, 2, 2, 2, 275, 269, 3, 2, 2, 2, 275, 272, 3, 2, 2, 2, 276, 279, 3, 2, 2, 2, 277, 275, 3, 2, 2, 2, 277, 278, 3, 2, 2, 2, 278, 39, 3, 2, 2, 2, 279, 277, 3, 2, 2, 2, 280, 287, 7, 35, 2, 2, 281, 282, 7, 31, 2, 2, 282, 283, 5, 36, 19, 2, 283, 284, 7, 32, 2, 2, 284, 286, 3, 2, 2, 2, 285, 281, 3, 2, 2, 2, 286, 289, 3, 2, 2, 2, 287, 285, 3, 2, 2, 2, 287, 288, 3, 2, 2, 2, 288, 41, 3, 2, 2, 2, 289, 287, 3, 2, 2, 2, 290, 291, 7, 36, 2, 2, 291, 43, 3, 2, 2, 2, 292, 293, 9, 7, 2, 2, 293, 45, 3, 2, 2, 2, 294, 299, 5, 48, 25, 2, 295, 296, 7, 33, 2, 2, 296, 298, 5, 48, 25, 2, 297, 295, 3, 2, 2, 2, 298, 301, 3, 2, 2, 2, 299, 297, 3, 2, 2, 2, 299, 300, 3, 2, 2, 2, 300, 47, 3, 2, 2, 2, 301, 299, 3, 2, 2, 2, 302, 303, 5, 36, 19, 2, 303, 49, 3, 2, 2, 2, 304, 305, 5, 36, 19, 2, 305, 51, 3, 2, 2, 2, 34, 56, 58, 64, 73, 87, 100, 103, 106, 114, 126, 131, 140, 143, 146, 152, 164, 177, 180, 186, 193, 201, 212, 226, 229, 241, 247, 255, 257, 275, 277, 287, 299]
--------------------------------------------------------------------------------
/src/SysYParser.tokens:
--------------------------------------------------------------------------------
1 | CONST=1
2 | INT=2
3 | VOID=3
4 | IF=4
5 | ELSE=5
6 | WHILE=6
7 | BREAK=7
8 | CONTINUE=8
9 | RETURN=9
10 | PLUS=10
11 | MINUS=11
12 | MUL=12
13 | DIV=13
14 | MOD=14
15 | ASSIGN=15
16 | EQ=16
17 | NEQ=17
18 | LT=18
19 | GT=19
20 | LE=20
21 | GE=21
22 | NOT=22
23 | AND=23
24 | OR=24
25 | L_PAREN=25
26 | R_PAREN=26
27 | L_BRACE=27
28 | R_BRACE=28
29 | L_BRACKT=29
30 | R_BRACKT=30
31 | COMMA=31
32 | SEMICOLON=32
33 | IDENT=33
34 | INTEGR_CONST=34
35 | WS=35
36 | SL_COMMENT=36
37 | ML_COMMENT=37
38 | 'const'=1
39 | 'int'=2
40 | 'void'=3
41 | 'if'=4
42 | 'else'=5
43 | 'while'=6
44 | 'break'=7
45 | 'continue'=8
46 | 'return'=9
47 | '+'=10
48 | '-'=11
49 | '*'=12
50 | '/'=13
51 | '%'=14
52 | '='=15
53 | '=='=16
54 | '!='=17
55 | '<'=18
56 | '>'=19
57 | '<='=20
58 | '>='=21
59 | '!'=22
60 | '&&'=23
61 | '||'=24
62 | '('=25
63 | ')'=26
64 | '{'=27
65 | '}'=28
66 | '['=29
67 | ']'=30
68 | ','=31
69 | ';'=32
70 |
--------------------------------------------------------------------------------
/src/SysYParserBaseListener.java:
--------------------------------------------------------------------------------
1 | // Generated from ./src/SysYParser.g4 by ANTLR 4.9.1
2 |
3 | import org.antlr.v4.runtime.ParserRuleContext;
4 | import org.antlr.v4.runtime.tree.ErrorNode;
5 | import org.antlr.v4.runtime.tree.TerminalNode;
6 |
7 | /**
8 | * This class provides an empty implementation of {@link SysYParserListener},
9 | * which can be extended to create a listener which only needs to handle a subset
10 | * of the available methods.
11 | */
12 | public class SysYParserBaseListener implements SysYParserListener {
13 | /**
14 | * {@inheritDoc}
15 | *
16 | * The default implementation does nothing.
17 | */
18 | @Override public void enterProgram(SysYParser.ProgramContext ctx) { }
19 | /**
20 | * {@inheritDoc}
21 | *
22 | * The default implementation does nothing.
23 | */
24 | @Override public void exitProgram(SysYParser.ProgramContext ctx) { }
25 | /**
26 | * {@inheritDoc}
27 | *
28 | * The default implementation does nothing.
29 | */
30 | @Override public void enterCompUnit(SysYParser.CompUnitContext ctx) { }
31 | /**
32 | * {@inheritDoc}
33 | *
34 | * The default implementation does nothing.
35 | */
36 | @Override public void exitCompUnit(SysYParser.CompUnitContext ctx) { }
37 | /**
38 | * {@inheritDoc}
39 | *
40 | * The default implementation does nothing.
41 | */
42 | @Override public void enterDecl(SysYParser.DeclContext ctx) { }
43 | /**
44 | * {@inheritDoc}
45 | *
46 | * The default implementation does nothing.
47 | */
48 | @Override public void exitDecl(SysYParser.DeclContext ctx) { }
49 | /**
50 | * {@inheritDoc}
51 | *
52 | * The default implementation does nothing.
53 | */
54 | @Override public void enterConstDecl(SysYParser.ConstDeclContext ctx) { }
55 | /**
56 | * {@inheritDoc}
57 | *
58 | * The default implementation does nothing.
59 | */
60 | @Override public void exitConstDecl(SysYParser.ConstDeclContext ctx) { }
61 | /**
62 | * {@inheritDoc}
63 | *
64 | * The default implementation does nothing.
65 | */
66 | @Override public void enterBType(SysYParser.BTypeContext ctx) { }
67 | /**
68 | * {@inheritDoc}
69 | *
70 | * The default implementation does nothing.
71 | */
72 | @Override public void exitBType(SysYParser.BTypeContext ctx) { }
73 | /**
74 | * {@inheritDoc}
75 | *
76 | * The default implementation does nothing.
77 | */
78 | @Override public void enterConstDef(SysYParser.ConstDefContext ctx) { }
79 | /**
80 | * {@inheritDoc}
81 | *
82 | * The default implementation does nothing.
83 | */
84 | @Override public void exitConstDef(SysYParser.ConstDefContext ctx) { }
85 | /**
86 | * {@inheritDoc}
87 | *
88 | * The default implementation does nothing.
89 | */
90 | @Override public void enterConstInitVal(SysYParser.ConstInitValContext ctx) { }
91 | /**
92 | * {@inheritDoc}
93 | *
94 | * The default implementation does nothing.
95 | */
96 | @Override public void exitConstInitVal(SysYParser.ConstInitValContext ctx) { }
97 | /**
98 | * {@inheritDoc}
99 | *
100 | * The default implementation does nothing.
101 | */
102 | @Override public void enterVarDecl(SysYParser.VarDeclContext ctx) { }
103 | /**
104 | * {@inheritDoc}
105 | *
106 | * The default implementation does nothing.
107 | */
108 | @Override public void exitVarDecl(SysYParser.VarDeclContext ctx) { }
109 | /**
110 | * {@inheritDoc}
111 | *
112 | * The default implementation does nothing.
113 | */
114 | @Override public void enterVarDef(SysYParser.VarDefContext ctx) { }
115 | /**
116 | * {@inheritDoc}
117 | *
118 | * The default implementation does nothing.
119 | */
120 | @Override public void exitVarDef(SysYParser.VarDefContext ctx) { }
121 | /**
122 | * {@inheritDoc}
123 | *
124 | * The default implementation does nothing.
125 | */
126 | @Override public void enterInitVal(SysYParser.InitValContext ctx) { }
127 | /**
128 | * {@inheritDoc}
129 | *
130 | * The default implementation does nothing.
131 | */
132 | @Override public void exitInitVal(SysYParser.InitValContext ctx) { }
133 | /**
134 | * {@inheritDoc}
135 | *
136 | * The default implementation does nothing.
137 | */
138 | @Override public void enterFuncDef(SysYParser.FuncDefContext ctx) { }
139 | /**
140 | * {@inheritDoc}
141 | *
142 | * The default implementation does nothing.
143 | */
144 | @Override public void exitFuncDef(SysYParser.FuncDefContext ctx) { }
145 | /**
146 | * {@inheritDoc}
147 | *
148 | * The default implementation does nothing.
149 | */
150 | @Override public void enterFuncType(SysYParser.FuncTypeContext ctx) { }
151 | /**
152 | * {@inheritDoc}
153 | *
154 | * The default implementation does nothing.
155 | */
156 | @Override public void exitFuncType(SysYParser.FuncTypeContext ctx) { }
157 | /**
158 | * {@inheritDoc}
159 | *
160 | * The default implementation does nothing.
161 | */
162 | @Override public void enterFuncFParams(SysYParser.FuncFParamsContext ctx) { }
163 | /**
164 | * {@inheritDoc}
165 | *
166 | * The default implementation does nothing.
167 | */
168 | @Override public void exitFuncFParams(SysYParser.FuncFParamsContext ctx) { }
169 | /**
170 | * {@inheritDoc}
171 | *
172 | * The default implementation does nothing.
173 | */
174 | @Override public void enterFuncFParam(SysYParser.FuncFParamContext ctx) { }
175 | /**
176 | * {@inheritDoc}
177 | *
178 | * The default implementation does nothing.
179 | */
180 | @Override public void exitFuncFParam(SysYParser.FuncFParamContext ctx) { }
181 | /**
182 | * {@inheritDoc}
183 | *
184 | * The default implementation does nothing.
185 | */
186 | @Override public void enterBlock(SysYParser.BlockContext ctx) { }
187 | /**
188 | * {@inheritDoc}
189 | *
190 | * The default implementation does nothing.
191 | */
192 | @Override public void exitBlock(SysYParser.BlockContext ctx) { }
193 | /**
194 | * {@inheritDoc}
195 | *
196 | * The default implementation does nothing.
197 | */
198 | @Override public void enterBlockItem(SysYParser.BlockItemContext ctx) { }
199 | /**
200 | * {@inheritDoc}
201 | *
202 | * The default implementation does nothing.
203 | */
204 | @Override public void exitBlockItem(SysYParser.BlockItemContext ctx) { }
205 | /**
206 | * {@inheritDoc}
207 | *
208 | * The default implementation does nothing.
209 | */
210 | @Override public void enterAssignment(SysYParser.AssignmentContext ctx) { }
211 | /**
212 | * {@inheritDoc}
213 | *
214 | * The default implementation does nothing.
215 | */
216 | @Override public void exitAssignment(SysYParser.AssignmentContext ctx) { }
217 | /**
218 | * {@inheritDoc}
219 | *
220 | * The default implementation does nothing.
221 | */
222 | @Override public void enterPossibleExp(SysYParser.PossibleExpContext ctx) { }
223 | /**
224 | * {@inheritDoc}
225 | *
226 | * The default implementation does nothing.
227 | */
228 | @Override public void exitPossibleExp(SysYParser.PossibleExpContext ctx) { }
229 | /**
230 | * {@inheritDoc}
231 | *
232 | * The default implementation does nothing.
233 | */
234 | @Override public void enterBlockStmt(SysYParser.BlockStmtContext ctx) { }
235 | /**
236 | * {@inheritDoc}
237 | *
238 | * The default implementation does nothing.
239 | */
240 | @Override public void exitBlockStmt(SysYParser.BlockStmtContext ctx) { }
241 | /**
242 | * {@inheritDoc}
243 | *
244 | * The default implementation does nothing.
245 | */
246 | @Override public void enterIfStmt(SysYParser.IfStmtContext ctx) { }
247 | /**
248 | * {@inheritDoc}
249 | *
250 | * The default implementation does nothing.
251 | */
252 | @Override public void exitIfStmt(SysYParser.IfStmtContext ctx) { }
253 | /**
254 | * {@inheritDoc}
255 | *
256 | * The default implementation does nothing.
257 | */
258 | @Override public void enterWhileStmt(SysYParser.WhileStmtContext ctx) { }
259 | /**
260 | * {@inheritDoc}
261 | *
262 | * The default implementation does nothing.
263 | */
264 | @Override public void exitWhileStmt(SysYParser.WhileStmtContext ctx) { }
265 | /**
266 | * {@inheritDoc}
267 | *
268 | * The default implementation does nothing.
269 | */
270 | @Override public void enterBreakStmt(SysYParser.BreakStmtContext ctx) { }
271 | /**
272 | * {@inheritDoc}
273 | *
274 | * The default implementation does nothing.
275 | */
276 | @Override public void exitBreakStmt(SysYParser.BreakStmtContext ctx) { }
277 | /**
278 | * {@inheritDoc}
279 | *
280 | * The default implementation does nothing.
281 | */
282 | @Override public void enterContinueStmt(SysYParser.ContinueStmtContext ctx) { }
283 | /**
284 | * {@inheritDoc}
285 | *
286 | * The default implementation does nothing.
287 | */
288 | @Override public void exitContinueStmt(SysYParser.ContinueStmtContext ctx) { }
289 | /**
290 | * {@inheritDoc}
291 | *
292 | * The default implementation does nothing.
293 | */
294 | @Override public void enterReturnStmt(SysYParser.ReturnStmtContext ctx) { }
295 | /**
296 | * {@inheritDoc}
297 | *
298 | * The default implementation does nothing.
299 | */
300 | @Override public void exitReturnStmt(SysYParser.ReturnStmtContext ctx) { }
301 | /**
302 | * {@inheritDoc}
303 | *
304 | * The default implementation does nothing.
305 | */
306 | @Override public void enterLValExp(SysYParser.LValExpContext ctx) { }
307 | /**
308 | * {@inheritDoc}
309 | *
310 | * The default implementation does nothing.
311 | */
312 | @Override public void exitLValExp(SysYParser.LValExpContext ctx) { }
313 | /**
314 | * {@inheritDoc}
315 | *
316 | * The default implementation does nothing.
317 | */
318 | @Override public void enterUnaryExp(SysYParser.UnaryExpContext ctx) { }
319 | /**
320 | * {@inheritDoc}
321 | *
322 | * The default implementation does nothing.
323 | */
324 | @Override public void exitUnaryExp(SysYParser.UnaryExpContext ctx) { }
325 | /**
326 | * {@inheritDoc}
327 | *
328 | * The default implementation does nothing.
329 | */
330 | @Override public void enterParenExp(SysYParser.ParenExpContext ctx) { }
331 | /**
332 | * {@inheritDoc}
333 | *
334 | * The default implementation does nothing.
335 | */
336 | @Override public void exitParenExp(SysYParser.ParenExpContext ctx) { }
337 | /**
338 | * {@inheritDoc}
339 | *
340 | * The default implementation does nothing.
341 | */
342 | @Override public void enterAddExp(SysYParser.AddExpContext ctx) { }
343 | /**
344 | * {@inheritDoc}
345 | *
346 | * The default implementation does nothing.
347 | */
348 | @Override public void exitAddExp(SysYParser.AddExpContext ctx) { }
349 | /**
350 | * {@inheritDoc}
351 | *
352 | * The default implementation does nothing.
353 | */
354 | @Override public void enterMulExp(SysYParser.MulExpContext ctx) { }
355 | /**
356 | * {@inheritDoc}
357 | *
358 | * The default implementation does nothing.
359 | */
360 | @Override public void exitMulExp(SysYParser.MulExpContext ctx) { }
361 | /**
362 | * {@inheritDoc}
363 | *
364 | * The default implementation does nothing.
365 | */
366 | @Override public void enterFuncCallExp(SysYParser.FuncCallExpContext ctx) { }
367 | /**
368 | * {@inheritDoc}
369 | *
370 | * The default implementation does nothing.
371 | */
372 | @Override public void exitFuncCallExp(SysYParser.FuncCallExpContext ctx) { }
373 | /**
374 | * {@inheritDoc}
375 | *
376 | * The default implementation does nothing.
377 | */
378 | @Override public void enterNumExp(SysYParser.NumExpContext ctx) { }
379 | /**
380 | * {@inheritDoc}
381 | *
382 | * The default implementation does nothing.
383 | */
384 | @Override public void exitNumExp(SysYParser.NumExpContext ctx) { }
385 | /**
386 | * {@inheritDoc}
387 | *
388 | * The default implementation does nothing.
389 | */
390 | @Override public void enterCompareExp(SysYParser.CompareExpContext ctx) { }
391 | /**
392 | * {@inheritDoc}
393 | *
394 | * The default implementation does nothing.
395 | */
396 | @Override public void exitCompareExp(SysYParser.CompareExpContext ctx) { }
397 | /**
398 | * {@inheritDoc}
399 | *
400 | * The default implementation does nothing.
401 | */
402 | @Override public void enterRelationExp(SysYParser.RelationExpContext ctx) { }
403 | /**
404 | * {@inheritDoc}
405 | *
406 | * The default implementation does nothing.
407 | */
408 | @Override public void exitRelationExp(SysYParser.RelationExpContext ctx) { }
409 | /**
410 | * {@inheritDoc}
411 | *
412 | * The default implementation does nothing.
413 | */
414 | @Override public void enterCondExp(SysYParser.CondExpContext ctx) { }
415 | /**
416 | * {@inheritDoc}
417 | *
418 | * The default implementation does nothing.
419 | */
420 | @Override public void exitCondExp(SysYParser.CondExpContext ctx) { }
421 | /**
422 | * {@inheritDoc}
423 | *
424 | * The default implementation does nothing.
425 | */
426 | @Override public void enterAndExp(SysYParser.AndExpContext ctx) { }
427 | /**
428 | * {@inheritDoc}
429 | *
430 | * The default implementation does nothing.
431 | */
432 | @Override public void exitAndExp(SysYParser.AndExpContext ctx) { }
433 | /**
434 | * {@inheritDoc}
435 | *
436 | * The default implementation does nothing.
437 | */
438 | @Override public void enterOrExp(SysYParser.OrExpContext ctx) { }
439 | /**
440 | * {@inheritDoc}
441 | *
442 | * The default implementation does nothing.
443 | */
444 | @Override public void exitOrExp(SysYParser.OrExpContext ctx) { }
445 | /**
446 | * {@inheritDoc}
447 | *
448 | * The default implementation does nothing.
449 | */
450 | @Override public void enterLVal(SysYParser.LValContext ctx) { }
451 | /**
452 | * {@inheritDoc}
453 | *
454 | * The default implementation does nothing.
455 | */
456 | @Override public void exitLVal(SysYParser.LValContext ctx) { }
457 | /**
458 | * {@inheritDoc}
459 | *
460 | * The default implementation does nothing.
461 | */
462 | @Override public void enterNumber(SysYParser.NumberContext ctx) { }
463 | /**
464 | * {@inheritDoc}
465 | *
466 | * The default implementation does nothing.
467 | */
468 | @Override public void exitNumber(SysYParser.NumberContext ctx) { }
469 | /**
470 | * {@inheritDoc}
471 | *
472 | * The default implementation does nothing.
473 | */
474 | @Override public void enterUnaryOp(SysYParser.UnaryOpContext ctx) { }
475 | /**
476 | * {@inheritDoc}
477 | *
478 | * The default implementation does nothing.
479 | */
480 | @Override public void exitUnaryOp(SysYParser.UnaryOpContext ctx) { }
481 | /**
482 | * {@inheritDoc}
483 | *
484 | * The default implementation does nothing.
485 | */
486 | @Override public void enterFuncRParams(SysYParser.FuncRParamsContext ctx) { }
487 | /**
488 | * {@inheritDoc}
489 | *
490 | * The default implementation does nothing.
491 | */
492 | @Override public void exitFuncRParams(SysYParser.FuncRParamsContext ctx) { }
493 | /**
494 | * {@inheritDoc}
495 | *
496 | * The default implementation does nothing.
497 | */
498 | @Override public void enterParam(SysYParser.ParamContext ctx) { }
499 | /**
500 | * {@inheritDoc}
501 | *
502 | * The default implementation does nothing.
503 | */
504 | @Override public void exitParam(SysYParser.ParamContext ctx) { }
505 | /**
506 | * {@inheritDoc}
507 | *
508 | * The default implementation does nothing.
509 | */
510 | @Override public void enterConstExp(SysYParser.ConstExpContext ctx) { }
511 | /**
512 | * {@inheritDoc}
513 | *
514 | * The default implementation does nothing.
515 | */
516 | @Override public void exitConstExp(SysYParser.ConstExpContext ctx) { }
517 |
518 | /**
519 | * {@inheritDoc}
520 | *
521 | * The default implementation does nothing.
522 | */
523 | @Override public void enterEveryRule(ParserRuleContext ctx) { }
524 | /**
525 | * {@inheritDoc}
526 | *
527 | * The default implementation does nothing.
528 | */
529 | @Override public void exitEveryRule(ParserRuleContext ctx) { }
530 | /**
531 | * {@inheritDoc}
532 | *
533 | * The default implementation does nothing.
534 | */
535 | @Override public void visitTerminal(TerminalNode node) { }
536 | /**
537 | * {@inheritDoc}
538 | *
539 | * The default implementation does nothing.
540 | */
541 | @Override public void visitErrorNode(ErrorNode node) { }
542 | }
--------------------------------------------------------------------------------
/src/SysYParserBaseVisitor.java:
--------------------------------------------------------------------------------
1 | // Generated from ./src/SysYParser.g4 by ANTLR 4.9.1
2 | import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
3 |
4 | /**
5 | * This class provides an empty implementation of {@link SysYParserVisitor},
6 | * which can be extended to create a visitor which only needs to handle a subset
7 | * of the available methods.
8 | *
9 | * @param The return type of the visit operation. Use {@link Void} for
10 | * operations with no return type.
11 | */
12 | public class SysYParserBaseVisitor extends AbstractParseTreeVisitor implements SysYParserVisitor {
13 | /**
14 | * {@inheritDoc}
15 | *
16 | * The default implementation returns the result of calling
17 | * {@link #visitChildren} on {@code ctx}.
18 | */
19 | @Override public T visitProgram(SysYParser.ProgramContext ctx) { return visitChildren(ctx); }
20 | /**
21 | * {@inheritDoc}
22 | *
23 | * The default implementation returns the result of calling
24 | * {@link #visitChildren} on {@code ctx}.
25 | */
26 | @Override public T visitCompUnit(SysYParser.CompUnitContext ctx) { return visitChildren(ctx); }
27 | /**
28 | * {@inheritDoc}
29 | *
30 | * The default implementation returns the result of calling
31 | * {@link #visitChildren} on {@code ctx}.
32 | */
33 | @Override public T visitDecl(SysYParser.DeclContext ctx) { return visitChildren(ctx); }
34 | /**
35 | * {@inheritDoc}
36 | *
37 | * The default implementation returns the result of calling
38 | * {@link #visitChildren} on {@code ctx}.
39 | */
40 | @Override public T visitConstDecl(SysYParser.ConstDeclContext ctx) { return visitChildren(ctx); }
41 | /**
42 | * {@inheritDoc}
43 | *
44 | * The default implementation returns the result of calling
45 | * {@link #visitChildren} on {@code ctx}.
46 | */
47 | @Override public T visitBType(SysYParser.BTypeContext ctx) { return visitChildren(ctx); }
48 | /**
49 | * {@inheritDoc}
50 | *
51 | * The default implementation returns the result of calling
52 | * {@link #visitChildren} on {@code ctx}.
53 | */
54 | @Override public T visitConstDef(SysYParser.ConstDefContext ctx) { return visitChildren(ctx); }
55 | /**
56 | * {@inheritDoc}
57 | *
58 | * The default implementation returns the result of calling
59 | * {@link #visitChildren} on {@code ctx}.
60 | */
61 | @Override public T visitConstInitVal(SysYParser.ConstInitValContext ctx) { return visitChildren(ctx); }
62 | /**
63 | * {@inheritDoc}
64 | *
65 | * The default implementation returns the result of calling
66 | * {@link #visitChildren} on {@code ctx}.
67 | */
68 | @Override public T visitVarDecl(SysYParser.VarDeclContext ctx) { return visitChildren(ctx); }
69 | /**
70 | * {@inheritDoc}
71 | *
72 | * The default implementation returns the result of calling
73 | * {@link #visitChildren} on {@code ctx}.
74 | */
75 | @Override public T visitVarDef(SysYParser.VarDefContext ctx) { return visitChildren(ctx); }
76 | /**
77 | * {@inheritDoc}
78 | *
79 | * The default implementation returns the result of calling
80 | * {@link #visitChildren} on {@code ctx}.
81 | */
82 | @Override public T visitInitVal(SysYParser.InitValContext ctx) { return visitChildren(ctx); }
83 | /**
84 | * {@inheritDoc}
85 | *
86 | * The default implementation returns the result of calling
87 | * {@link #visitChildren} on {@code ctx}.
88 | */
89 | @Override public T visitFuncDef(SysYParser.FuncDefContext ctx) { return visitChildren(ctx); }
90 | /**
91 | * {@inheritDoc}
92 | *
93 | * The default implementation returns the result of calling
94 | * {@link #visitChildren} on {@code ctx}.
95 | */
96 | @Override public T visitFuncType(SysYParser.FuncTypeContext ctx) { return visitChildren(ctx); }
97 | /**
98 | * {@inheritDoc}
99 | *
100 | * The default implementation returns the result of calling
101 | * {@link #visitChildren} on {@code ctx}.
102 | */
103 | @Override public T visitFuncFParams(SysYParser.FuncFParamsContext ctx) { return visitChildren(ctx); }
104 | /**
105 | * {@inheritDoc}
106 | *
107 | * The default implementation returns the result of calling
108 | * {@link #visitChildren} on {@code ctx}.
109 | */
110 | @Override public T visitFuncFParam(SysYParser.FuncFParamContext ctx) { return visitChildren(ctx); }
111 | /**
112 | * {@inheritDoc}
113 | *
114 | * The default implementation returns the result of calling
115 | * {@link #visitChildren} on {@code ctx}.
116 | */
117 | @Override public T visitBlock(SysYParser.BlockContext ctx) { return visitChildren(ctx); }
118 | /**
119 | * {@inheritDoc}
120 | *
121 | * The default implementation returns the result of calling
122 | * {@link #visitChildren} on {@code ctx}.
123 | */
124 | @Override public T visitBlockItem(SysYParser.BlockItemContext ctx) { return visitChildren(ctx); }
125 | /**
126 | * {@inheritDoc}
127 | *
128 | * The default implementation returns the result of calling
129 | * {@link #visitChildren} on {@code ctx}.
130 | */
131 | @Override public T visitAssignment(SysYParser.AssignmentContext ctx) { return visitChildren(ctx); }
132 | /**
133 | * {@inheritDoc}
134 | *
135 | * The default implementation returns the result of calling
136 | * {@link #visitChildren} on {@code ctx}.
137 | */
138 | @Override public T visitPossibleExp(SysYParser.PossibleExpContext ctx) { return visitChildren(ctx); }
139 | /**
140 | * {@inheritDoc}
141 | *
142 | * The default implementation returns the result of calling
143 | * {@link #visitChildren} on {@code ctx}.
144 | */
145 | @Override public T visitBlockStmt(SysYParser.BlockStmtContext ctx) { return visitChildren(ctx); }
146 | /**
147 | * {@inheritDoc}
148 | *
149 | * The default implementation returns the result of calling
150 | * {@link #visitChildren} on {@code ctx}.
151 | */
152 | @Override public T visitIfStmt(SysYParser.IfStmtContext ctx) { return visitChildren(ctx); }
153 | /**
154 | * {@inheritDoc}
155 | *
156 | * The default implementation returns the result of calling
157 | * {@link #visitChildren} on {@code ctx}.
158 | */
159 | @Override public T visitWhileStmt(SysYParser.WhileStmtContext ctx) { return visitChildren(ctx); }
160 | /**
161 | * {@inheritDoc}
162 | *
163 | * The default implementation returns the result of calling
164 | * {@link #visitChildren} on {@code ctx}.
165 | */
166 | @Override public T visitBreakStmt(SysYParser.BreakStmtContext ctx) { return visitChildren(ctx); }
167 | /**
168 | * {@inheritDoc}
169 | *
170 | * The default implementation returns the result of calling
171 | * {@link #visitChildren} on {@code ctx}.
172 | */
173 | @Override public T visitContinueStmt(SysYParser.ContinueStmtContext ctx) { return visitChildren(ctx); }
174 | /**
175 | * {@inheritDoc}
176 | *
177 | * The default implementation returns the result of calling
178 | * {@link #visitChildren} on {@code ctx}.
179 | */
180 | @Override public T visitReturnStmt(SysYParser.ReturnStmtContext ctx) { return visitChildren(ctx); }
181 | /**
182 | * {@inheritDoc}
183 | *
184 | * The default implementation returns the result of calling
185 | * {@link #visitChildren} on {@code ctx}.
186 | */
187 | @Override public T visitLValExp(SysYParser.LValExpContext ctx) { return visitChildren(ctx); }
188 | /**
189 | * {@inheritDoc}
190 | *
191 | * The default implementation returns the result of calling
192 | * {@link #visitChildren} on {@code ctx}.
193 | */
194 | @Override public T visitUnaryExp(SysYParser.UnaryExpContext ctx) { return visitChildren(ctx); }
195 | /**
196 | * {@inheritDoc}
197 | *
198 | * The default implementation returns the result of calling
199 | * {@link #visitChildren} on {@code ctx}.
200 | */
201 | @Override public T visitParenExp(SysYParser.ParenExpContext ctx) { return visitChildren(ctx); }
202 | /**
203 | * {@inheritDoc}
204 | *
205 | * The default implementation returns the result of calling
206 | * {@link #visitChildren} on {@code ctx}.
207 | */
208 | @Override public T visitAddExp(SysYParser.AddExpContext ctx) { return visitChildren(ctx); }
209 | /**
210 | * {@inheritDoc}
211 | *
212 | * The default implementation returns the result of calling
213 | * {@link #visitChildren} on {@code ctx}.
214 | */
215 | @Override public T visitMulExp(SysYParser.MulExpContext ctx) { return visitChildren(ctx); }
216 | /**
217 | * {@inheritDoc}
218 | *
219 | * The default implementation returns the result of calling
220 | * {@link #visitChildren} on {@code ctx}.
221 | */
222 | @Override public T visitFuncCallExp(SysYParser.FuncCallExpContext ctx) { return visitChildren(ctx); }
223 | /**
224 | * {@inheritDoc}
225 | *
226 | * The default implementation returns the result of calling
227 | * {@link #visitChildren} on {@code ctx}.
228 | */
229 | @Override public T visitNumExp(SysYParser.NumExpContext ctx) { return visitChildren(ctx); }
230 | /**
231 | * {@inheritDoc}
232 | *
233 | * The default implementation returns the result of calling
234 | * {@link #visitChildren} on {@code ctx}.
235 | */
236 | @Override public T visitCompareExp(SysYParser.CompareExpContext ctx) { return visitChildren(ctx); }
237 | /**
238 | * {@inheritDoc}
239 | *
240 | * The default implementation returns the result of calling
241 | * {@link #visitChildren} on {@code ctx}.
242 | */
243 | @Override public T visitRelationExp(SysYParser.RelationExpContext ctx) { return visitChildren(ctx); }
244 | /**
245 | * {@inheritDoc}
246 | *
247 | * The default implementation returns the result of calling
248 | * {@link #visitChildren} on {@code ctx}.
249 | */
250 | @Override public T visitCondExp(SysYParser.CondExpContext ctx) { return visitChildren(ctx); }
251 | /**
252 | * {@inheritDoc}
253 | *
254 | * The default implementation returns the result of calling
255 | * {@link #visitChildren} on {@code ctx}.
256 | */
257 | @Override public T visitAndExp(SysYParser.AndExpContext ctx) { return visitChildren(ctx); }
258 | /**
259 | * {@inheritDoc}
260 | *
261 | * The default implementation returns the result of calling
262 | * {@link #visitChildren} on {@code ctx}.
263 | */
264 | @Override public T visitOrExp(SysYParser.OrExpContext ctx) { return visitChildren(ctx); }
265 | /**
266 | * {@inheritDoc}
267 | *
268 | * The default implementation returns the result of calling
269 | * {@link #visitChildren} on {@code ctx}.
270 | */
271 | @Override public T visitLVal(SysYParser.LValContext ctx) { return visitChildren(ctx); }
272 | /**
273 | * {@inheritDoc}
274 | *
275 | * The default implementation returns the result of calling
276 | * {@link #visitChildren} on {@code ctx}.
277 | */
278 | @Override public T visitNumber(SysYParser.NumberContext ctx) { return visitChildren(ctx); }
279 | /**
280 | * {@inheritDoc}
281 | *
282 | * The default implementation returns the result of calling
283 | * {@link #visitChildren} on {@code ctx}.
284 | */
285 | @Override public T visitUnaryOp(SysYParser.UnaryOpContext ctx) { return visitChildren(ctx); }
286 | /**
287 | * {@inheritDoc}
288 | *
289 | * The default implementation returns the result of calling
290 | * {@link #visitChildren} on {@code ctx}.
291 | */
292 | @Override public T visitFuncRParams(SysYParser.FuncRParamsContext ctx) { return visitChildren(ctx); }
293 | /**
294 | * {@inheritDoc}
295 | *
296 | * The default implementation returns the result of calling
297 | * {@link #visitChildren} on {@code ctx}.
298 | */
299 | @Override public T visitParam(SysYParser.ParamContext ctx) { return visitChildren(ctx); }
300 | /**
301 | * {@inheritDoc}
302 | *
303 | * The default implementation returns the result of calling
304 | * {@link #visitChildren} on {@code ctx}.
305 | */
306 | @Override public T visitConstExp(SysYParser.ConstExpContext ctx) { return visitChildren(ctx); }
307 | }
--------------------------------------------------------------------------------
/src/SysYParserVisitor.java:
--------------------------------------------------------------------------------
1 | // Generated from ./src/SysYParser.g4 by ANTLR 4.9.1
2 | import org.antlr.v4.runtime.tree.ParseTreeVisitor;
3 |
4 | /**
5 | * This interface defines a complete generic visitor for a parse tree produced
6 | * by {@link SysYParser}.
7 | *
8 | * @param The return type of the visit operation. Use {@link Void} for
9 | * operations with no return type.
10 | */
11 | public interface SysYParserVisitor extends ParseTreeVisitor {
12 | /**
13 | * Visit a parse tree produced by {@link SysYParser#program}.
14 | * @param ctx the parse tree
15 | * @return the visitor result
16 | */
17 | T visitProgram(SysYParser.ProgramContext ctx);
18 | /**
19 | * Visit a parse tree produced by {@link SysYParser#compUnit}.
20 | * @param ctx the parse tree
21 | * @return the visitor result
22 | */
23 | T visitCompUnit(SysYParser.CompUnitContext ctx);
24 | /**
25 | * Visit a parse tree produced by {@link SysYParser#decl}.
26 | * @param ctx the parse tree
27 | * @return the visitor result
28 | */
29 | T visitDecl(SysYParser.DeclContext ctx);
30 | /**
31 | * Visit a parse tree produced by {@link SysYParser#constDecl}.
32 | * @param ctx the parse tree
33 | * @return the visitor result
34 | */
35 | T visitConstDecl(SysYParser.ConstDeclContext ctx);
36 | /**
37 | * Visit a parse tree produced by {@link SysYParser#bType}.
38 | * @param ctx the parse tree
39 | * @return the visitor result
40 | */
41 | T visitBType(SysYParser.BTypeContext ctx);
42 | /**
43 | * Visit a parse tree produced by {@link SysYParser#constDef}.
44 | * @param ctx the parse tree
45 | * @return the visitor result
46 | */
47 | T visitConstDef(SysYParser.ConstDefContext ctx);
48 | /**
49 | * Visit a parse tree produced by {@link SysYParser#constInitVal}.
50 | * @param ctx the parse tree
51 | * @return the visitor result
52 | */
53 | T visitConstInitVal(SysYParser.ConstInitValContext ctx);
54 | /**
55 | * Visit a parse tree produced by {@link SysYParser#varDecl}.
56 | * @param ctx the parse tree
57 | * @return the visitor result
58 | */
59 | T visitVarDecl(SysYParser.VarDeclContext ctx);
60 | /**
61 | * Visit a parse tree produced by {@link SysYParser#varDef}.
62 | * @param ctx the parse tree
63 | * @return the visitor result
64 | */
65 | T visitVarDef(SysYParser.VarDefContext ctx);
66 | /**
67 | * Visit a parse tree produced by {@link SysYParser#initVal}.
68 | * @param ctx the parse tree
69 | * @return the visitor result
70 | */
71 | T visitInitVal(SysYParser.InitValContext ctx);
72 | /**
73 | * Visit a parse tree produced by {@link SysYParser#funcDef}.
74 | * @param ctx the parse tree
75 | * @return the visitor result
76 | */
77 | T visitFuncDef(SysYParser.FuncDefContext ctx);
78 | /**
79 | * Visit a parse tree produced by {@link SysYParser#funcType}.
80 | * @param ctx the parse tree
81 | * @return the visitor result
82 | */
83 | T visitFuncType(SysYParser.FuncTypeContext ctx);
84 | /**
85 | * Visit a parse tree produced by {@link SysYParser#funcFParams}.
86 | * @param ctx the parse tree
87 | * @return the visitor result
88 | */
89 | T visitFuncFParams(SysYParser.FuncFParamsContext ctx);
90 | /**
91 | * Visit a parse tree produced by {@link SysYParser#funcFParam}.
92 | * @param ctx the parse tree
93 | * @return the visitor result
94 | */
95 | T visitFuncFParam(SysYParser.FuncFParamContext ctx);
96 | /**
97 | * Visit a parse tree produced by {@link SysYParser#block}.
98 | * @param ctx the parse tree
99 | * @return the visitor result
100 | */
101 | T visitBlock(SysYParser.BlockContext ctx);
102 | /**
103 | * Visit a parse tree produced by {@link SysYParser#blockItem}.
104 | * @param ctx the parse tree
105 | * @return the visitor result
106 | */
107 | T visitBlockItem(SysYParser.BlockItemContext ctx);
108 | /**
109 | * Visit a parse tree produced by the {@code assignment}
110 | * labeled alternative in {@link SysYParser#stmt}.
111 | * @param ctx the parse tree
112 | * @return the visitor result
113 | */
114 | T visitAssignment(SysYParser.AssignmentContext ctx);
115 | /**
116 | * Visit a parse tree produced by the {@code possibleExp}
117 | * labeled alternative in {@link SysYParser#stmt}.
118 | * @param ctx the parse tree
119 | * @return the visitor result
120 | */
121 | T visitPossibleExp(SysYParser.PossibleExpContext ctx);
122 | /**
123 | * Visit a parse tree produced by the {@code blockStmt}
124 | * labeled alternative in {@link SysYParser#stmt}.
125 | * @param ctx the parse tree
126 | * @return the visitor result
127 | */
128 | T visitBlockStmt(SysYParser.BlockStmtContext ctx);
129 | /**
130 | * Visit a parse tree produced by the {@code ifStmt}
131 | * labeled alternative in {@link SysYParser#stmt}.
132 | * @param ctx the parse tree
133 | * @return the visitor result
134 | */
135 | T visitIfStmt(SysYParser.IfStmtContext ctx);
136 | /**
137 | * Visit a parse tree produced by the {@code whileStmt}
138 | * labeled alternative in {@link SysYParser#stmt}.
139 | * @param ctx the parse tree
140 | * @return the visitor result
141 | */
142 | T visitWhileStmt(SysYParser.WhileStmtContext ctx);
143 | /**
144 | * Visit a parse tree produced by the {@code breakStmt}
145 | * labeled alternative in {@link SysYParser#stmt}.
146 | * @param ctx the parse tree
147 | * @return the visitor result
148 | */
149 | T visitBreakStmt(SysYParser.BreakStmtContext ctx);
150 | /**
151 | * Visit a parse tree produced by the {@code continueStmt}
152 | * labeled alternative in {@link SysYParser#stmt}.
153 | * @param ctx the parse tree
154 | * @return the visitor result
155 | */
156 | T visitContinueStmt(SysYParser.ContinueStmtContext ctx);
157 | /**
158 | * Visit a parse tree produced by the {@code returnStmt}
159 | * labeled alternative in {@link SysYParser#stmt}.
160 | * @param ctx the parse tree
161 | * @return the visitor result
162 | */
163 | T visitReturnStmt(SysYParser.ReturnStmtContext ctx);
164 | /**
165 | * Visit a parse tree produced by the {@code lValExp}
166 | * labeled alternative in {@link SysYParser#exp}.
167 | * @param ctx the parse tree
168 | * @return the visitor result
169 | */
170 | T visitLValExp(SysYParser.LValExpContext ctx);
171 | /**
172 | * Visit a parse tree produced by the {@code unaryExp}
173 | * labeled alternative in {@link SysYParser#exp}.
174 | * @param ctx the parse tree
175 | * @return the visitor result
176 | */
177 | T visitUnaryExp(SysYParser.UnaryExpContext ctx);
178 | /**
179 | * Visit a parse tree produced by the {@code parenExp}
180 | * labeled alternative in {@link SysYParser#exp}.
181 | * @param ctx the parse tree
182 | * @return the visitor result
183 | */
184 | T visitParenExp(SysYParser.ParenExpContext ctx);
185 | /**
186 | * Visit a parse tree produced by the {@code addExp}
187 | * labeled alternative in {@link SysYParser#exp}.
188 | * @param ctx the parse tree
189 | * @return the visitor result
190 | */
191 | T visitAddExp(SysYParser.AddExpContext ctx);
192 | /**
193 | * Visit a parse tree produced by the {@code mulExp}
194 | * labeled alternative in {@link SysYParser#exp}.
195 | * @param ctx the parse tree
196 | * @return the visitor result
197 | */
198 | T visitMulExp(SysYParser.MulExpContext ctx);
199 | /**
200 | * Visit a parse tree produced by the {@code funcCallExp}
201 | * labeled alternative in {@link SysYParser#exp}.
202 | * @param ctx the parse tree
203 | * @return the visitor result
204 | */
205 | T visitFuncCallExp(SysYParser.FuncCallExpContext ctx);
206 | /**
207 | * Visit a parse tree produced by the {@code numExp}
208 | * labeled alternative in {@link SysYParser#exp}.
209 | * @param ctx the parse tree
210 | * @return the visitor result
211 | */
212 | T visitNumExp(SysYParser.NumExpContext ctx);
213 | /**
214 | * Visit a parse tree produced by the {@code compareExp}
215 | * labeled alternative in {@link SysYParser#cond}.
216 | * @param ctx the parse tree
217 | * @return the visitor result
218 | */
219 | T visitCompareExp(SysYParser.CompareExpContext ctx);
220 | /**
221 | * Visit a parse tree produced by the {@code relationExp}
222 | * labeled alternative in {@link SysYParser#cond}.
223 | * @param ctx the parse tree
224 | * @return the visitor result
225 | */
226 | T visitRelationExp(SysYParser.RelationExpContext ctx);
227 | /**
228 | * Visit a parse tree produced by the {@code condExp}
229 | * labeled alternative in {@link SysYParser#cond}.
230 | * @param ctx the parse tree
231 | * @return the visitor result
232 | */
233 | T visitCondExp(SysYParser.CondExpContext ctx);
234 | /**
235 | * Visit a parse tree produced by the {@code andExp}
236 | * labeled alternative in {@link SysYParser#cond}.
237 | * @param ctx the parse tree
238 | * @return the visitor result
239 | */
240 | T visitAndExp(SysYParser.AndExpContext ctx);
241 | /**
242 | * Visit a parse tree produced by the {@code orExp}
243 | * labeled alternative in {@link SysYParser#cond}.
244 | * @param ctx the parse tree
245 | * @return the visitor result
246 | */
247 | T visitOrExp(SysYParser.OrExpContext ctx);
248 | /**
249 | * Visit a parse tree produced by {@link SysYParser#lVal}.
250 | * @param ctx the parse tree
251 | * @return the visitor result
252 | */
253 | T visitLVal(SysYParser.LValContext ctx);
254 | /**
255 | * Visit a parse tree produced by {@link SysYParser#number}.
256 | * @param ctx the parse tree
257 | * @return the visitor result
258 | */
259 | T visitNumber(SysYParser.NumberContext ctx);
260 | /**
261 | * Visit a parse tree produced by {@link SysYParser#unaryOp}.
262 | * @param ctx the parse tree
263 | * @return the visitor result
264 | */
265 | T visitUnaryOp(SysYParser.UnaryOpContext ctx);
266 | /**
267 | * Visit a parse tree produced by {@link SysYParser#funcRParams}.
268 | * @param ctx the parse tree
269 | * @return the visitor result
270 | */
271 | T visitFuncRParams(SysYParser.FuncRParamsContext ctx);
272 | /**
273 | * Visit a parse tree produced by {@link SysYParser#param}.
274 | * @param ctx the parse tree
275 | * @return the visitor result
276 | */
277 | T visitParam(SysYParser.ParamContext ctx);
278 | /**
279 | * Visit a parse tree produced by {@link SysYParser#constExp}.
280 | * @param ctx the parse tree
281 | * @return the visitor result
282 | */
283 | T visitConstExp(SysYParser.ConstExpContext ctx);
284 | }
--------------------------------------------------------------------------------
/src/Type/ArrayType.java:
--------------------------------------------------------------------------------
1 | package Type;
2 |
3 | public class ArrayType implements Type {
4 | public Type elementType;
5 | int elementCount;
6 |
7 | public ArrayType(int elementCount, Type elementType) {
8 | this.elementCount = elementCount;
9 | this.elementType = elementType;
10 | }
11 |
12 | @Override
13 | public String toString() {
14 | return "array(" + elementType + ")";
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/Type/FunctionType.java:
--------------------------------------------------------------------------------
1 | package Type;
2 |
3 | import java.util.ArrayList;
4 |
5 | public class FunctionType implements Type {
6 | Type retType;
7 | ArrayList paramsType;
8 |
9 | public FunctionType(Type retType, ArrayList paramsType) {
10 | this.retType = retType;
11 | this.paramsType = paramsType;
12 | }
13 |
14 | public Type getRetType() {
15 | return retType;
16 | }
17 |
18 | public ArrayList getParamsType() {
19 | return paramsType;
20 | }
21 |
22 | @Override
23 | public String toString() {
24 | StringBuilder ret = new StringBuilder(retType + "(");
25 | for (Type type : paramsType) {
26 | ret.append(type.toString());
27 | }
28 | ret.append(")");
29 | return ret.toString();
30 | }
31 |
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src/Type/Type.java:
--------------------------------------------------------------------------------
1 | package Type;
2 |
3 | public interface Type {
4 | }
--------------------------------------------------------------------------------
/src/gen/SysYLexer.interp:
--------------------------------------------------------------------------------
1 | token literal names:
2 | null
3 | 'const'
4 | 'int'
5 | 'void'
6 | 'if'
7 | 'else'
8 | 'while'
9 | 'break'
10 | 'continue'
11 | 'return'
12 | '+'
13 | '-'
14 | '*'
15 | '/'
16 | '%'
17 | '='
18 | '=='
19 | '!='
20 | '<'
21 | '>'
22 | '<='
23 | '>='
24 | '!'
25 | '&&'
26 | '||'
27 | '('
28 | ')'
29 | '{'
30 | '}'
31 | '['
32 | ']'
33 | ','
34 | ';'
35 | null
36 | null
37 | null
38 | null
39 | null
40 |
41 | token symbolic names:
42 | null
43 | CONST
44 | INT
45 | VOID
46 | IF
47 | ELSE
48 | WHILE
49 | BREAK
50 | CONTINUE
51 | RETURN
52 | PLUS
53 | MINUS
54 | MUL
55 | DIV
56 | MOD
57 | ASSIGN
58 | EQ
59 | NEQ
60 | LT
61 | GT
62 | LE
63 | GE
64 | NOT
65 | AND
66 | OR
67 | L_PAREN
68 | R_PAREN
69 | L_BRACE
70 | R_BRACE
71 | L_BRACKT
72 | R_BRACKT
73 | COMMA
74 | SEMICOLON
75 | IDENT
76 | INTEGR_CONST
77 | WS
78 | SL_COMMENT
79 | ML_COMMENT
80 |
81 | rule names:
82 | CONST
83 | INT
84 | VOID
85 | IF
86 | ELSE
87 | WHILE
88 | BREAK
89 | CONTINUE
90 | RETURN
91 | PLUS
92 | MINUS
93 | MUL
94 | DIV
95 | MOD
96 | ASSIGN
97 | EQ
98 | NEQ
99 | LT
100 | GT
101 | LE
102 | GE
103 | NOT
104 | AND
105 | OR
106 | L_PAREN
107 | R_PAREN
108 | L_BRACE
109 | R_BRACE
110 | L_BRACKT
111 | R_BRACKT
112 | COMMA
113 | SEMICOLON
114 | IDENT
115 | INTEGR_CONST
116 | DECIMAL
117 | OCTAL
118 | HEXADECIMAL
119 | WS
120 | SL_COMMENT
121 | ML_COMMENT
122 | LETTER
123 | DIGIT
124 |
125 | channel names:
126 | DEFAULT_TOKEN_CHANNEL
127 | HIDDEN
128 |
129 | mode names:
130 | DEFAULT_MODE
131 |
132 | atn:
133 | [4, 0, 37, 271, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, 20, 2, 21, 7, 21, 2, 22, 7, 22, 2, 23, 7, 23, 2, 24, 7, 24, 2, 25, 7, 25, 2, 26, 7, 26, 2, 27, 7, 27, 2, 28, 7, 28, 2, 29, 7, 29, 2, 30, 7, 30, 2, 31, 7, 31, 2, 32, 7, 32, 2, 33, 7, 33, 2, 34, 7, 34, 2, 35, 7, 35, 2, 36, 7, 36, 2, 37, 7, 37, 2, 38, 7, 38, 2, 39, 7, 39, 2, 40, 7, 40, 2, 41, 7, 41, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 1, 3, 1, 3, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 10, 1, 10, 1, 11, 1, 11, 1, 12, 1, 12, 1, 13, 1, 13, 1, 14, 1, 14, 1, 15, 1, 15, 1, 15, 1, 16, 1, 16, 1, 16, 1, 17, 1, 17, 1, 18, 1, 18, 1, 19, 1, 19, 1, 19, 1, 20, 1, 20, 1, 20, 1, 21, 1, 21, 1, 22, 1, 22, 1, 22, 1, 23, 1, 23, 1, 23, 1, 24, 1, 24, 1, 25, 1, 25, 1, 26, 1, 26, 1, 27, 1, 27, 1, 28, 1, 28, 1, 29, 1, 29, 1, 30, 1, 30, 1, 31, 1, 31, 1, 32, 1, 32, 3, 32, 191, 8, 32, 1, 32, 1, 32, 1, 32, 5, 32, 196, 8, 32, 10, 32, 12, 32, 199, 9, 32, 1, 33, 1, 33, 1, 33, 3, 33, 204, 8, 33, 1, 34, 1, 34, 1, 34, 5, 34, 209, 8, 34, 10, 34, 12, 34, 212, 9, 34, 3, 34, 214, 8, 34, 1, 35, 1, 35, 4, 35, 218, 8, 35, 11, 35, 12, 35, 219, 1, 36, 1, 36, 1, 36, 1, 36, 3, 36, 226, 8, 36, 1, 36, 1, 36, 4, 36, 230, 8, 36, 11, 36, 12, 36, 231, 1, 37, 4, 37, 235, 8, 37, 11, 37, 12, 37, 236, 1, 37, 1, 37, 1, 38, 1, 38, 1, 38, 1, 38, 5, 38, 245, 8, 38, 10, 38, 12, 38, 248, 9, 38, 1, 38, 1, 38, 1, 38, 1, 38, 1, 39, 1, 39, 1, 39, 1, 39, 5, 39, 258, 8, 39, 10, 39, 12, 39, 261, 9, 39, 1, 39, 1, 39, 1, 39, 1, 39, 1, 39, 1, 40, 1, 40, 1, 41, 1, 41, 2, 246, 259, 0, 42, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10, 21, 11, 23, 12, 25, 13, 27, 14, 29, 15, 31, 16, 33, 17, 35, 18, 37, 19, 39, 20, 41, 21, 43, 22, 45, 23, 47, 24, 49, 25, 51, 26, 53, 27, 55, 28, 57, 29, 59, 30, 61, 31, 63, 32, 65, 33, 67, 34, 69, 0, 71, 0, 73, 0, 75, 35, 77, 36, 79, 37, 81, 0, 83, 0, 1, 0, 6, 1, 0, 49, 57, 1, 0, 48, 57, 1, 0, 48, 55, 2, 0, 65, 70, 97, 102, 3, 0, 9, 10, 13, 13, 32, 32, 2, 0, 65, 90, 97, 122, 280, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 27, 1, 0, 0, 0, 0, 29, 1, 0, 0, 0, 0, 31, 1, 0, 0, 0, 0, 33, 1, 0, 0, 0, 0, 35, 1, 0, 0, 0, 0, 37, 1, 0, 0, 0, 0, 39, 1, 0, 0, 0, 0, 41, 1, 0, 0, 0, 0, 43, 1, 0, 0, 0, 0, 45, 1, 0, 0, 0, 0, 47, 1, 0, 0, 0, 0, 49, 1, 0, 0, 0, 0, 51, 1, 0, 0, 0, 0, 53, 1, 0, 0, 0, 0, 55, 1, 0, 0, 0, 0, 57, 1, 0, 0, 0, 0, 59, 1, 0, 0, 0, 0, 61, 1, 0, 0, 0, 0, 63, 1, 0, 0, 0, 0, 65, 1, 0, 0, 0, 0, 67, 1, 0, 0, 0, 0, 75, 1, 0, 0, 0, 0, 77, 1, 0, 0, 0, 0, 79, 1, 0, 0, 0, 1, 85, 1, 0, 0, 0, 3, 91, 1, 0, 0, 0, 5, 95, 1, 0, 0, 0, 7, 100, 1, 0, 0, 0, 9, 103, 1, 0, 0, 0, 11, 108, 1, 0, 0, 0, 13, 114, 1, 0, 0, 0, 15, 120, 1, 0, 0, 0, 17, 129, 1, 0, 0, 0, 19, 136, 1, 0, 0, 0, 21, 138, 1, 0, 0, 0, 23, 140, 1, 0, 0, 0, 25, 142, 1, 0, 0, 0, 27, 144, 1, 0, 0, 0, 29, 146, 1, 0, 0, 0, 31, 148, 1, 0, 0, 0, 33, 151, 1, 0, 0, 0, 35, 154, 1, 0, 0, 0, 37, 156, 1, 0, 0, 0, 39, 158, 1, 0, 0, 0, 41, 161, 1, 0, 0, 0, 43, 164, 1, 0, 0, 0, 45, 166, 1, 0, 0, 0, 47, 169, 1, 0, 0, 0, 49, 172, 1, 0, 0, 0, 51, 174, 1, 0, 0, 0, 53, 176, 1, 0, 0, 0, 55, 178, 1, 0, 0, 0, 57, 180, 1, 0, 0, 0, 59, 182, 1, 0, 0, 0, 61, 184, 1, 0, 0, 0, 63, 186, 1, 0, 0, 0, 65, 190, 1, 0, 0, 0, 67, 203, 1, 0, 0, 0, 69, 213, 1, 0, 0, 0, 71, 215, 1, 0, 0, 0, 73, 225, 1, 0, 0, 0, 75, 234, 1, 0, 0, 0, 77, 240, 1, 0, 0, 0, 79, 253, 1, 0, 0, 0, 81, 267, 1, 0, 0, 0, 83, 269, 1, 0, 0, 0, 85, 86, 5, 99, 0, 0, 86, 87, 5, 111, 0, 0, 87, 88, 5, 110, 0, 0, 88, 89, 5, 115, 0, 0, 89, 90, 5, 116, 0, 0, 90, 2, 1, 0, 0, 0, 91, 92, 5, 105, 0, 0, 92, 93, 5, 110, 0, 0, 93, 94, 5, 116, 0, 0, 94, 4, 1, 0, 0, 0, 95, 96, 5, 118, 0, 0, 96, 97, 5, 111, 0, 0, 97, 98, 5, 105, 0, 0, 98, 99, 5, 100, 0, 0, 99, 6, 1, 0, 0, 0, 100, 101, 5, 105, 0, 0, 101, 102, 5, 102, 0, 0, 102, 8, 1, 0, 0, 0, 103, 104, 5, 101, 0, 0, 104, 105, 5, 108, 0, 0, 105, 106, 5, 115, 0, 0, 106, 107, 5, 101, 0, 0, 107, 10, 1, 0, 0, 0, 108, 109, 5, 119, 0, 0, 109, 110, 5, 104, 0, 0, 110, 111, 5, 105, 0, 0, 111, 112, 5, 108, 0, 0, 112, 113, 5, 101, 0, 0, 113, 12, 1, 0, 0, 0, 114, 115, 5, 98, 0, 0, 115, 116, 5, 114, 0, 0, 116, 117, 5, 101, 0, 0, 117, 118, 5, 97, 0, 0, 118, 119, 5, 107, 0, 0, 119, 14, 1, 0, 0, 0, 120, 121, 5, 99, 0, 0, 121, 122, 5, 111, 0, 0, 122, 123, 5, 110, 0, 0, 123, 124, 5, 116, 0, 0, 124, 125, 5, 105, 0, 0, 125, 126, 5, 110, 0, 0, 126, 127, 5, 117, 0, 0, 127, 128, 5, 101, 0, 0, 128, 16, 1, 0, 0, 0, 129, 130, 5, 114, 0, 0, 130, 131, 5, 101, 0, 0, 131, 132, 5, 116, 0, 0, 132, 133, 5, 117, 0, 0, 133, 134, 5, 114, 0, 0, 134, 135, 5, 110, 0, 0, 135, 18, 1, 0, 0, 0, 136, 137, 5, 43, 0, 0, 137, 20, 1, 0, 0, 0, 138, 139, 5, 45, 0, 0, 139, 22, 1, 0, 0, 0, 140, 141, 5, 42, 0, 0, 141, 24, 1, 0, 0, 0, 142, 143, 5, 47, 0, 0, 143, 26, 1, 0, 0, 0, 144, 145, 5, 37, 0, 0, 145, 28, 1, 0, 0, 0, 146, 147, 5, 61, 0, 0, 147, 30, 1, 0, 0, 0, 148, 149, 5, 61, 0, 0, 149, 150, 5, 61, 0, 0, 150, 32, 1, 0, 0, 0, 151, 152, 5, 33, 0, 0, 152, 153, 5, 61, 0, 0, 153, 34, 1, 0, 0, 0, 154, 155, 5, 60, 0, 0, 155, 36, 1, 0, 0, 0, 156, 157, 5, 62, 0, 0, 157, 38, 1, 0, 0, 0, 158, 159, 5, 60, 0, 0, 159, 160, 5, 61, 0, 0, 160, 40, 1, 0, 0, 0, 161, 162, 5, 62, 0, 0, 162, 163, 5, 61, 0, 0, 163, 42, 1, 0, 0, 0, 164, 165, 5, 33, 0, 0, 165, 44, 1, 0, 0, 0, 166, 167, 5, 38, 0, 0, 167, 168, 5, 38, 0, 0, 168, 46, 1, 0, 0, 0, 169, 170, 5, 124, 0, 0, 170, 171, 5, 124, 0, 0, 171, 48, 1, 0, 0, 0, 172, 173, 5, 40, 0, 0, 173, 50, 1, 0, 0, 0, 174, 175, 5, 41, 0, 0, 175, 52, 1, 0, 0, 0, 176, 177, 5, 123, 0, 0, 177, 54, 1, 0, 0, 0, 178, 179, 5, 125, 0, 0, 179, 56, 1, 0, 0, 0, 180, 181, 5, 91, 0, 0, 181, 58, 1, 0, 0, 0, 182, 183, 5, 93, 0, 0, 183, 60, 1, 0, 0, 0, 184, 185, 5, 44, 0, 0, 185, 62, 1, 0, 0, 0, 186, 187, 5, 59, 0, 0, 187, 64, 1, 0, 0, 0, 188, 191, 3, 81, 40, 0, 189, 191, 5, 95, 0, 0, 190, 188, 1, 0, 0, 0, 190, 189, 1, 0, 0, 0, 191, 197, 1, 0, 0, 0, 192, 196, 3, 81, 40, 0, 193, 196, 3, 83, 41, 0, 194, 196, 5, 95, 0, 0, 195, 192, 1, 0, 0, 0, 195, 193, 1, 0, 0, 0, 195, 194, 1, 0, 0, 0, 196, 199, 1, 0, 0, 0, 197, 195, 1, 0, 0, 0, 197, 198, 1, 0, 0, 0, 198, 66, 1, 0, 0, 0, 199, 197, 1, 0, 0, 0, 200, 204, 3, 71, 35, 0, 201, 204, 3, 73, 36, 0, 202, 204, 3, 69, 34, 0, 203, 200, 1, 0, 0, 0, 203, 201, 1, 0, 0, 0, 203, 202, 1, 0, 0, 0, 204, 68, 1, 0, 0, 0, 205, 214, 5, 48, 0, 0, 206, 210, 7, 0, 0, 0, 207, 209, 7, 1, 0, 0, 208, 207, 1, 0, 0, 0, 209, 212, 1, 0, 0, 0, 210, 208, 1, 0, 0, 0, 210, 211, 1, 0, 0, 0, 211, 214, 1, 0, 0, 0, 212, 210, 1, 0, 0, 0, 213, 205, 1, 0, 0, 0, 213, 206, 1, 0, 0, 0, 214, 70, 1, 0, 0, 0, 215, 217, 5, 48, 0, 0, 216, 218, 7, 2, 0, 0, 217, 216, 1, 0, 0, 0, 218, 219, 1, 0, 0, 0, 219, 217, 1, 0, 0, 0, 219, 220, 1, 0, 0, 0, 220, 72, 1, 0, 0, 0, 221, 222, 5, 48, 0, 0, 222, 226, 5, 120, 0, 0, 223, 224, 5, 48, 0, 0, 224, 226, 5, 88, 0, 0, 225, 221, 1, 0, 0, 0, 225, 223, 1, 0, 0, 0, 226, 229, 1, 0, 0, 0, 227, 230, 3, 83, 41, 0, 228, 230, 7, 3, 0, 0, 229, 227, 1, 0, 0, 0, 229, 228, 1, 0, 0, 0, 230, 231, 1, 0, 0, 0, 231, 229, 1, 0, 0, 0, 231, 232, 1, 0, 0, 0, 232, 74, 1, 0, 0, 0, 233, 235, 7, 4, 0, 0, 234, 233, 1, 0, 0, 0, 235, 236, 1, 0, 0, 0, 236, 234, 1, 0, 0, 0, 236, 237, 1, 0, 0, 0, 237, 238, 1, 0, 0, 0, 238, 239, 6, 37, 0, 0, 239, 76, 1, 0, 0, 0, 240, 241, 5, 47, 0, 0, 241, 242, 5, 47, 0, 0, 242, 246, 1, 0, 0, 0, 243, 245, 9, 0, 0, 0, 244, 243, 1, 0, 0, 0, 245, 248, 1, 0, 0, 0, 246, 247, 1, 0, 0, 0, 246, 244, 1, 0, 0, 0, 247, 249, 1, 0, 0, 0, 248, 246, 1, 0, 0, 0, 249, 250, 5, 10, 0, 0, 250, 251, 1, 0, 0, 0, 251, 252, 6, 38, 0, 0, 252, 78, 1, 0, 0, 0, 253, 254, 5, 47, 0, 0, 254, 255, 5, 42, 0, 0, 255, 259, 1, 0, 0, 0, 256, 258, 9, 0, 0, 0, 257, 256, 1, 0, 0, 0, 258, 261, 1, 0, 0, 0, 259, 260, 1, 0, 0, 0, 259, 257, 1, 0, 0, 0, 260, 262, 1, 0, 0, 0, 261, 259, 1, 0, 0, 0, 262, 263, 5, 42, 0, 0, 263, 264, 5, 47, 0, 0, 264, 265, 1, 0, 0, 0, 265, 266, 6, 39, 0, 0, 266, 80, 1, 0, 0, 0, 267, 268, 7, 5, 0, 0, 268, 82, 1, 0, 0, 0, 269, 270, 7, 1, 0, 0, 270, 84, 1, 0, 0, 0, 14, 0, 190, 195, 197, 203, 210, 213, 219, 225, 229, 231, 236, 246, 259, 1, 6, 0, 0]
--------------------------------------------------------------------------------
/src/gen/SysYLexer.tokens:
--------------------------------------------------------------------------------
1 | CONST=1
2 | INT=2
3 | VOID=3
4 | IF=4
5 | ELSE=5
6 | WHILE=6
7 | BREAK=7
8 | CONTINUE=8
9 | RETURN=9
10 | PLUS=10
11 | MINUS=11
12 | MUL=12
13 | DIV=13
14 | MOD=14
15 | ASSIGN=15
16 | EQ=16
17 | NEQ=17
18 | LT=18
19 | GT=19
20 | LE=20
21 | GE=21
22 | NOT=22
23 | AND=23
24 | OR=24
25 | L_PAREN=25
26 | R_PAREN=26
27 | L_BRACE=27
28 | R_BRACE=28
29 | L_BRACKT=29
30 | R_BRACKT=30
31 | COMMA=31
32 | SEMICOLON=32
33 | IDENT=33
34 | INTEGR_CONST=34
35 | WS=35
36 | SL_COMMENT=36
37 | ML_COMMENT=37
38 | 'const'=1
39 | 'int'=2
40 | 'void'=3
41 | 'if'=4
42 | 'else'=5
43 | 'while'=6
44 | 'break'=7
45 | 'continue'=8
46 | 'return'=9
47 | '+'=10
48 | '-'=11
49 | '*'=12
50 | '/'=13
51 | '%'=14
52 | '='=15
53 | '=='=16
54 | '!='=17
55 | '<'=18
56 | '>'=19
57 | '<='=20
58 | '>='=21
59 | '!'=22
60 | '&&'=23
61 | '||'=24
62 | '('=25
63 | ')'=26
64 | '{'=27
65 | '}'=28
66 | '['=29
67 | ']'=30
68 | ','=31
69 | ';'=32
70 |
--------------------------------------------------------------------------------
/submit.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -e
3 |
4 | # Change USERNAME, PASSWORD
5 | USERNAME="201250172"
6 | PASSWORD="123456"
7 |
8 | echo "--------Begin to Submit--------"
9 |
10 | if [[ $USERNAME == "20xxxxxxx" || $PASSWORD == "xxxxxxxxx" ]]; then
11 | echo "Fail. You need to change USERNAME and PASSWORD"
12 | exit -1
13 | fi
14 |
15 | COURSE=PTC2022
16 | MODULE=$(git rev-parse --abbrev-ref HEAD | tr '[a-z]' '[A-Z]')
17 | WORKSPACE=$(basename $(realpath .))
18 | FILE=submit.zip
19 |
20 | #if [[ $(git status --porcelain) ]]; then
21 | # echo "Error: Git repository is dirty."
22 | # echo "Commit all your changes before submitting."
23 | # echo "Hint: run 'git status' to show changed files."
24 | # exit -1
25 | #fi
26 |
27 | # Construct assignmentId
28 | ANTLRTMP="labN"
29 |
30 | BRANCH=$(git symbolic-ref --short -q HEAD)
31 | NUMBER=$(echo $BRANCH | tr -cd "[0-9]")
32 | ID=$(echo $ANTLRTMP | sed "s/N/${NUMBER}/g")
33 |
34 | echo "In branch: $BRANCH "
35 | echo "Submit to assignment: $ID"
36 |
37 |
38 | # Compress the whole folder instead of git storage only.
39 | cd ..
40 | rm -f $FILE
41 | zip -r "$FILE" $(ls -d "$WORKSPACE/.git" 2>/dev/null) > /dev/null
42 | if [ $? -ne 0 ]; then
43 | echo ""
44 | echo "Fail to zip for submit.zip!"
45 | else
46 | echo ""
47 | echo "generate submit.zip"
48 | fi
49 |
50 |
51 | # construct json for cul
52 | TMPRAW='{"username":"XXXUSERXXX","password":"YYYPWDYYY"}'
53 | DATARAW=$(echo $TMPRAW | sed "s/XXXUSERXXX/$USERNAME/g" | sed "s/YYYPWDYYY/$PASSWORD/g")
54 | URL=http://47.122.3.40:28300
55 |
56 | # extract token
57 | RAW=$(curl "$URL/auth/login" \
58 | -H 'Content-Type: application/json' \
59 | --data-raw $DATARAW )
60 | TOKEN=$(echo $RAW | sed 's/,/\n/g' | grep "token" | sed 's/:/\n/g' | sed '1d' | sed 's/}//g' | sed 's/\"//g')
61 |
62 | RES=$(curl "$URL/submissions" \
63 | -H "Authorization: Bearer $TOKEN" \
64 | -F "assignmentId=$ID" \
65 | -F "file=@$FILE" )
66 |
67 | FLAG0=$?
68 |
69 | TIME=$(echo $RES | sed 's/,/\n/g' | grep "createdAt" | sed 's/:/\n/g' | sed '1d' | sed 's/}//g' | sed 's/\"//g')
70 |
71 | if [[ $FLAG0 -ne 0 || -z $TIME ]]; then
72 | echo ""
73 | echo "T_T Commit Fail! T_T"
74 | else
75 | echo ""
76 | echo "^v^ Commit Success! ^v^ "
77 | fi
78 |
79 |
--------------------------------------------------------------------------------
/target/classes/LLVMIRVisitor.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/LLVMIRVisitor.class
--------------------------------------------------------------------------------
/target/classes/Main.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/Main.class
--------------------------------------------------------------------------------
/target/classes/Scope/BaseScope.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/Scope/BaseScope.class
--------------------------------------------------------------------------------
/target/classes/Scope/FunctionScope.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/Scope/FunctionScope.class
--------------------------------------------------------------------------------
/target/classes/Scope/GlobalScope.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/Scope/GlobalScope.class
--------------------------------------------------------------------------------
/target/classes/Scope/LocalScope.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/Scope/LocalScope.class
--------------------------------------------------------------------------------
/target/classes/Scope/Scope.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/Scope/Scope.class
--------------------------------------------------------------------------------
/target/classes/Symbol/BaseSymbol.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/Symbol/BaseSymbol.class
--------------------------------------------------------------------------------
/target/classes/Symbol/BasicTypeSymbol.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/Symbol/BasicTypeSymbol.class
--------------------------------------------------------------------------------
/target/classes/Symbol/Symbol.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/Symbol/Symbol.class
--------------------------------------------------------------------------------
/target/classes/Symbol/VariableSymbol.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/Symbol/VariableSymbol.class
--------------------------------------------------------------------------------
/target/classes/SysYLexer.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYLexer.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$AddExpContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$AddExpContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$AndExpContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$AndExpContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$AssignmentContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$AssignmentContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$BTypeContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$BTypeContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$BlockContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$BlockContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$BlockItemContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$BlockItemContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$BlockStmtContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$BlockStmtContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$BreakStmtContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$BreakStmtContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$CompUnitContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$CompUnitContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$CompareExpContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$CompareExpContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$CondContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$CondContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$CondExpContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$CondExpContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$ConstDeclContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$ConstDeclContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$ConstDefContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$ConstDefContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$ConstExpContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$ConstExpContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$ConstInitValContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$ConstInitValContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$ContinueStmtContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$ContinueStmtContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$DeclContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$DeclContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$ExpContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$ExpContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$FuncCallExpContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$FuncCallExpContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$FuncDefContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$FuncDefContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$FuncFParamContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$FuncFParamContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$FuncFParamsContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$FuncFParamsContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$FuncRParamsContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$FuncRParamsContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$FuncTypeContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$FuncTypeContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$IfStmtContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$IfStmtContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$InitValContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$InitValContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$LValContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$LValContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$LValExpContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$LValExpContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$MulExpContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$MulExpContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$NumExpContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$NumExpContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$NumberContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$NumberContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$OrExpContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$OrExpContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$ParamContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$ParamContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$ParenExpContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$ParenExpContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$PossibleExpContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$PossibleExpContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$ProgramContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$ProgramContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$RelationExpContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$RelationExpContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$ReturnStmtContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$ReturnStmtContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$StmtContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$StmtContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$UnaryExpContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$UnaryExpContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$UnaryOpContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$UnaryOpContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$VarDeclContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$VarDeclContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$VarDefContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$VarDefContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser$WhileStmtContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser$WhileStmtContext.class
--------------------------------------------------------------------------------
/target/classes/SysYParser.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParser.class
--------------------------------------------------------------------------------
/target/classes/SysYParserBaseListener.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParserBaseListener.class
--------------------------------------------------------------------------------
/target/classes/SysYParserBaseVisitor.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParserBaseVisitor.class
--------------------------------------------------------------------------------
/target/classes/SysYParserListener.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParserListener.class
--------------------------------------------------------------------------------
/target/classes/SysYParserVisitor.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/SysYParserVisitor.class
--------------------------------------------------------------------------------
/target/classes/Type/ArrayType.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/Type/ArrayType.class
--------------------------------------------------------------------------------
/target/classes/Type/FunctionType.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/Type/FunctionType.class
--------------------------------------------------------------------------------
/target/classes/Type/Type.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/Type/Type.class
--------------------------------------------------------------------------------
/target/classes/Visitor.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EagleBear2002/Compiler-Lab/3c31797ca142ffc5116fc77f51d1477f1c9433ba/target/classes/Visitor.class
--------------------------------------------------------------------------------
/tests/lab1-test1.sysy:
--------------------------------------------------------------------------------
1 | int main()
2 | {
3 | // line comment
4 | /*
5 | block comment
6 | */
7 | int i = 0x1;
8 | }
9 |
--------------------------------------------------------------------------------
/tests/lab1-test2.sysy:
--------------------------------------------------------------------------------
1 | int main(){
2 | int i = 1;
3 | int j = ~i;
4 | }
5 |
--------------------------------------------------------------------------------
/tests/lab2-test1.sysy:
--------------------------------------------------------------------------------
1 | const int c = 10;
2 | int main() {
3 | int a = 0x10;
4 | const int b = 9;
5 | return a;
6 | }
7 |
--------------------------------------------------------------------------------
/tests/lab2-test2.sysy:
--------------------------------------------------------------------------------
1 | int main(){
2 | int a[];
3 | return a][;
4 | }
5 |
--------------------------------------------------------------------------------
/tests/lab3-rename-test.sysy:
--------------------------------------------------------------------------------
1 | int a() {
2 | return 10;
3 | }
4 |
5 | int main() {
6 | int a = 3;
7 | int b = 4;
8 | a = 5;
9 | return a;
10 | }
11 |
--------------------------------------------------------------------------------
/tests/lab3-type-test1.sysy:
--------------------------------------------------------------------------------
1 | int a(){
2 | return 1;
3 | }
4 |
5 | int a(){
6 | return 0;
7 | }
8 |
9 | int main(){
10 | b = c();
11 | int test1;
12 | int test1;
13 | int array[2] = {0,0};
14 | test1 = array;
15 | test1 = a + array;
16 | test1 = a(1);
17 | test1 = test1[0];
18 | test1();
19 | a = 1;
20 | return a;
21 | }
22 |
--------------------------------------------------------------------------------
/tests/lab3-type-test2.sysy:
--------------------------------------------------------------------------------
1 | int globalVar;
2 | int globalArray[2];
3 |
4 | void voidFunc1() {
5 | return;
6 | }
7 |
8 | void voidFunc2(int param1) {
9 | return 1; // type 7
10 | }
11 |
12 | void voidFunc3(int param1, int param2[]) {
13 | return param1; // type 7
14 | }
15 |
16 | int intFunc1() {
17 | return 1;
18 | }
19 |
20 | int intFunc1(int param) { // type 4
21 | return intFunc1(); // valid
22 | }
23 |
24 | int intFunc2(int param1) {
25 | return intFunc2(param1); // valid
26 | }
27 |
28 | int intFunc3(int param1, int param2[]) {
29 | return param2; // type 7
30 | }
31 |
32 | int voidFunc1() { // type 4
33 |
34 | }
35 |
36 | int test(int i, int i){ // type 3
37 | return test(i + 1); // valid
38 | }
39 |
40 | int main(){
41 | a = 3; // type 1
42 | int b = func(); // type 2
43 | int b; // type 3
44 |
45 | int c[3][3][3];
46 | int d[2][2];
47 | c[1] = d; // valid
48 | c[1][1] = d; // type 5
49 | c[1][1] = d; // type 5
50 | int f = voidFunc1() + intFunc1(); // type 6
51 | int g = intFunc3(b); // type 8
52 | int h = intFunc3(b, globalArray); // valid
53 |
54 | int i = b[5]; // type 9
55 | int j = c(); // type 10
56 | c = 6; // type 5
57 | voidFunc1 = 6; // type 11
58 |
59 | if (1 || globalArray || 2 || d) { // type 6 for 3 times
60 |
61 | }
62 |
63 | int k = voidFunc1(); // type 5
64 | int l = voidFunc(); // type 2
65 | int m = k;
66 | return z(); // type 2
67 | }
--------------------------------------------------------------------------------
/tests/lab4-test1.sysy:
--------------------------------------------------------------------------------
1 | int main(){
2 | return -2147483647 / -1;
3 | }
4 |
--------------------------------------------------------------------------------
/tests/lab4-test2.sysy:
--------------------------------------------------------------------------------
1 | int main(){
2 | return 3+2*5;
3 | }
4 |
--------------------------------------------------------------------------------
/tests/lab5-test1.sysy:
--------------------------------------------------------------------------------
1 | int f(int i){
2 | return i;
3 | }
4 |
5 | void g() {
6 | int j = 1 + 5;
7 | return;
8 | }
9 |
10 | void func() {
11 | }
12 |
13 | int main(){
14 | int a = 1;
15 | int array[5] = {1, 2, 3};
16 | array[3] = a;
17 | array[4] = a + 5;
18 | g();
19 | return f(a * array[4]);
20 | }
21 |
--------------------------------------------------------------------------------
/tests/lab5-test2.sysy:
--------------------------------------------------------------------------------
1 | int main(){
2 | int a[3] = {1,2,3};
3 | return a[1];
4 | }
5 |
--------------------------------------------------------------------------------
/tests/lab6-test1.sysy:
--------------------------------------------------------------------------------
1 | int a[3] = { 0,1,1 };
2 | int main() {
3 | a[0] = !a[0];
4 | if (a[0]) {
5 | a[1] = 2;
6 | }
7 | return a[1];
8 | }
9 |
--------------------------------------------------------------------------------
/tests/lab6-test2.sysy:
--------------------------------------------------------------------------------
1 | int a[10] = {};
2 |
3 | int f(int a) {
4 | return 0;
5 | }
6 |
7 | int main() {
8 | a[1] = 1;
9 | return 0;
10 | }
--------------------------------------------------------------------------------
/tests/lab7-test1.sysy:
--------------------------------------------------------------------------------
1 | int a[10]={5,4,3,2,1,8,6,2,4,7};
2 |
3 | int main(){
4 | int i=0,j=0;
5 | int min=0;
6 | while(i<9){
7 | j=i;
8 | min=i;
9 | while(j<9){
10 | if(a[j]