1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
|
// Generated from /home/gabri/Desktop/clp_project/src/svm/SVM.g4 by ANTLR 4.13.1
package svm;
import java.util.HashMap;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.misc.*;
import org.antlr.v4.runtime.tree.*;
import java.util.List;
import java.util.Iterator;
import java.util.ArrayList;
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue"})
public class SVMParser extends Parser {
static { RuntimeMetaData.checkVersion("4.13.1", RuntimeMetaData.VERSION); }
protected static final DFA[] _decisionToDFA;
protected static final PredictionContextCache _sharedContextCache =
new PredictionContextCache();
public static final int
T__0=1, T__1=2, T__2=3, LOAD=4, STORE=5, STOREI=6, MOVE=7, ADD=8, ADDI=9,
SUB=10, SUBI=11, MUL=12, MULI=13, DIV=14, DIVI=15, PUSH=16, PUSHR=17,
POP=18, POPR=19, BRANCH=20, BRANCHEQ=21, BRANCHLESSEQ=22, JUMPSUB=23,
RETURNSUB=24, HALT=25, REG=26, LABEL=27, NUMBER=28, WHITESP=29, LINECOMENTS=30,
ERR=31;
public static final int
RULE_assembly = 0, RULE_instruction = 1;
private static String[] makeRuleNames() {
return new String[] {
"assembly", "instruction"
};
}
public static final String[] ruleNames = makeRuleNames();
private static String[] makeLiteralNames() {
return new String[] {
null, "'('", "')'", "':'", "'load'", "'store'", "'storei'", "'move'",
"'add'", "'addi'", "'sub'", "'subi'", "'mul'", "'muli'", "'div'", "'divi'",
"'push'", "'pushr'", "'pop'", "'popr'", "'b'", "'beq'", "'bleq'", "'jsub'",
"'rsub'", "'halt'"
};
}
private static final String[] _LITERAL_NAMES = makeLiteralNames();
private static String[] makeSymbolicNames() {
return new String[] {
null, null, null, null, "LOAD", "STORE", "STOREI", "MOVE", "ADD", "ADDI",
"SUB", "SUBI", "MUL", "MULI", "DIV", "DIVI", "PUSH", "PUSHR", "POP",
"POPR", "BRANCH", "BRANCHEQ", "BRANCHLESSEQ", "JUMPSUB", "RETURNSUB",
"HALT", "REG", "LABEL", "NUMBER", "WHITESP", "LINECOMENTS", "ERR"
};
}
private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames();
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
/**
* @deprecated Use {@link #VOCABULARY} instead.
*/
@Deprecated
public static final String[] tokenNames;
static {
tokenNames = new String[_SYMBOLIC_NAMES.length];
for (int i = 0; i < tokenNames.length; i++) {
tokenNames[i] = VOCABULARY.getLiteralName(i);
if (tokenNames[i] == null) {
tokenNames[i] = VOCABULARY.getSymbolicName(i);
}
if (tokenNames[i] == null) {
tokenNames[i] = "<INVALID>";
}
}
}
@Override
@Deprecated
public String[] getTokenNames() {
return tokenNames;
}
@Override
public Vocabulary getVocabulary() {
return VOCABULARY;
}
@Override
public String getGrammarFileName() { return "SVM.g4"; }
@Override
public String[] getRuleNames() { return ruleNames; }
@Override
public String getSerializedATN() { return _serializedATN; }
@Override
public ATN getATN() { return _ATN; }
public SVMParser(TokenStream input) {
super(input);
_interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
@SuppressWarnings("CheckReturnValue")
public static class AssemblyContext extends ParserRuleContext {
public List<InstructionContext> instruction() {
return getRuleContexts(InstructionContext.class);
}
public InstructionContext instruction(int i) {
return getRuleContext(InstructionContext.class,i);
}
public AssemblyContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_assembly; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof SVMListener ) ((SVMListener)listener).enterAssembly(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof SVMListener ) ((SVMListener)listener).exitAssembly(this);
}
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof SVMVisitor ) return ((SVMVisitor<? extends T>)visitor).visitAssembly(this);
else return visitor.visitChildren(this);
}
}
public final AssemblyContext assembly() throws RecognitionException {
AssemblyContext _localctx = new AssemblyContext(_ctx, getState());
enterRule(_localctx, 0, RULE_assembly);
int _la;
try {
enterOuterAlt(_localctx, 1);
{
setState(7);
_errHandler.sync(this);
_la = _input.LA(1);
while ((((_la) & ~0x3f) == 0 && ((1L << _la) & 201326576L) != 0)) {
{
{
setState(4);
instruction();
}
}
setState(9);
_errHandler.sync(this);
_la = _input.LA(1);
}
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
@SuppressWarnings("CheckReturnValue")
public static class InstructionContext extends ParserRuleContext {
public Token n;
public Token l;
public TerminalNode LOAD() { return getToken(SVMParser.LOAD, 0); }
public List<TerminalNode> REG() { return getTokens(SVMParser.REG); }
public TerminalNode REG(int i) {
return getToken(SVMParser.REG, i);
}
public TerminalNode NUMBER() { return getToken(SVMParser.NUMBER, 0); }
public TerminalNode STORE() { return getToken(SVMParser.STORE, 0); }
public TerminalNode STOREI() { return getToken(SVMParser.STOREI, 0); }
public TerminalNode MOVE() { return getToken(SVMParser.MOVE, 0); }
public TerminalNode ADD() { return getToken(SVMParser.ADD, 0); }
public TerminalNode ADDI() { return getToken(SVMParser.ADDI, 0); }
public TerminalNode SUB() { return getToken(SVMParser.SUB, 0); }
public TerminalNode SUBI() { return getToken(SVMParser.SUBI, 0); }
public TerminalNode MUL() { return getToken(SVMParser.MUL, 0); }
public TerminalNode MULI() { return getToken(SVMParser.MULI, 0); }
public TerminalNode DIV() { return getToken(SVMParser.DIV, 0); }
public TerminalNode DIVI() { return getToken(SVMParser.DIVI, 0); }
public TerminalNode PUSH() { return getToken(SVMParser.PUSH, 0); }
public TerminalNode PUSHR() { return getToken(SVMParser.PUSHR, 0); }
public TerminalNode POP() { return getToken(SVMParser.POP, 0); }
public TerminalNode POPR() { return getToken(SVMParser.POPR, 0); }
public TerminalNode BRANCH() { return getToken(SVMParser.BRANCH, 0); }
public TerminalNode LABEL() { return getToken(SVMParser.LABEL, 0); }
public TerminalNode BRANCHEQ() { return getToken(SVMParser.BRANCHEQ, 0); }
public TerminalNode BRANCHLESSEQ() { return getToken(SVMParser.BRANCHLESSEQ, 0); }
public TerminalNode JUMPSUB() { return getToken(SVMParser.JUMPSUB, 0); }
public TerminalNode RETURNSUB() { return getToken(SVMParser.RETURNSUB, 0); }
public TerminalNode HALT() { return getToken(SVMParser.HALT, 0); }
public InstructionContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_instruction; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof SVMListener ) ((SVMListener)listener).enterInstruction(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof SVMListener ) ((SVMListener)listener).exitInstruction(this);
}
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof SVMVisitor ) return ((SVMVisitor<? extends T>)visitor).visitInstruction(this);
else return visitor.visitChildren(this);
}
}
public final InstructionContext instruction() throws RecognitionException {
InstructionContext _localctx = new InstructionContext(_ctx, getState());
enterRule(_localctx, 2, RULE_instruction);
try {
enterOuterAlt(_localctx, 1);
{
setState(79);
_errHandler.sync(this);
switch (_input.LA(1)) {
case LOAD:
{
setState(10);
match(LOAD);
setState(11);
match(REG);
setState(12);
match(NUMBER);
setState(13);
match(T__0);
setState(14);
match(REG);
setState(15);
match(T__1);
}
break;
case STORE:
{
setState(16);
match(STORE);
setState(17);
match(REG);
setState(18);
match(NUMBER);
setState(19);
match(T__0);
setState(20);
match(REG);
setState(21);
match(T__1);
}
break;
case STOREI:
{
setState(22);
match(STOREI);
setState(23);
match(REG);
setState(24);
match(NUMBER);
}
break;
case MOVE:
{
setState(25);
match(MOVE);
setState(26);
match(REG);
setState(27);
match(REG);
}
break;
case ADD:
{
setState(28);
match(ADD);
setState(29);
match(REG);
setState(30);
match(REG);
}
break;
case ADDI:
{
setState(31);
match(ADDI);
setState(32);
match(REG);
setState(33);
match(NUMBER);
}
break;
case SUB:
{
setState(34);
match(SUB);
setState(35);
match(REG);
setState(36);
match(REG);
}
break;
case SUBI:
{
setState(37);
match(SUBI);
setState(38);
match(REG);
setState(39);
match(NUMBER);
}
break;
case MUL:
{
setState(40);
match(MUL);
setState(41);
match(REG);
setState(42);
match(REG);
}
break;
case MULI:
{
setState(43);
match(MULI);
setState(44);
match(REG);
setState(45);
match(NUMBER);
}
break;
case DIV:
{
setState(46);
match(DIV);
setState(47);
match(REG);
setState(48);
match(REG);
}
break;
case DIVI:
{
setState(49);
match(DIVI);
setState(50);
match(REG);
setState(51);
match(NUMBER);
}
break;
case PUSH:
{
setState(52);
match(PUSH);
setState(55);
_errHandler.sync(this);
switch (_input.LA(1)) {
case NUMBER:
{
setState(53);
((InstructionContext)_localctx).n = match(NUMBER);
}
break;
case LABEL:
{
setState(54);
((InstructionContext)_localctx).l = match(LABEL);
}
break;
default:
throw new NoViableAltException(this);
}
}
break;
case PUSHR:
{
setState(57);
match(PUSHR);
setState(58);
match(REG);
}
break;
case POP:
{
setState(59);
match(POP);
}
break;
case POPR:
{
setState(60);
match(POPR);
setState(61);
match(REG);
}
break;
case BRANCH:
{
setState(62);
match(BRANCH);
setState(63);
match(LABEL);
}
break;
case BRANCHEQ:
{
setState(64);
match(BRANCHEQ);
setState(65);
match(REG);
setState(66);
match(REG);
setState(67);
match(LABEL);
}
break;
case BRANCHLESSEQ:
{
setState(68);
match(BRANCHLESSEQ);
setState(69);
match(REG);
setState(70);
match(REG);
setState(71);
match(LABEL);
}
break;
case JUMPSUB:
{
setState(72);
match(JUMPSUB);
setState(73);
match(LABEL);
}
break;
case RETURNSUB:
{
setState(74);
match(RETURNSUB);
setState(75);
match(REG);
}
break;
case LABEL:
{
setState(76);
((InstructionContext)_localctx).l = match(LABEL);
setState(77);
match(T__2);
}
break;
case HALT:
{
setState(78);
match(HALT);
}
break;
default:
throw new NoViableAltException(this);
}
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static final String _serializedATN =
"\u0004\u0001\u001fR\u0002\u0000\u0007\u0000\u0002\u0001\u0007\u0001\u0001"+
"\u0000\u0005\u0000\u0006\b\u0000\n\u0000\f\u0000\t\t\u0000\u0001\u0001"+
"\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001"+
"\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001"+
"\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001"+
"\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001"+
"\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001"+
"\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001"+
"\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001"+
"\u0001\u0001\u0001\u0001\u0003\u00018\b\u0001\u0001\u0001\u0001\u0001"+
"\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001"+
"\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001"+
"\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001"+
"\u0001\u0001\u0001\u0001\u0003\u0001P\b\u0001\u0001\u0001\u0000\u0000"+
"\u0002\u0000\u0002\u0000\u0000g\u0000\u0007\u0001\u0000\u0000\u0000\u0002"+
"O\u0001\u0000\u0000\u0000\u0004\u0006\u0003\u0002\u0001\u0000\u0005\u0004"+
"\u0001\u0000\u0000\u0000\u0006\t\u0001\u0000\u0000\u0000\u0007\u0005\u0001"+
"\u0000\u0000\u0000\u0007\b\u0001\u0000\u0000\u0000\b\u0001\u0001\u0000"+
"\u0000\u0000\t\u0007\u0001\u0000\u0000\u0000\n\u000b\u0005\u0004\u0000"+
"\u0000\u000b\f\u0005\u001a\u0000\u0000\f\r\u0005\u001c\u0000\u0000\r\u000e"+
"\u0005\u0001\u0000\u0000\u000e\u000f\u0005\u001a\u0000\u0000\u000fP\u0005"+
"\u0002\u0000\u0000\u0010\u0011\u0005\u0005\u0000\u0000\u0011\u0012\u0005"+
"\u001a\u0000\u0000\u0012\u0013\u0005\u001c\u0000\u0000\u0013\u0014\u0005"+
"\u0001\u0000\u0000\u0014\u0015\u0005\u001a\u0000\u0000\u0015P\u0005\u0002"+
"\u0000\u0000\u0016\u0017\u0005\u0006\u0000\u0000\u0017\u0018\u0005\u001a"+
"\u0000\u0000\u0018P\u0005\u001c\u0000\u0000\u0019\u001a\u0005\u0007\u0000"+
"\u0000\u001a\u001b\u0005\u001a\u0000\u0000\u001bP\u0005\u001a\u0000\u0000"+
"\u001c\u001d\u0005\b\u0000\u0000\u001d\u001e\u0005\u001a\u0000\u0000\u001e"+
"P\u0005\u001a\u0000\u0000\u001f \u0005\t\u0000\u0000 !\u0005\u001a\u0000"+
"\u0000!P\u0005\u001c\u0000\u0000\"#\u0005\n\u0000\u0000#$\u0005\u001a"+
"\u0000\u0000$P\u0005\u001a\u0000\u0000%&\u0005\u000b\u0000\u0000&\'\u0005"+
"\u001a\u0000\u0000\'P\u0005\u001c\u0000\u0000()\u0005\f\u0000\u0000)*"+
"\u0005\u001a\u0000\u0000*P\u0005\u001a\u0000\u0000+,\u0005\r\u0000\u0000"+
",-\u0005\u001a\u0000\u0000-P\u0005\u001c\u0000\u0000./\u0005\u000e\u0000"+
"\u0000/0\u0005\u001a\u0000\u00000P\u0005\u001a\u0000\u000012\u0005\u000f"+
"\u0000\u000023\u0005\u001a\u0000\u00003P\u0005\u001c\u0000\u000047\u0005"+
"\u0010\u0000\u000058\u0005\u001c\u0000\u000068\u0005\u001b\u0000\u0000"+
"75\u0001\u0000\u0000\u000076\u0001\u0000\u0000\u00008P\u0001\u0000\u0000"+
"\u00009:\u0005\u0011\u0000\u0000:P\u0005\u001a\u0000\u0000;P\u0005\u0012"+
"\u0000\u0000<=\u0005\u0013\u0000\u0000=P\u0005\u001a\u0000\u0000>?\u0005"+
"\u0014\u0000\u0000?P\u0005\u001b\u0000\u0000@A\u0005\u0015\u0000\u0000"+
"AB\u0005\u001a\u0000\u0000BC\u0005\u001a\u0000\u0000CP\u0005\u001b\u0000"+
"\u0000DE\u0005\u0016\u0000\u0000EF\u0005\u001a\u0000\u0000FG\u0005\u001a"+
"\u0000\u0000GP\u0005\u001b\u0000\u0000HI\u0005\u0017\u0000\u0000IP\u0005"+
"\u001b\u0000\u0000JK\u0005\u0018\u0000\u0000KP\u0005\u001a\u0000\u0000"+
"LM\u0005\u001b\u0000\u0000MP\u0005\u0003\u0000\u0000NP\u0005\u0019\u0000"+
"\u0000O\n\u0001\u0000\u0000\u0000O\u0010\u0001\u0000\u0000\u0000O\u0016"+
"\u0001\u0000\u0000\u0000O\u0019\u0001\u0000\u0000\u0000O\u001c\u0001\u0000"+
"\u0000\u0000O\u001f\u0001\u0000\u0000\u0000O\"\u0001\u0000\u0000\u0000"+
"O%\u0001\u0000\u0000\u0000O(\u0001\u0000\u0000\u0000O+\u0001\u0000\u0000"+
"\u0000O.\u0001\u0000\u0000\u0000O1\u0001\u0000\u0000\u0000O4\u0001\u0000"+
"\u0000\u0000O9\u0001\u0000\u0000\u0000O;\u0001\u0000\u0000\u0000O<\u0001"+
"\u0000\u0000\u0000O>\u0001\u0000\u0000\u0000O@\u0001\u0000\u0000\u0000"+
"OD\u0001\u0000\u0000\u0000OH\u0001\u0000\u0000\u0000OJ\u0001\u0000\u0000"+
"\u0000OL\u0001\u0000\u0000\u0000ON\u0001\u0000\u0000\u0000P\u0003\u0001"+
"\u0000\u0000\u0000\u0003\u00077O";
public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static {
_decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
_decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
}
}
}
|