add 1 not ok, dont come back with result

This commit is contained in:
Vu Tuan Minh
2025-04-01 21:13:01 +02:00
parent 40e2bc5522
commit 52a5c00f74
12 changed files with 387 additions and 242 deletions

File diff suppressed because one or more lines are too long

View File

@@ -1,4 +1,4 @@
// Generated from c:/Users/Thibaut/Documents/Git/PDS/tp2-vsl-pds/src/main/antlr/VSLLexer.g by ANTLR 4.13.1
// Generated from /home/tuanvu/Desktop/M1/S8/PDS/tp2-vsl-pds/src/main/antlr/VSLLexer.g by ANTLR 4.13.1
package TP2;
@@ -22,7 +22,7 @@ public class VSLLexer extends Lexer {
FUNCTION=1, PROTOTYPE=2, TYPE_INT=3, TYPE_VOID=4, LE=5, LT=6, GE=7, GT=8,
IF=9, THEN=10, ELSE=11, FIN=12, WHILE=13, DO=14, DONE=15, READ=16, PRINT=17,
RETURN=18, TEXT=19, NUMBER=20, ParO=21, ParF=22, PLUS=23, MINUS=24, DIV=25,
TIMES=26, WS=27, COMMENT=28;
TIMES=26, MOD=27, IDENT=28, WS=29, COMMENT=30;
public static String[] channelNames = {
"DEFAULT_TOKEN_CHANNEL", "HIDDEN"
};
@@ -36,7 +36,7 @@ public class VSLLexer extends Lexer {
"FUNCTION", "PROTOTYPE", "TYPE_INT", "TYPE_VOID", "LE", "LT", "GE", "GT",
"IF", "THEN", "ELSE", "FIN", "WHILE", "DO", "DONE", "READ", "PRINT",
"RETURN", "TEXT", "NUMBER", "ParO", "ParF", "PLUS", "MINUS", "DIV", "TIMES",
"WS", "COMMENT", "LETTER", "DIGIT", "ASCII"
"MOD", "IDENT", "WS", "COMMENT", "LETTER", "DIGIT", "ASCII"
};
}
public static final String[] ruleNames = makeRuleNames();
@@ -46,7 +46,7 @@ public class VSLLexer extends Lexer {
null, "'FUNC'", "'PROTO'", "'INT'", "'VOID'", "'<='", "'<'", "'>='",
"'>'", "'IF'", "'THEN'", "'ELSE'", "'FI'", "'WHILE'", "'DO'", "'DONE'",
"'READ'", "'PRINT'", "'RETURN'", null, null, "'('", "')'", "'+'", "'-'",
"'/'", "'*'"
"'/'", "'*'", "'%'"
};
}
private static final String[] _LITERAL_NAMES = makeLiteralNames();
@@ -55,7 +55,7 @@ public class VSLLexer extends Lexer {
null, "FUNCTION", "PROTOTYPE", "TYPE_INT", "TYPE_VOID", "LE", "LT", "GE",
"GT", "IF", "THEN", "ELSE", "FIN", "WHILE", "DO", "DONE", "READ", "PRINT",
"RETURN", "TEXT", "NUMBER", "ParO", "ParF", "PLUS", "MINUS", "DIV", "TIMES",
"WS", "COMMENT"
"MOD", "IDENT", "WS", "COMMENT"
};
}
private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames();
@@ -119,41 +119,31 @@ public class VSLLexer extends Lexer {
@Override
public void action(RuleContext _localctx, int ruleIndex, int actionIndex) {
switch (ruleIndex) {
case 18:
TEXT_action((RuleContext)_localctx, actionIndex);
break;
case 26:
case 28:
WS_action((RuleContext)_localctx, actionIndex);
break;
case 27:
case 29:
COMMENT_action((RuleContext)_localctx, actionIndex);
break;
}
}
private void TEXT_action(RuleContext _localctx, int actionIndex) {
switch (actionIndex) {
case 0:
getText().substring(1,getText().length()-1);
break;
}
}
private void WS_action(RuleContext _localctx, int actionIndex) {
switch (actionIndex) {
case 1:
case 0:
skip();
break;
}
}
private void COMMENT_action(RuleContext _localctx, int actionIndex) {
switch (actionIndex) {
case 2:
case 1:
skip();
break;
}
}
public static final String _serializedATN =
"\u0004\u0000\u001c\u00bb\u0006\uffff\uffff\u0002\u0000\u0007\u0000\u0002"+
"\u0004\u0000\u001e\u00c7\u0006\uffff\uffff\u0002\u0000\u0007\u0000\u0002"+
"\u0001\u0007\u0001\u0002\u0002\u0007\u0002\u0002\u0003\u0007\u0003\u0002"+
"\u0004\u0007\u0004\u0002\u0005\u0007\u0005\u0002\u0006\u0007\u0006\u0002"+
"\u0007\u0007\u0007\u0002\b\u0007\b\u0002\t\u0007\t\u0002\n\u0007\n\u0002"+
@@ -163,108 +153,117 @@ public class VSLLexer extends Lexer {
"\u0002\u0015\u0007\u0015\u0002\u0016\u0007\u0016\u0002\u0017\u0007\u0017"+
"\u0002\u0018\u0007\u0018\u0002\u0019\u0007\u0019\u0002\u001a\u0007\u001a"+
"\u0002\u001b\u0007\u001b\u0002\u001c\u0007\u001c\u0002\u001d\u0007\u001d"+
"\u0002\u001e\u0007\u001e\u0001\u0000\u0001\u0000\u0001\u0000\u0001\u0000"+
"\u0001\u0000\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001"+
"\u0001\u0001\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0003"+
"\u0001\u0003\u0001\u0003\u0001\u0003\u0001\u0003\u0001\u0004\u0001\u0004"+
"\u0001\u0004\u0001\u0005\u0001\u0005\u0001\u0006\u0001\u0006\u0001\u0006"+
"\u0001\u0007\u0001\u0007\u0001\b\u0001\b\u0001\b\u0001\t\u0001\t\u0001"+
"\t\u0001\t\u0001\t\u0001\n\u0001\n\u0001\n\u0001\n\u0001\n\u0001\u000b"+
"\u0001\u000b\u0001\u000b\u0001\f\u0001\f\u0001\f\u0001\f\u0001\f\u0001"+
"\f\u0001\r\u0001\r\u0001\r\u0001\u000e\u0001\u000e\u0001\u000e\u0001\u000e"+
"\u0001\u000e\u0001\u000f\u0001\u000f\u0001\u000f\u0001\u000f\u0001\u000f"+
"\u0001\u0010\u0001\u0010\u0001\u0010\u0001\u0010\u0001\u0010\u0001\u0010"+
"\u0001\u0011\u0001\u0011\u0001\u0011\u0001\u0011\u0001\u0011\u0001\u0011"+
"\u0001\u0011\u0001\u0012\u0001\u0012\u0004\u0012\u0090\b\u0012\u000b\u0012"+
"\f\u0012\u0091\u0001\u0012\u0001\u0012\u0001\u0012\u0001\u0013\u0004\u0013"+
"\u0098\b\u0013\u000b\u0013\f\u0013\u0099\u0001\u0014\u0001\u0014\u0001"+
"\u0015\u0001\u0015\u0001\u0016\u0001\u0016\u0001\u0017\u0001\u0017\u0001"+
"\u0018\u0001\u0018\u0001\u0019\u0001\u0019\u0001\u001a\u0001\u001a\u0001"+
"\u001a\u0001\u001b\u0001\u001b\u0001\u001b\u0001\u001b\u0005\u001b\u00af"+
"\b\u001b\n\u001b\f\u001b\u00b2\t\u001b\u0001\u001b\u0001\u001b\u0001\u001c"+
"\u0001\u001c\u0001\u001d\u0001\u001d\u0001\u001e\u0001\u001e\u0000\u0000"+
"\u001f\u0001\u0001\u0003\u0002\u0005\u0003\u0007\u0004\t\u0005\u000b\u0006"+
"\r\u0007\u000f\b\u0011\t\u0013\n\u0015\u000b\u0017\f\u0019\r\u001b\u000e"+
"\u001d\u000f\u001f\u0010!\u0011#\u0012%\u0013\'\u0014)\u0015+\u0016-\u0017"+
"/\u00181\u00193\u001a5\u001b7\u001c9\u0000;\u0000=\u0000\u0001\u0000\u0003"+
"\u0002\u0000\t\n \u0001\u0000\n\n\u0002\u0000\n\n\"\"\u00ba\u0000\u0001"+
"\u0001\u0000\u0000\u0000\u0000\u0003\u0001\u0000\u0000\u0000\u0000\u0005"+
"\u0001\u0000\u0000\u0000\u0000\u0007\u0001\u0000\u0000\u0000\u0000\t\u0001"+
"\u0000\u0000\u0000\u0000\u000b\u0001\u0000\u0000\u0000\u0000\r\u0001\u0000"+
"\u0000\u0000\u0000\u000f\u0001\u0000\u0000\u0000\u0000\u0011\u0001\u0000"+
"\u0000\u0000\u0000\u0013\u0001\u0000\u0000\u0000\u0000\u0015\u0001\u0000"+
"\u0000\u0000\u0000\u0017\u0001\u0000\u0000\u0000\u0000\u0019\u0001\u0000"+
"\u0000\u0000\u0000\u001b\u0001\u0000\u0000\u0000\u0000\u001d\u0001\u0000"+
"\u0000\u0000\u0000\u001f\u0001\u0000\u0000\u0000\u0000!\u0001\u0000\u0000"+
"\u0000\u0000#\u0001\u0000\u0000\u0000\u0000%\u0001\u0000\u0000\u0000\u0000"+
"\'\u0001\u0000\u0000\u0000\u0000)\u0001\u0000\u0000\u0000\u0000+\u0001"+
"\u0000\u0000\u0000\u0000-\u0001\u0000\u0000\u0000\u0000/\u0001\u0000\u0000"+
"\u0000\u00001\u0001\u0000\u0000\u0000\u00003\u0001\u0000\u0000\u0000\u0000"+
"5\u0001\u0000\u0000\u0000\u00007\u0001\u0000\u0000\u0000\u0001?\u0001"+
"\u0000\u0000\u0000\u0003D\u0001\u0000\u0000\u0000\u0005J\u0001\u0000\u0000"+
"\u0000\u0007N\u0001\u0000\u0000\u0000\tS\u0001\u0000\u0000\u0000\u000b"+
"V\u0001\u0000\u0000\u0000\rX\u0001\u0000\u0000\u0000\u000f[\u0001\u0000"+
"\u0000\u0000\u0011]\u0001\u0000\u0000\u0000\u0013`\u0001\u0000\u0000\u0000"+
"\u0015e\u0001\u0000\u0000\u0000\u0017j\u0001\u0000\u0000\u0000\u0019m"+
"\u0001\u0000\u0000\u0000\u001bs\u0001\u0000\u0000\u0000\u001dv\u0001\u0000"+
"\u0000\u0000\u001f{\u0001\u0000\u0000\u0000!\u0080\u0001\u0000\u0000\u0000"+
"#\u0086\u0001\u0000\u0000\u0000%\u008d\u0001\u0000\u0000\u0000\'\u0097"+
"\u0001\u0000\u0000\u0000)\u009b\u0001\u0000\u0000\u0000+\u009d\u0001\u0000"+
"\u0000\u0000-\u009f\u0001\u0000\u0000\u0000/\u00a1\u0001\u0000\u0000\u0000"+
"1\u00a3\u0001\u0000\u0000\u00003\u00a5\u0001\u0000\u0000\u00005\u00a7"+
"\u0001\u0000\u0000\u00007\u00aa\u0001\u0000\u0000\u00009\u00b5\u0001\u0000"+
"\u0000\u0000;\u00b7\u0001\u0000\u0000\u0000=\u00b9\u0001\u0000\u0000\u0000"+
"?@\u0005F\u0000\u0000@A\u0005U\u0000\u0000AB\u0005N\u0000\u0000BC\u0005"+
"C\u0000\u0000C\u0002\u0001\u0000\u0000\u0000DE\u0005P\u0000\u0000EF\u0005"+
"R\u0000\u0000FG\u0005O\u0000\u0000GH\u0005T\u0000\u0000HI\u0005O\u0000"+
"\u0000I\u0004\u0001\u0000\u0000\u0000JK\u0005I\u0000\u0000KL\u0005N\u0000"+
"\u0000LM\u0005T\u0000\u0000M\u0006\u0001\u0000\u0000\u0000NO\u0005V\u0000"+
"\u0000OP\u0005O\u0000\u0000PQ\u0005I\u0000\u0000QR\u0005D\u0000\u0000"+
"R\b\u0001\u0000\u0000\u0000ST\u0005<\u0000\u0000TU\u0005=\u0000\u0000"+
"U\n\u0001\u0000\u0000\u0000VW\u0005<\u0000\u0000W\f\u0001\u0000\u0000"+
"\u0000XY\u0005>\u0000\u0000YZ\u0005=\u0000\u0000Z\u000e\u0001\u0000\u0000"+
"\u0000[\\\u0005>\u0000\u0000\\\u0010\u0001\u0000\u0000\u0000]^\u0005I"+
"\u0000\u0000^_\u0005F\u0000\u0000_\u0012\u0001\u0000\u0000\u0000`a\u0005"+
"T\u0000\u0000ab\u0005H\u0000\u0000bc\u0005E\u0000\u0000cd\u0005N\u0000"+
"\u0000d\u0014\u0001\u0000\u0000\u0000ef\u0005E\u0000\u0000fg\u0005L\u0000"+
"\u0000gh\u0005S\u0000\u0000hi\u0005E\u0000\u0000i\u0016\u0001\u0000\u0000"+
"\u0000jk\u0005F\u0000\u0000kl\u0005I\u0000\u0000l\u0018\u0001\u0000\u0000"+
"\u0000mn\u0005W\u0000\u0000no\u0005H\u0000\u0000op\u0005I\u0000\u0000"+
"pq\u0005L\u0000\u0000qr\u0005E\u0000\u0000r\u001a\u0001\u0000\u0000\u0000"+
"st\u0005D\u0000\u0000tu\u0005O\u0000\u0000u\u001c\u0001\u0000\u0000\u0000"+
"vw\u0005D\u0000\u0000wx\u0005O\u0000\u0000xy\u0005N\u0000\u0000yz\u0005"+
"E\u0000\u0000z\u001e\u0001\u0000\u0000\u0000{|\u0005R\u0000\u0000|}\u0005"+
"E\u0000\u0000}~\u0005A\u0000\u0000~\u007f\u0005D\u0000\u0000\u007f \u0001"+
"\u0000\u0000\u0000\u0080\u0081\u0005P\u0000\u0000\u0081\u0082\u0005R\u0000"+
"\u0000\u0082\u0083\u0005I\u0000\u0000\u0083\u0084\u0005N\u0000\u0000\u0084"+
"\u0085\u0005T\u0000\u0000\u0085\"\u0001\u0000\u0000\u0000\u0086\u0087"+
"\u0005R\u0000\u0000\u0087\u0088\u0005E\u0000\u0000\u0088\u0089\u0005T"+
"\u0000\u0000\u0089\u008a\u0005U\u0000\u0000\u008a\u008b\u0005R\u0000\u0000"+
"\u008b\u008c\u0005N\u0000\u0000\u008c$\u0001\u0000\u0000\u0000\u008d\u008f"+
"\u0005\"\u0000\u0000\u008e\u0090\u0003=\u001e\u0000\u008f\u008e\u0001"+
"\u0000\u0000\u0000\u0090\u0091\u0001\u0000\u0000\u0000\u0091\u008f\u0001"+
"\u0000\u0000\u0000\u0091\u0092\u0001\u0000\u0000\u0000\u0092\u0093\u0001"+
"\u0000\u0000\u0000\u0093\u0094\u0005\"\u0000\u0000\u0094\u0095\u0006\u0012"+
"\u0000\u0000\u0095&\u0001\u0000\u0000\u0000\u0096\u0098\u0003;\u001d\u0000"+
"\u0097\u0096\u0001\u0000\u0000\u0000\u0098\u0099\u0001\u0000\u0000\u0000"+
"\u0099\u0097\u0001\u0000\u0000\u0000\u0099\u009a\u0001\u0000\u0000\u0000"+
"\u009a(\u0001\u0000\u0000\u0000\u009b\u009c\u0005(\u0000\u0000\u009c*"+
"\u0001\u0000\u0000\u0000\u009d\u009e\u0005)\u0000\u0000\u009e,\u0001\u0000"+
"\u0000\u0000\u009f\u00a0\u0005+\u0000\u0000\u00a0.\u0001\u0000\u0000\u0000"+
"\u00a1\u00a2\u0005-\u0000\u0000\u00a20\u0001\u0000\u0000\u0000\u00a3\u00a4"+
"\u0005/\u0000\u0000\u00a42\u0001\u0000\u0000\u0000\u00a5\u00a6\u0005*"+
"\u0000\u0000\u00a64\u0001\u0000\u0000\u0000\u00a7\u00a8\u0007\u0000\u0000"+
"\u0000\u00a8\u00a9\u0006\u001a\u0001\u0000\u00a96\u0001\u0000\u0000\u0000"+
"\u00aa\u00ab\u0005/\u0000\u0000\u00ab\u00ac\u0005/\u0000\u0000\u00ac\u00b0"+
"\u0001\u0000\u0000\u0000\u00ad\u00af\b\u0001\u0000\u0000\u00ae\u00ad\u0001"+
"\u0000\u0000\u0000\u00af\u00b2\u0001\u0000\u0000\u0000\u00b0\u00ae\u0001"+
"\u0000\u0000\u0000\u00b0\u00b1\u0001\u0000\u0000\u0000\u00b1\u00b3\u0001"+
"\u0000\u0000\u0000\u00b2\u00b0\u0001\u0000\u0000\u0000\u00b3\u00b4\u0006"+
"\u001b\u0002\u0000\u00b48\u0001\u0000\u0000\u0000\u00b5\u00b6\u0002az"+
"\u0000\u00b6:\u0001\u0000\u0000\u0000\u00b7\u00b8\u000209\u0000\u00b8"+
"<\u0001\u0000\u0000\u0000\u00b9\u00ba\b\u0002\u0000\u0000\u00ba>\u0001"+
"\u0000\u0000\u0000\u0004\u0000\u0091\u0099\u00b0\u0003\u0001\u0012\u0000"+
"\u0001\u001a\u0001\u0001\u001b\u0002";
"\u0002\u001e\u0007\u001e\u0002\u001f\u0007\u001f\u0002 \u0007 \u0001\u0000"+
"\u0001\u0000\u0001\u0000\u0001\u0000\u0001\u0000\u0001\u0001\u0001\u0001"+
"\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0002\u0001\u0002"+
"\u0001\u0002\u0001\u0002\u0001\u0003\u0001\u0003\u0001\u0003\u0001\u0003"+
"\u0001\u0003\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0005\u0001\u0005"+
"\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0007\u0001\u0007\u0001\b\u0001"+
"\b\u0001\b\u0001\t\u0001\t\u0001\t\u0001\t\u0001\t\u0001\n\u0001\n\u0001"+
"\n\u0001\n\u0001\n\u0001\u000b\u0001\u000b\u0001\u000b\u0001\f\u0001\f"+
"\u0001\f\u0001\f\u0001\f\u0001\f\u0001\r\u0001\r\u0001\r\u0001\u000e\u0001"+
"\u000e\u0001\u000e\u0001\u000e\u0001\u000e\u0001\u000f\u0001\u000f\u0001"+
"\u000f\u0001\u000f\u0001\u000f\u0001\u0010\u0001\u0010\u0001\u0010\u0001"+
"\u0010\u0001\u0010\u0001\u0010\u0001\u0011\u0001\u0011\u0001\u0011\u0001"+
"\u0011\u0001\u0011\u0001\u0011\u0001\u0011\u0001\u0012\u0001\u0012\u0004"+
"\u0012\u0094\b\u0012\u000b\u0012\f\u0012\u0095\u0001\u0012\u0001\u0012"+
"\u0001\u0013\u0004\u0013\u009b\b\u0013\u000b\u0013\f\u0013\u009c\u0001"+
"\u0014\u0001\u0014\u0001\u0015\u0001\u0015\u0001\u0016\u0001\u0016\u0001"+
"\u0017\u0001\u0017\u0001\u0018\u0001\u0018\u0001\u0019\u0001\u0019\u0001"+
"\u001a\u0001\u001a\u0001\u001b\u0001\u001b\u0005\u001b\u00af\b\u001b\n"+
"\u001b\f\u001b\u00b2\t\u001b\u0001\u001c\u0001\u001c\u0001\u001c\u0001"+
"\u001d\u0001\u001d\u0001\u001d\u0001\u001d\u0005\u001d\u00bb\b\u001d\n"+
"\u001d\f\u001d\u00be\t\u001d\u0001\u001d\u0001\u001d\u0001\u001e\u0001"+
"\u001e\u0001\u001f\u0001\u001f\u0001 \u0001 \u0000\u0000!\u0001\u0001"+
"\u0003\u0002\u0005\u0003\u0007\u0004\t\u0005\u000b\u0006\r\u0007\u000f"+
"\b\u0011\t\u0013\n\u0015\u000b\u0017\f\u0019\r\u001b\u000e\u001d\u000f"+
"\u001f\u0010!\u0011#\u0012%\u0013\'\u0014)\u0015+\u0016-\u0017/\u0018"+
"1\u00193\u001a5\u001b7\u001c9\u001d;\u001e=\u0000?\u0000A\u0000\u0001"+
"\u0000\u0005\u0002\u0000AZaz\u0005\u0000--09AZ__az\u0002\u0000\t\n \u0001"+
"\u0000\n\n\u0002\u0000\n\n\"\"\u00c7\u0000\u0001\u0001\u0000\u0000\u0000"+
"\u0000\u0003\u0001\u0000\u0000\u0000\u0000\u0005\u0001\u0000\u0000\u0000"+
"\u0000\u0007\u0001\u0000\u0000\u0000\u0000\t\u0001\u0000\u0000\u0000\u0000"+
"\u000b\u0001\u0000\u0000\u0000\u0000\r\u0001\u0000\u0000\u0000\u0000\u000f"+
"\u0001\u0000\u0000\u0000\u0000\u0011\u0001\u0000\u0000\u0000\u0000\u0013"+
"\u0001\u0000\u0000\u0000\u0000\u0015\u0001\u0000\u0000\u0000\u0000\u0017"+
"\u0001\u0000\u0000\u0000\u0000\u0019\u0001\u0000\u0000\u0000\u0000\u001b"+
"\u0001\u0000\u0000\u0000\u0000\u001d\u0001\u0000\u0000\u0000\u0000\u001f"+
"\u0001\u0000\u0000\u0000\u0000!\u0001\u0000\u0000\u0000\u0000#\u0001\u0000"+
"\u0000\u0000\u0000%\u0001\u0000\u0000\u0000\u0000\'\u0001\u0000\u0000"+
"\u0000\u0000)\u0001\u0000\u0000\u0000\u0000+\u0001\u0000\u0000\u0000\u0000"+
"-\u0001\u0000\u0000\u0000\u0000/\u0001\u0000\u0000\u0000\u00001\u0001"+
"\u0000\u0000\u0000\u00003\u0001\u0000\u0000\u0000\u00005\u0001\u0000\u0000"+
"\u0000\u00007\u0001\u0000\u0000\u0000\u00009\u0001\u0000\u0000\u0000\u0000"+
";\u0001\u0000\u0000\u0000\u0001C\u0001\u0000\u0000\u0000\u0003H\u0001"+
"\u0000\u0000\u0000\u0005N\u0001\u0000\u0000\u0000\u0007R\u0001\u0000\u0000"+
"\u0000\tW\u0001\u0000\u0000\u0000\u000bZ\u0001\u0000\u0000\u0000\r\\\u0001"+
"\u0000\u0000\u0000\u000f_\u0001\u0000\u0000\u0000\u0011a\u0001\u0000\u0000"+
"\u0000\u0013d\u0001\u0000\u0000\u0000\u0015i\u0001\u0000\u0000\u0000\u0017"+
"n\u0001\u0000\u0000\u0000\u0019q\u0001\u0000\u0000\u0000\u001bw\u0001"+
"\u0000\u0000\u0000\u001dz\u0001\u0000\u0000\u0000\u001f\u007f\u0001\u0000"+
"\u0000\u0000!\u0084\u0001\u0000\u0000\u0000#\u008a\u0001\u0000\u0000\u0000"+
"%\u0091\u0001\u0000\u0000\u0000\'\u009a\u0001\u0000\u0000\u0000)\u009e"+
"\u0001\u0000\u0000\u0000+\u00a0\u0001\u0000\u0000\u0000-\u00a2\u0001\u0000"+
"\u0000\u0000/\u00a4\u0001\u0000\u0000\u00001\u00a6\u0001\u0000\u0000\u0000"+
"3\u00a8\u0001\u0000\u0000\u00005\u00aa\u0001\u0000\u0000\u00007\u00ac"+
"\u0001\u0000\u0000\u00009\u00b3\u0001\u0000\u0000\u0000;\u00b6\u0001\u0000"+
"\u0000\u0000=\u00c1\u0001\u0000\u0000\u0000?\u00c3\u0001\u0000\u0000\u0000"+
"A\u00c5\u0001\u0000\u0000\u0000CD\u0005F\u0000\u0000DE\u0005U\u0000\u0000"+
"EF\u0005N\u0000\u0000FG\u0005C\u0000\u0000G\u0002\u0001\u0000\u0000\u0000"+
"HI\u0005P\u0000\u0000IJ\u0005R\u0000\u0000JK\u0005O\u0000\u0000KL\u0005"+
"T\u0000\u0000LM\u0005O\u0000\u0000M\u0004\u0001\u0000\u0000\u0000NO\u0005"+
"I\u0000\u0000OP\u0005N\u0000\u0000PQ\u0005T\u0000\u0000Q\u0006\u0001\u0000"+
"\u0000\u0000RS\u0005V\u0000\u0000ST\u0005O\u0000\u0000TU\u0005I\u0000"+
"\u0000UV\u0005D\u0000\u0000V\b\u0001\u0000\u0000\u0000WX\u0005<\u0000"+
"\u0000XY\u0005=\u0000\u0000Y\n\u0001\u0000\u0000\u0000Z[\u0005<\u0000"+
"\u0000[\f\u0001\u0000\u0000\u0000\\]\u0005>\u0000\u0000]^\u0005=\u0000"+
"\u0000^\u000e\u0001\u0000\u0000\u0000_`\u0005>\u0000\u0000`\u0010\u0001"+
"\u0000\u0000\u0000ab\u0005I\u0000\u0000bc\u0005F\u0000\u0000c\u0012\u0001"+
"\u0000\u0000\u0000de\u0005T\u0000\u0000ef\u0005H\u0000\u0000fg\u0005E"+
"\u0000\u0000gh\u0005N\u0000\u0000h\u0014\u0001\u0000\u0000\u0000ij\u0005"+
"E\u0000\u0000jk\u0005L\u0000\u0000kl\u0005S\u0000\u0000lm\u0005E\u0000"+
"\u0000m\u0016\u0001\u0000\u0000\u0000no\u0005F\u0000\u0000op\u0005I\u0000"+
"\u0000p\u0018\u0001\u0000\u0000\u0000qr\u0005W\u0000\u0000rs\u0005H\u0000"+
"\u0000st\u0005I\u0000\u0000tu\u0005L\u0000\u0000uv\u0005E\u0000\u0000"+
"v\u001a\u0001\u0000\u0000\u0000wx\u0005D\u0000\u0000xy\u0005O\u0000\u0000"+
"y\u001c\u0001\u0000\u0000\u0000z{\u0005D\u0000\u0000{|\u0005O\u0000\u0000"+
"|}\u0005N\u0000\u0000}~\u0005E\u0000\u0000~\u001e\u0001\u0000\u0000\u0000"+
"\u007f\u0080\u0005R\u0000\u0000\u0080\u0081\u0005E\u0000\u0000\u0081\u0082"+
"\u0005A\u0000\u0000\u0082\u0083\u0005D\u0000\u0000\u0083 \u0001\u0000"+
"\u0000\u0000\u0084\u0085\u0005P\u0000\u0000\u0085\u0086\u0005R\u0000\u0000"+
"\u0086\u0087\u0005I\u0000\u0000\u0087\u0088\u0005N\u0000\u0000\u0088\u0089"+
"\u0005T\u0000\u0000\u0089\"\u0001\u0000\u0000\u0000\u008a\u008b\u0005"+
"R\u0000\u0000\u008b\u008c\u0005E\u0000\u0000\u008c\u008d\u0005T\u0000"+
"\u0000\u008d\u008e\u0005U\u0000\u0000\u008e\u008f\u0005R\u0000\u0000\u008f"+
"\u0090\u0005N\u0000\u0000\u0090$\u0001\u0000\u0000\u0000\u0091\u0093\u0005"+
"\"\u0000\u0000\u0092\u0094\u0003A \u0000\u0093\u0092\u0001\u0000\u0000"+
"\u0000\u0094\u0095\u0001\u0000\u0000\u0000\u0095\u0093\u0001\u0000\u0000"+
"\u0000\u0095\u0096\u0001\u0000\u0000\u0000\u0096\u0097\u0001\u0000\u0000"+
"\u0000\u0097\u0098\u0005\"\u0000\u0000\u0098&\u0001\u0000\u0000\u0000"+
"\u0099\u009b\u0003?\u001f\u0000\u009a\u0099\u0001\u0000\u0000\u0000\u009b"+
"\u009c\u0001\u0000\u0000\u0000\u009c\u009a\u0001\u0000\u0000\u0000\u009c"+
"\u009d\u0001\u0000\u0000\u0000\u009d(\u0001\u0000\u0000\u0000\u009e\u009f"+
"\u0005(\u0000\u0000\u009f*\u0001\u0000\u0000\u0000\u00a0\u00a1\u0005)"+
"\u0000\u0000\u00a1,\u0001\u0000\u0000\u0000\u00a2\u00a3\u0005+\u0000\u0000"+
"\u00a3.\u0001\u0000\u0000\u0000\u00a4\u00a5\u0005-\u0000\u0000\u00a50"+
"\u0001\u0000\u0000\u0000\u00a6\u00a7\u0005/\u0000\u0000\u00a72\u0001\u0000"+
"\u0000\u0000\u00a8\u00a9\u0005*\u0000\u0000\u00a94\u0001\u0000\u0000\u0000"+
"\u00aa\u00ab\u0005%\u0000\u0000\u00ab6\u0001\u0000\u0000\u0000\u00ac\u00b0"+
"\u0007\u0000\u0000\u0000\u00ad\u00af\u0007\u0001\u0000\u0000\u00ae\u00ad"+
"\u0001\u0000\u0000\u0000\u00af\u00b2\u0001\u0000\u0000\u0000\u00b0\u00ae"+
"\u0001\u0000\u0000\u0000\u00b0\u00b1\u0001\u0000\u0000\u0000\u00b18\u0001"+
"\u0000\u0000\u0000\u00b2\u00b0\u0001\u0000\u0000\u0000\u00b3\u00b4\u0007"+
"\u0002\u0000\u0000\u00b4\u00b5\u0006\u001c\u0000\u0000\u00b5:\u0001\u0000"+
"\u0000\u0000\u00b6\u00b7\u0005/\u0000\u0000\u00b7\u00b8\u0005/\u0000\u0000"+
"\u00b8\u00bc\u0001\u0000\u0000\u0000\u00b9\u00bb\b\u0003\u0000\u0000\u00ba"+
"\u00b9\u0001\u0000\u0000\u0000\u00bb\u00be\u0001\u0000\u0000\u0000\u00bc"+
"\u00ba\u0001\u0000\u0000\u0000\u00bc\u00bd\u0001\u0000\u0000\u0000\u00bd"+
"\u00bf\u0001\u0000\u0000\u0000\u00be\u00bc\u0001\u0000\u0000\u0000\u00bf"+
"\u00c0\u0006\u001d\u0001\u0000\u00c0<\u0001\u0000\u0000\u0000\u00c1\u00c2"+
"\u0002az\u0000\u00c2>\u0001\u0000\u0000\u0000\u00c3\u00c4\u000209\u0000"+
"\u00c4@\u0001\u0000\u0000\u0000\u00c5\u00c6\b\u0004\u0000\u0000\u00c6"+
"B\u0001\u0000\u0000\u0000\u0005\u0000\u0095\u009c\u00b0\u00bc\u0002\u0001"+
"\u001c\u0000\u0001\u001d\u0001";
public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static {

View File

@@ -24,8 +24,10 @@ PLUS=23
MINUS=24
DIV=25
TIMES=26
WS=27
COMMENT=28
MOD=27
IDENT=28
WS=29
COMMENT=30
'FUNC'=1
'PROTO'=2
'INT'=3
@@ -50,3 +52,4 @@ COMMENT=28
'-'=24
'/'=25
'*'=26
'%'=27

View File

@@ -26,6 +26,8 @@ null
'-'
'/'
'*'
'%'
null
null
null
@@ -57,6 +59,8 @@ PLUS
MINUS
DIV
TIMES
MOD
IDENT
WS
COMMENT
@@ -74,4 +78,4 @@ type
atn:
[4, 1, 28, 76, 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, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 3, 1, 4, 1, 4, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 5, 5, 48, 8, 5, 10, 5, 12, 5, 51, 9, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 5, 6, 59, 8, 6, 10, 6, 12, 6, 62, 9, 6, 1, 7, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 9, 1, 9, 3, 9, 74, 8, 9, 1, 9, 0, 0, 10, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 0, 2, 1, 0, 23, 24, 1, 0, 25, 26, 68, 0, 20, 1, 0, 0, 0, 2, 24, 1, 0, 0, 0, 4, 32, 1, 0, 0, 0, 6, 34, 1, 0, 0, 0, 8, 37, 1, 0, 0, 0, 10, 41, 1, 0, 0, 0, 12, 52, 1, 0, 0, 0, 14, 63, 1, 0, 0, 0, 16, 66, 1, 0, 0, 0, 18, 73, 1, 0, 0, 0, 20, 21, 3, 2, 1, 0, 21, 22, 5, 0, 0, 1, 22, 23, 6, 0, -1, 0, 23, 1, 1, 0, 0, 0, 24, 25, 5, 1, 0, 0, 25, 26, 3, 18, 9, 0, 26, 27, 3, 16, 8, 0, 27, 28, 5, 21, 0, 0, 28, 29, 5, 22, 0, 0, 29, 30, 3, 6, 3, 0, 30, 31, 6, 1, -1, 0, 31, 3, 1, 0, 0, 0, 32, 33, 1, 0, 0, 0, 33, 5, 1, 0, 0, 0, 34, 35, 3, 8, 4, 0, 35, 36, 6, 3, -1, 0, 36, 7, 1, 0, 0, 0, 37, 38, 5, 18, 0, 0, 38, 39, 3, 10, 5, 0, 39, 40, 6, 4, -1, 0, 40, 9, 1, 0, 0, 0, 41, 42, 3, 12, 6, 0, 42, 49, 6, 5, -1, 0, 43, 44, 7, 0, 0, 0, 44, 45, 3, 12, 6, 0, 45, 46, 6, 5, -1, 0, 46, 48, 1, 0, 0, 0, 47, 43, 1, 0, 0, 0, 48, 51, 1, 0, 0, 0, 49, 47, 1, 0, 0, 0, 49, 50, 1, 0, 0, 0, 50, 11, 1, 0, 0, 0, 51, 49, 1, 0, 0, 0, 52, 53, 3, 14, 7, 0, 53, 60, 6, 6, -1, 0, 54, 55, 7, 1, 0, 0, 55, 56, 3, 14, 7, 0, 56, 57, 6, 6, -1, 0, 57, 59, 1, 0, 0, 0, 58, 54, 1, 0, 0, 0, 59, 62, 1, 0, 0, 0, 60, 58, 1, 0, 0, 0, 60, 61, 1, 0, 0, 0, 61, 13, 1, 0, 0, 0, 62, 60, 1, 0, 0, 0, 63, 64, 5, 20, 0, 0, 64, 65, 6, 7, -1, 0, 65, 15, 1, 0, 0, 0, 66, 67, 5, 19, 0, 0, 67, 68, 6, 8, -1, 0, 68, 17, 1, 0, 0, 0, 69, 70, 5, 3, 0, 0, 70, 74, 6, 9, -1, 0, 71, 72, 5, 4, 0, 0, 72, 74, 6, 9, -1, 0, 73, 69, 1, 0, 0, 0, 73, 71, 1, 0, 0, 0, 74, 19, 1, 0, 0, 0, 3, 49, 60, 73]
[4, 1, 30, 80, 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, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 3, 4, 3, 38, 8, 3, 11, 3, 12, 3, 39, 1, 4, 1, 4, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 5, 5, 52, 8, 5, 10, 5, 12, 5, 55, 9, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 5, 6, 63, 8, 6, 10, 6, 12, 6, 66, 9, 6, 1, 7, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 9, 1, 9, 3, 9, 78, 8, 9, 1, 9, 0, 0, 10, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 0, 2, 1, 0, 23, 24, 1, 0, 25, 26, 73, 0, 20, 1, 0, 0, 0, 2, 24, 1, 0, 0, 0, 4, 32, 1, 0, 0, 0, 6, 37, 1, 0, 0, 0, 8, 41, 1, 0, 0, 0, 10, 45, 1, 0, 0, 0, 12, 56, 1, 0, 0, 0, 14, 67, 1, 0, 0, 0, 16, 70, 1, 0, 0, 0, 18, 77, 1, 0, 0, 0, 20, 21, 3, 2, 1, 0, 21, 22, 5, 0, 0, 1, 22, 23, 6, 0, -1, 0, 23, 1, 1, 0, 0, 0, 24, 25, 5, 1, 0, 0, 25, 26, 3, 18, 9, 0, 26, 27, 3, 16, 8, 0, 27, 28, 5, 21, 0, 0, 28, 29, 5, 22, 0, 0, 29, 30, 3, 6, 3, 0, 30, 31, 6, 1, -1, 0, 31, 3, 1, 0, 0, 0, 32, 33, 1, 0, 0, 0, 33, 5, 1, 0, 0, 0, 34, 35, 3, 8, 4, 0, 35, 36, 6, 3, -1, 0, 36, 38, 1, 0, 0, 0, 37, 34, 1, 0, 0, 0, 38, 39, 1, 0, 0, 0, 39, 37, 1, 0, 0, 0, 39, 40, 1, 0, 0, 0, 40, 7, 1, 0, 0, 0, 41, 42, 5, 18, 0, 0, 42, 43, 3, 10, 5, 0, 43, 44, 6, 4, -1, 0, 44, 9, 1, 0, 0, 0, 45, 46, 3, 12, 6, 0, 46, 53, 6, 5, -1, 0, 47, 48, 7, 0, 0, 0, 48, 49, 3, 12, 6, 0, 49, 50, 6, 5, -1, 0, 50, 52, 1, 0, 0, 0, 51, 47, 1, 0, 0, 0, 52, 55, 1, 0, 0, 0, 53, 51, 1, 0, 0, 0, 53, 54, 1, 0, 0, 0, 54, 11, 1, 0, 0, 0, 55, 53, 1, 0, 0, 0, 56, 57, 3, 14, 7, 0, 57, 64, 6, 6, -1, 0, 58, 59, 7, 1, 0, 0, 59, 60, 3, 14, 7, 0, 60, 61, 6, 6, -1, 0, 61, 63, 1, 0, 0, 0, 62, 58, 1, 0, 0, 0, 63, 66, 1, 0, 0, 0, 64, 62, 1, 0, 0, 0, 64, 65, 1, 0, 0, 0, 65, 13, 1, 0, 0, 0, 66, 64, 1, 0, 0, 0, 67, 68, 5, 20, 0, 0, 68, 69, 6, 7, -1, 0, 69, 15, 1, 0, 0, 0, 70, 71, 5, 28, 0, 0, 71, 72, 6, 8, -1, 0, 72, 17, 1, 0, 0, 0, 73, 74, 5, 3, 0, 0, 74, 78, 6, 9, -1, 0, 75, 76, 5, 4, 0, 0, 76, 78, 6, 9, -1, 0, 77, 73, 1, 0, 0, 0, 77, 75, 1, 0, 0, 0, 78, 19, 1, 0, 0, 0, 4, 39, 53, 64, 77]

View File

@@ -1,9 +1,10 @@
// Generated from c:/Users/Thibaut/Documents/Git/PDS/tp2-vsl-pds/src/main/antlr/VSLParser.g by ANTLR 4.13.1
// Generated from /home/tuanvu/Desktop/M1/S8/PDS/tp2-vsl-pds/src/main/antlr/VSLParser.g by ANTLR 4.13.1
package TP2;
import TP2.asd.Program.*;
import TP2.asd.*;
import TP2.asd.Interface.*;
import TP2.asd.Eval.*;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
@@ -25,7 +26,7 @@ public class VSLParser extends Parser {
FUNCTION=1, PROTOTYPE=2, TYPE_INT=3, TYPE_VOID=4, LE=5, LT=6, GE=7, GT=8,
IF=9, THEN=10, ELSE=11, FIN=12, WHILE=13, DO=14, DONE=15, READ=16, PRINT=17,
RETURN=18, TEXT=19, NUMBER=20, ParO=21, ParF=22, PLUS=23, MINUS=24, DIV=25,
TIMES=26, WS=27, COMMENT=28;
TIMES=26, MOD=27, IDENT=28, WS=29, COMMENT=30;
public static final int
RULE_program = 0, RULE_function = 1, RULE_prototype = 2, RULE_list_instr = 3,
RULE_instruction = 4, RULE_expression = 5, RULE_td_expression = 6, RULE_lit = 7,
@@ -43,7 +44,7 @@ public class VSLParser extends Parser {
null, "'FUNC'", "'PROTO'", "'INT'", "'VOID'", "'<='", "'<'", "'>='",
"'>'", "'IF'", "'THEN'", "'ELSE'", "'FI'", "'WHILE'", "'DO'", "'DONE'",
"'READ'", "'PRINT'", "'RETURN'", null, null, "'('", "')'", "'+'", "'-'",
"'/'", "'*'"
"'/'", "'*'", "'%'"
};
}
private static final String[] _LITERAL_NAMES = makeLiteralNames();
@@ -52,7 +53,7 @@ public class VSLParser extends Parser {
null, "FUNCTION", "PROTOTYPE", "TYPE_INT", "TYPE_VOID", "LE", "LT", "GE",
"GT", "IF", "THEN", "ELSE", "FIN", "WHILE", "DO", "DONE", "READ", "PRINT",
"RETURN", "TEXT", "NUMBER", "ParO", "ParF", "PLUS", "MINUS", "DIV", "TIMES",
"WS", "COMMENT"
"MOD", "IDENT", "WS", "COMMENT"
};
}
private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames();
@@ -173,6 +174,7 @@ public class VSLParser extends Parser {
enterRule(_localctx, 2, RULE_function);
SymTable sym_table = new SymTable();
((FunctionContext)_localctx).out = new ArrayList<Function>();
try {
enterOuterAlt(_localctx, 1);
@@ -190,7 +192,7 @@ public class VSLParser extends Parser {
setState(29);
((FunctionContext)_localctx).instrs = list_instr(sym_table);
_localctx.out.add(new Function(((FunctionContext)_localctx).t.return_type, ((FunctionContext)_localctx).i.out, ((FunctionContext)_localctx).instrs.out));
_localctx.out.add(new FunctionImp(((FunctionContext)_localctx).t.return_type, ((FunctionContext)_localctx).i.out, ((FunctionContext)_localctx).instrs.out));
}
}
@@ -238,8 +240,11 @@ public class VSLParser extends Parser {
public SymTable table;
public ArrayList<Instruction> out;
public InstructionContext instruction;
public InstructionContext instruction() {
return getRuleContext(InstructionContext.class,0);
public List<InstructionContext> instruction() {
return getRuleContexts(InstructionContext.class);
}
public InstructionContext instruction(int i) {
return getRuleContext(InstructionContext.class,i);
}
public List_instrContext(ParserRuleContext parent, int invokingState) { super(parent, invokingState); }
public List_instrContext(ParserRuleContext parent, int invokingState, SymTable table) {
@@ -255,14 +260,27 @@ public class VSLParser extends Parser {
((List_instrContext)_localctx).out = new ArrayList<>();
int _la;
try {
enterOuterAlt(_localctx, 1);
{
setState(34);
((List_instrContext)_localctx).instruction = instruction(table);
setState(37);
_errHandler.sync(this);
_la = _input.LA(1);
do {
{
{
setState(34);
((List_instrContext)_localctx).instruction = instruction(table);
_localctx.out.addAll(((List_instrContext)_localctx).instruction.out);
_localctx.out.add(((List_instrContext)_localctx).instruction.out);
}
}
setState(39);
_errHandler.sync(this);
_la = _input.LA(1);
} while ( _la==RETURN );
}
}
catch (RecognitionException re) {
@@ -279,7 +297,7 @@ public class VSLParser extends Parser {
@SuppressWarnings("CheckReturnValue")
public static class InstructionContext extends ParserRuleContext {
public SymTable table;
public ArrayList<Instruction> out;
public Instruction out;
public ExpressionContext e;
public TerminalNode RETURN() { return getToken(VSLParser.RETURN, 0); }
public ExpressionContext expression() {
@@ -299,12 +317,12 @@ public class VSLParser extends Parser {
try {
enterOuterAlt(_localctx, 1);
{
setState(37);
setState(41);
match(RETURN);
setState(38);
setState(42);
((InstructionContext)_localctx).e = expression(table);
((InstructionContext)_localctx).out = new ArrayList<>();
_localctx.out.add(new Return_instr(((InstructionContext)_localctx).e.out));
((InstructionContext)_localctx).out = new Return_instrImp(((InstructionContext)_localctx).e.out);
}
}
catch (RecognitionException re) {
@@ -355,19 +373,19 @@ public class VSLParser extends Parser {
try {
enterOuterAlt(_localctx, 1);
{
setState(41);
setState(45);
((ExpressionContext)_localctx).left = td_expression(table);
((ExpressionContext)_localctx).out = ((ExpressionContext)_localctx).left.out;
((ExpressionContext)_localctx).return_Type = ((ExpressionContext)_localctx).left.return_Type;
setState(49);
setState(53);
_errHandler.sync(this);
_la = _input.LA(1);
while (_la==PLUS || _la==MINUS) {
{
{
setState(43);
setState(47);
((ExpressionContext)_localctx).op = _input.LT(1);
_la = _input.LA(1);
if ( !(_la==PLUS || _la==MINUS) ) {
@@ -378,10 +396,10 @@ public class VSLParser extends Parser {
_errHandler.reportMatch(this);
consume();
}
setState(44);
setState(48);
((ExpressionContext)_localctx).right = td_expression(table);
((ExpressionContext)_localctx).out = new BinopExpression(
((ExpressionContext)_localctx).out = new BinopExpressionImp(
switch(((ExpressionContext)_localctx).op.getType()) {
case PLUS -> Op.PLUS;
case MINUS -> Op.MINUS;
@@ -394,7 +412,7 @@ public class VSLParser extends Parser {
}
}
setState(51);
setState(55);
_errHandler.sync(this);
_la = _input.LA(1);
}
@@ -448,19 +466,19 @@ public class VSLParser extends Parser {
try {
enterOuterAlt(_localctx, 1);
{
setState(52);
setState(56);
((Td_expressionContext)_localctx).left = lit();
((Td_expressionContext)_localctx).out = ((Td_expressionContext)_localctx).left.out;
((Td_expressionContext)_localctx).return_Type = ((Td_expressionContext)_localctx).left.return_Type;
setState(60);
setState(64);
_errHandler.sync(this);
_la = _input.LA(1);
while (_la==DIV || _la==TIMES) {
{
{
setState(54);
setState(58);
((Td_expressionContext)_localctx).op = _input.LT(1);
_la = _input.LA(1);
if ( !(_la==DIV || _la==TIMES) ) {
@@ -471,13 +489,14 @@ public class VSLParser extends Parser {
_errHandler.reportMatch(this);
consume();
}
setState(55);
setState(59);
((Td_expressionContext)_localctx).right = lit();
((Td_expressionContext)_localctx).out = new Program.BinopExpression(
((Td_expressionContext)_localctx).out = new Program.BinopExpressionImp(
switch(((Td_expressionContext)_localctx).op.getType()) {
case TIMES -> Op.TIMES;
case DIV -> Op.DIV;
case MOD -> Op.MOD;
default -> throw new IllegalArgumentException("Unknown operator");
},
((Td_expressionContext)_localctx).left.out,
@@ -487,7 +506,7 @@ public class VSLParser extends Parser {
}
}
setState(62);
setState(66);
_errHandler.sync(this);
_la = _input.LA(1);
}
@@ -522,11 +541,11 @@ public class VSLParser extends Parser {
try {
enterOuterAlt(_localctx, 1);
{
setState(63);
setState(67);
((LitContext)_localctx).NUMBER = match(NUMBER);
((LitContext)_localctx).return_Type = new Type_int();
((LitContext)_localctx).out = new Const((((LitContext)_localctx).NUMBER!=null?Integer.valueOf(((LitContext)_localctx).NUMBER.getText()):0));
((LitContext)_localctx).return_Type = new Type_intImp();
((LitContext)_localctx).out = new ConstImp((((LitContext)_localctx).NUMBER!=null?Integer.valueOf(((LitContext)_localctx).NUMBER.getText()):0));
}
}
@@ -544,8 +563,8 @@ public class VSLParser extends Parser {
@SuppressWarnings("CheckReturnValue")
public static class IdentContext extends ParserRuleContext {
public String out;
public Token TEXT;
public TerminalNode TEXT() { return getToken(VSLParser.TEXT, 0); }
public Token IDENT;
public TerminalNode IDENT() { return getToken(VSLParser.IDENT, 0); }
public IdentContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@@ -558,9 +577,9 @@ public class VSLParser extends Parser {
try {
enterOuterAlt(_localctx, 1);
{
setState(66);
((IdentContext)_localctx).TEXT = match(TEXT);
((IdentContext)_localctx).out = ((IdentContext)_localctx).TEXT.getText();
setState(70);
((IdentContext)_localctx).IDENT = match(IDENT);
((IdentContext)_localctx).out = ((IdentContext)_localctx).IDENT.getText();
}
}
catch (RecognitionException re) {
@@ -589,23 +608,23 @@ public class VSLParser extends Parser {
TypeContext _localctx = new TypeContext(_ctx, getState());
enterRule(_localctx, 18, RULE_type);
try {
setState(73);
setState(77);
_errHandler.sync(this);
switch (_input.LA(1)) {
case TYPE_INT:
enterOuterAlt(_localctx, 1);
{
setState(69);
setState(73);
match(TYPE_INT);
((TypeContext)_localctx).return_type = new Type_int();
((TypeContext)_localctx).return_type = new Type_intImp();
}
break;
case TYPE_VOID:
enterOuterAlt(_localctx, 2);
{
setState(71);
setState(75);
match(TYPE_VOID);
((TypeContext)_localctx).return_type = new Type_void();
((TypeContext)_localctx).return_type = new Type_voidImp();
}
break;
default:
@@ -624,48 +643,50 @@ public class VSLParser extends Parser {
}
public static final String _serializedATN =
"\u0004\u0001\u001cL\u0002\u0000\u0007\u0000\u0002\u0001\u0007\u0001\u0002"+
"\u0004\u0001\u001eP\u0002\u0000\u0007\u0000\u0002\u0001\u0007\u0001\u0002"+
"\u0002\u0007\u0002\u0002\u0003\u0007\u0003\u0002\u0004\u0007\u0004\u0002"+
"\u0005\u0007\u0005\u0002\u0006\u0007\u0006\u0002\u0007\u0007\u0007\u0002"+
"\b\u0007\b\u0002\t\u0007\t\u0001\u0000\u0001\u0000\u0001\u0000\u0001\u0000"+
"\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001"+
"\u0001\u0001\u0001\u0001\u0001\u0002\u0001\u0002\u0001\u0003\u0001\u0003"+
"\u0001\u0003\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0005"+
"\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0005\u0005"+
"0\b\u0005\n\u0005\f\u00053\t\u0005\u0001\u0006\u0001\u0006\u0001\u0006"+
"\u0001\u0006\u0001\u0006\u0001\u0006\u0005\u0006;\b\u0006\n\u0006\f\u0006"+
">\t\u0006\u0001\u0007\u0001\u0007\u0001\u0007\u0001\b\u0001\b\u0001\b"+
"\u0001\t\u0001\t\u0001\t\u0001\t\u0003\tJ\b\t\u0001\t\u0000\u0000\n\u0000"+
"\u0002\u0004\u0006\b\n\f\u000e\u0010\u0012\u0000\u0002\u0001\u0000\u0017"+
"\u0018\u0001\u0000\u0019\u001aD\u0000\u0014\u0001\u0000\u0000\u0000\u0002"+
"\u0018\u0001\u0000\u0000\u0000\u0004 \u0001\u0000\u0000\u0000\u0006\""+
"\u0001\u0000\u0000\u0000\b%\u0001\u0000\u0000\u0000\n)\u0001\u0000\u0000"+
"\u0000\f4\u0001\u0000\u0000\u0000\u000e?\u0001\u0000\u0000\u0000\u0010"+
"B\u0001\u0000\u0000\u0000\u0012I\u0001\u0000\u0000\u0000\u0014\u0015\u0003"+
"\u0002\u0001\u0000\u0015\u0016\u0005\u0000\u0000\u0001\u0016\u0017\u0006"+
"\u0000\uffff\uffff\u0000\u0017\u0001\u0001\u0000\u0000\u0000\u0018\u0019"+
"\u0005\u0001\u0000\u0000\u0019\u001a\u0003\u0012\t\u0000\u001a\u001b\u0003"+
"\u0010\b\u0000\u001b\u001c\u0005\u0015\u0000\u0000\u001c\u001d\u0005\u0016"+
"\u0000\u0000\u001d\u001e\u0003\u0006\u0003\u0000\u001e\u001f\u0006\u0001"+
"\uffff\uffff\u0000\u001f\u0003\u0001\u0000\u0000\u0000 !\u0001\u0000\u0000"+
"\u0000!\u0005\u0001\u0000\u0000\u0000\"#\u0003\b\u0004\u0000#$\u0006\u0003"+
"\uffff\uffff\u0000$\u0007\u0001\u0000\u0000\u0000%&\u0005\u0012\u0000"+
"\u0000&\'\u0003\n\u0005\u0000\'(\u0006\u0004\uffff\uffff\u0000(\t\u0001"+
"\u0000\u0000\u0000)*\u0003\f\u0006\u0000*1\u0006\u0005\uffff\uffff\u0000"+
"+,\u0007\u0000\u0000\u0000,-\u0003\f\u0006\u0000-.\u0006\u0005\uffff\uffff"+
"\u0000.0\u0001\u0000\u0000\u0000/+\u0001\u0000\u0000\u000003\u0001\u0000"+
"\u0000\u00001/\u0001\u0000\u0000\u000012\u0001\u0000\u0000\u00002\u000b"+
"\u0001\u0000\u0000\u000031\u0001\u0000\u0000\u000045\u0003\u000e\u0007"+
"\u00005<\u0006\u0006\uffff\uffff\u000067\u0007\u0001\u0000\u000078\u0003"+
"\u000e\u0007\u000089\u0006\u0006\uffff\uffff\u00009;\u0001\u0000\u0000"+
"\u0000:6\u0001\u0000\u0000\u0000;>\u0001\u0000\u0000\u0000<:\u0001\u0000"+
"\u0000\u0000<=\u0001\u0000\u0000\u0000=\r\u0001\u0000\u0000\u0000><\u0001"+
"\u0000\u0000\u0000?@\u0005\u0014\u0000\u0000@A\u0006\u0007\uffff\uffff"+
"\u0000A\u000f\u0001\u0000\u0000\u0000BC\u0005\u0013\u0000\u0000CD\u0006"+
"\b\uffff\uffff\u0000D\u0011\u0001\u0000\u0000\u0000EF\u0005\u0003\u0000"+
"\u0000FJ\u0006\t\uffff\uffff\u0000GH\u0005\u0004\u0000\u0000HJ\u0006\t"+
"\uffff\uffff\u0000IE\u0001\u0000\u0000\u0000IG\u0001\u0000\u0000\u0000"+
"J\u0013\u0001\u0000\u0000\u0000\u00031<I";
"\u0001\u0003\u0004\u0003&\b\u0003\u000b\u0003\f\u0003\'\u0001\u0004\u0001"+
"\u0004\u0001\u0004\u0001\u0004\u0001\u0005\u0001\u0005\u0001\u0005\u0001"+
"\u0005\u0001\u0005\u0001\u0005\u0005\u00054\b\u0005\n\u0005\f\u00057\t"+
"\u0005\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0006\u0001"+
"\u0006\u0005\u0006?\b\u0006\n\u0006\f\u0006B\t\u0006\u0001\u0007\u0001"+
"\u0007\u0001\u0007\u0001\b\u0001\b\u0001\b\u0001\t\u0001\t\u0001\t\u0001"+
"\t\u0003\tN\b\t\u0001\t\u0000\u0000\n\u0000\u0002\u0004\u0006\b\n\f\u000e"+
"\u0010\u0012\u0000\u0002\u0001\u0000\u0017\u0018\u0001\u0000\u0019\u001a"+
"I\u0000\u0014\u0001\u0000\u0000\u0000\u0002\u0018\u0001\u0000\u0000\u0000"+
"\u0004 \u0001\u0000\u0000\u0000\u0006%\u0001\u0000\u0000\u0000\b)\u0001"+
"\u0000\u0000\u0000\n-\u0001\u0000\u0000\u0000\f8\u0001\u0000\u0000\u0000"+
"\u000eC\u0001\u0000\u0000\u0000\u0010F\u0001\u0000\u0000\u0000\u0012M"+
"\u0001\u0000\u0000\u0000\u0014\u0015\u0003\u0002\u0001\u0000\u0015\u0016"+
"\u0005\u0000\u0000\u0001\u0016\u0017\u0006\u0000\uffff\uffff\u0000\u0017"+
"\u0001\u0001\u0000\u0000\u0000\u0018\u0019\u0005\u0001\u0000\u0000\u0019"+
"\u001a\u0003\u0012\t\u0000\u001a\u001b\u0003\u0010\b\u0000\u001b\u001c"+
"\u0005\u0015\u0000\u0000\u001c\u001d\u0005\u0016\u0000\u0000\u001d\u001e"+
"\u0003\u0006\u0003\u0000\u001e\u001f\u0006\u0001\uffff\uffff\u0000\u001f"+
"\u0003\u0001\u0000\u0000\u0000 !\u0001\u0000\u0000\u0000!\u0005\u0001"+
"\u0000\u0000\u0000\"#\u0003\b\u0004\u0000#$\u0006\u0003\uffff\uffff\u0000"+
"$&\u0001\u0000\u0000\u0000%\"\u0001\u0000\u0000\u0000&\'\u0001\u0000\u0000"+
"\u0000\'%\u0001\u0000\u0000\u0000\'(\u0001\u0000\u0000\u0000(\u0007\u0001"+
"\u0000\u0000\u0000)*\u0005\u0012\u0000\u0000*+\u0003\n\u0005\u0000+,\u0006"+
"\u0004\uffff\uffff\u0000,\t\u0001\u0000\u0000\u0000-.\u0003\f\u0006\u0000"+
".5\u0006\u0005\uffff\uffff\u0000/0\u0007\u0000\u0000\u000001\u0003\f\u0006"+
"\u000012\u0006\u0005\uffff\uffff\u000024\u0001\u0000\u0000\u00003/\u0001"+
"\u0000\u0000\u000047\u0001\u0000\u0000\u000053\u0001\u0000\u0000\u0000"+
"56\u0001\u0000\u0000\u00006\u000b\u0001\u0000\u0000\u000075\u0001\u0000"+
"\u0000\u000089\u0003\u000e\u0007\u00009@\u0006\u0006\uffff\uffff\u0000"+
":;\u0007\u0001\u0000\u0000;<\u0003\u000e\u0007\u0000<=\u0006\u0006\uffff"+
"\uffff\u0000=?\u0001\u0000\u0000\u0000>:\u0001\u0000\u0000\u0000?B\u0001"+
"\u0000\u0000\u0000@>\u0001\u0000\u0000\u0000@A\u0001\u0000\u0000\u0000"+
"A\r\u0001\u0000\u0000\u0000B@\u0001\u0000\u0000\u0000CD\u0005\u0014\u0000"+
"\u0000DE\u0006\u0007\uffff\uffff\u0000E\u000f\u0001\u0000\u0000\u0000"+
"FG\u0005\u001c\u0000\u0000GH\u0006\b\uffff\uffff\u0000H\u0011\u0001\u0000"+
"\u0000\u0000IJ\u0005\u0003\u0000\u0000JN\u0006\t\uffff\uffff\u0000KL\u0005"+
"\u0004\u0000\u0000LN\u0006\t\uffff\uffff\u0000MI\u0001\u0000\u0000\u0000"+
"MK\u0001\u0000\u0000\u0000N\u0013\u0001\u0000\u0000\u0000\u0004\'5@M";
public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static {

View File

@@ -24,8 +24,10 @@ PLUS=23
MINUS=24
DIV=25
TIMES=26
WS=27
COMMENT=28
MOD=27
IDENT=28
WS=29
COMMENT=30
'FUNC'=1
'PROTO'=2
'INT'=3
@@ -50,3 +52,4 @@ COMMENT=28
'-'=24
'/'=25
'*'=26
'%'=27

View File

@@ -44,7 +44,7 @@ PRINT : 'PRINT'
;
RETURN: 'RETURN'
;
TEXT : '"' (ASCII)+ '"' {getText().substring(1,getText().length()-1);}
TEXT : '"' (ASCII)+ '"'
;
NUMBER : (DIGIT)+
;
@@ -60,7 +60,10 @@ DIV:'/'
;
TIMES: '*'
;
MOD: '%'
;
IDENT: ('a'..'z'|'A'..'Z')('a'..'z'|'A'..'Z'|'0'..'9'|'_'|'-')*
;
WS : (' '|'\n'|'\t') { skip(); }
;

View File

@@ -11,6 +11,7 @@ options {
import TP2.asd.Program.*;
import TP2.asd.*;
import TP2.asd.Interface.*;
import TP2.asd.Eval.*;
}
// On syntax error, raise exception rather than silently recovery
@@ -31,10 +32,11 @@ program returns [ProgramImp p] :
function returns [ArrayList<Function> out]
@init{
SymTable sym_table = new SymTable();
$out = new ArrayList<Function>();
}:
FUNCTION t=type i=ident ParO ParF instrs=list_instr[sym_table]
{
$out.add(new Function($t.return_type, $i.out, $instrs.out));
$out.add(new FunctionImp($t.return_type, $i.out, $instrs.out));
}
;
@@ -45,15 +47,15 @@ list_instr [SymTable table] returns [ArrayList<Instruction> out]
@init{
$out = new ArrayList<>();
}:
instruction [table] {
$out.addAll($instruction.out);
}
(instruction [table] {
$out.add($instruction.out);
})+
;
instruction [SymTable table] returns [ArrayList<Instruction> out]:
instruction [SymTable table] returns [Instruction out]:
RETURN e=expression [table]
{$out = new ArrayList<>();
$out.add(new Return_instr($e.out));}
{
$out =new Return_instrImp($e.out);}
;
expression [SymTable table] returns [Type return_Type, Expression out]:
@@ -65,7 +67,7 @@ expression [SymTable table] returns [Type return_Type, Expression out]:
//maybe it will be binop(s) with add/sub here
//if it is mul or div, they are all gonna be left=td_expression[table] to handle
(op=(PLUS | MINUS) right=td_expression[table] {
$out = new BinopExpression(
$out = new BinopExpressionImp(
switch($op.getType()) {
case PLUS -> Op.PLUS;
case MINUS -> Op.MINUS;
@@ -84,10 +86,11 @@ td_expression [SymTable table] returns [Type return_Type, Expression out]:
$return_Type = $left.return_Type;
}
(op=(TIMES | DIV) right=lit {
$out = new Program.BinopExpression(
$out = new Program.BinopExpressionImp(
switch($op.getType()) {
case TIMES -> Op.TIMES;
case DIV -> Op.DIV;
case MOD -> Op.MOD;
default -> throw new IllegalArgumentException("Unknown operator");
},
$left.out,
@@ -99,16 +102,16 @@ td_expression [SymTable table] returns [Type return_Type, Expression out]:
lit returns [Expression out, Type return_Type]:
NUMBER {
$return_Type = new Type_int();
$out = new Const($NUMBER.int);
$return_Type = new Type_intImp();
$out = new ConstImp($NUMBER.int);
}
;
ident returns [String out]:
TEXT { $out = $TEXT.getText(); }
IDENT { $out = $IDENT.getText(); }
;
type returns [Type return_type]:
TYPE_INT { $return_type = new Type_int(); }
|TYPE_VOID { $return_type = new Type_void(); }
TYPE_INT { $return_type = new Type_intImp(); }
|TYPE_VOID { $return_type = new Type_voidImp(); }
;

View File

@@ -7,6 +7,7 @@ import org.antlr.runtime.ANTLRInputStream;
import org.antlr.runtime.CharStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.Token;
import TP2.asd.Program.*;
import java.util.*;
@@ -28,6 +29,10 @@ public class Main {
VSLLexer lexer = new VSLLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
for (Token token : tokens.getTokens()) {
System.out.println("Token: " + token.getText() + " Type: " + token.getType());
}
// Instantiate Parser
VSLParser parser = new VSLParser(tokens);

View File

@@ -0,0 +1,34 @@
package TP2.asd;
import java.util.Map;
import TP2.asd.Interface.*;
import TP2.asd.Program.*;
public class Eval {
public class ExprEval implements ExprVisitor<Map<String,Integer>,Integer>{
public Integer visitConst(ConstImp c, Map<String,Integer> h){
return c.c();
}
public Integer visitBinOp(BinopExpressionImp e, Map<String, Integer> h) {
switch(e.op()) {
case Op.PLUS: return e.e1().accept(this, h)+e.e2().accept(this, h);
case Op.MINUS: return e.e1().accept(this, h)-e.e2().accept(this, h);
case Op.TIMES: return e.e1().accept(this, h)*e.e2().accept(this, h);
case Op.DIV: return e.e1().accept(this, h)/e.e2().accept(this, h);
default: throw new IllegalArgumentException();
}
}
}
public class InstructionEval implements InstrVisitor<Map<String,Integer>,Integer>{
@Override
public Integer visitReturn(Return_instrImp e, Map<String, Integer> h) {
ExprEval exprEval = new ExprEval();
return e.e().accept(exprEval, h);
}
}
}

View File

@@ -1,36 +1,47 @@
package TP2.asd;
import java.util.ArrayList;
import java.util.Map;
import TP2.asd.Program.*;
public interface Interface{
public interface Expression {
public <H,S> S accept(ExprVisitor<H,S> v, H h);
}
public interface Interface{
public interface ProgramI {
public <H,S> S accept(ProgramVisitor<H,S> v, H h);
}
public interface Function {
public <H,S> S accept(FunctionVisitor<H,S> v, H h);
}
public interface Instruction {
public <H,S> S accept(InstrVisitor<H,S> v, H h);
}
public interface Expression {
public <H,S> S accept(ExprVisitor<H,S> v, H h);
}
public interface ProgramVisitor<H,S> {
public S visitProgram(ProgramImp p, H h);
public S visitFunction(Function f, H h);
public S visitProgram(ProgramImp programImp, H h);
}
public interface FunctionVisitor<H,S> {
public S visitFunction(FunctionImp e, H h);
}
public interface InstrVisitor<H,S>{
public S visitReturn(Return_instr e, H h);
public S visitReturn(Return_instrImp e, H h);
}
public interface ExprVisitor<H,S> {
public S visitConst(Const e,H h);
public S visitBinOp(BinopExpression e, H h);
public S visitConst(ConstImp e,H h);
public S visitBinOp(BinopExpressionImp e, H h);
}
public interface Type{
public String prettyprinter();
}
public enum Op {PLUS, MINUS, TIMES, DIV}
public enum Op {PLUS, MINUS, TIMES, DIV,MOD}
//Eval
public interface ExprEval extends ExprVisitor<Map<String, Integer>, Integer> {

View File

@@ -2,55 +2,108 @@ package TP2.asd;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import TP2.asd.Interface.*;
import TP2.asd.Eval.*;
public class Program{
public static record ProgramImp(ArrayList<Function> instructions){
public static record ProgramImp(ArrayList<Function> instructions) implements ProgramI{
public <H, S> S accept(ProgramVisitor<H, S> v, H h) {
return v.visitProgram(this, h);
}
}
public static record Function(Type type, String nom, ArrayList<Instruction> instructions){
public Function(Type type, String name, Instruction instruction) {
public static record FunctionImp(Type type, String nom, ArrayList<Instruction> instructions)implements Function {
public FunctionImp(Type type, String name, Instruction instruction) {
this(type, name, new ArrayList<>() {{ add(instruction); }});
}
public <H, S> S accept(ProgramVisitor<H, S> v, H h) {
public <H, S> S accept(FunctionVisitor<H, S> v, H h) {
return v.visitFunction(this, h);
}
}
public static record Const(int c) implements Expression{
public static record ConstImp(int c) implements Expression{
public <H, S> S accept(ExprVisitor<H, S> v, H h) {
return v.visitConst(this, h);
}
}
public static record BinopExpression(Op op,Expression e1, Expression e2) implements Expression{
public static record BinopExpressionImp(Op op,Expression e1, Expression e2) implements Expression{
public <H, S> S accept(ExprVisitor<H, S> v, H h) {
return v.visitBinOp(this, h);
}
}
public static record Return_instr(Expression e) implements Instruction{
public static record Return_instrImp(Expression e) implements Instruction{
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
return v.visitReturn(this,h);
}
}
public static record Type_void() implements Type{
public static record Type_voidImp() implements Type{
public String prettyprinter() {
return "VOID";
}
}
public static record Type_int() implements Type{
public static record Type_intImp() implements Type{
public String prettyprinter() {
return "INT";
}
}
}
//Eval
public static class ProgramEval implements ProgramVisitor<Map<String, Integer>, Integer> {
@Override
public Integer visitProgram(ProgramImp e, Map<String, Integer> h) {
Integer result = null;
FunctionEval functionEval = new FunctionEval();
for (Function function : e.instructions()) {
result = function.accept(functionEval, h);
}
return result;
}
}
public static class FunctionEval implements FunctionVisitor<Map<String, Integer>, Integer> {
@Override
public Integer visitFunction(FunctionImp e, Map<String, Integer> h) {
InstructionEval instructionEval = new InstructionEval();
Integer result = null;
for (Instruction instr : e.instructions()) {
result = instr.accept(instructionEval, h);
}
return result;
}
}
public static class InstructionEval implements InstrVisitor<Map<String,Integer>,Integer>{
@Override
public Integer visitReturn(Return_instrImp e, Map<String, Integer> h) {
ExprEval exprEval = new ExprEval();
return e.e().accept(exprEval, h);
}
}
public static class ExprEval implements ExprVisitor<Map<String,Integer>,Integer>{
public Integer visitConst(ConstImp c, Map<String,Integer> h){
return c.c();
}
public Integer visitBinOp(BinopExpressionImp e, Map<String, Integer> h) {
switch(e.op()) {
case Op.PLUS: return e.e1().accept(this, h)+e.e2().accept(this, h);
case Op.MINUS: return e.e1().accept(this, h)-e.e2().accept(this, h);
case Op.TIMES: return e.e1().accept(this, h)*e.e2().accept(this, h);
case Op.DIV: return e.e1().accept(this, h)/e.e2().accept(this, h);
case Op.MOD: return e.e1().accept(this, h)%e.e2().accept(this, h);
default: throw new IllegalArgumentException();
}
}
}
}