diff --git a/src/.antlr/SysY.interp b/src/.antlr/SysY.interp deleted file mode 100644 index 5b1df8b..0000000 --- a/src/.antlr/SysY.interp +++ /dev/null @@ -1,28 +0,0 @@ -token literal names: -null -',' -null -null -null -null -null -null - -token symbolic names: -null -Comma -IntLiteral -FloatLiteral -STRING -WS -LINE_COMMENT -COMMENT - -rule names: -funcRParams -funcRParam -number - - -atn: -[3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 3, 9, 23, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 3, 2, 3, 2, 3, 2, 7, 2, 12, 10, 2, 12, 2, 14, 2, 15, 11, 2, 3, 3, 3, 3, 5, 3, 19, 10, 3, 3, 4, 3, 4, 3, 4, 2, 2, 5, 2, 4, 6, 2, 3, 3, 2, 4, 5, 2, 21, 2, 8, 3, 2, 2, 2, 4, 18, 3, 2, 2, 2, 6, 20, 3, 2, 2, 2, 8, 13, 5, 4, 3, 2, 9, 10, 7, 3, 2, 2, 10, 12, 5, 4, 3, 2, 11, 9, 3, 2, 2, 2, 12, 15, 3, 2, 2, 2, 13, 11, 3, 2, 2, 2, 13, 14, 3, 2, 2, 2, 14, 3, 3, 2, 2, 2, 15, 13, 3, 2, 2, 2, 16, 19, 5, 6, 4, 2, 17, 19, 7, 6, 2, 2, 18, 16, 3, 2, 2, 2, 18, 17, 3, 2, 2, 2, 19, 5, 3, 2, 2, 2, 20, 21, 9, 2, 2, 2, 21, 7, 3, 2, 2, 2, 4, 13, 18] \ No newline at end of file diff --git a/src/.antlr/SysY.tokens b/src/.antlr/SysY.tokens deleted file mode 100644 index 600d554..0000000 --- a/src/.antlr/SysY.tokens +++ /dev/null @@ -1,8 +0,0 @@ -Comma=1 -IntLiteral=2 -FloatLiteral=3 -STRING=4 -WS=5 -LINE_COMMENT=6 -COMMENT=7 -','=1 diff --git a/src/.antlr/SysYLexer.interp b/src/.antlr/SysYLexer.interp deleted file mode 100644 index ab7ca53..0000000 --- a/src/.antlr/SysYLexer.interp +++ /dev/null @@ -1,42 +0,0 @@ -token literal names: -null -',' -null -null -null -null -null -null - -token symbolic names: -null -Comma -IntLiteral -FloatLiteral -STRING -WS -LINE_COMMENT -COMMENT - -rule names: -Comma -IntLiteral -HexadecimalDigits -ExponentPart -FractionPart -FloatLiteral -STRING -ESC -WS -LINE_COMMENT -COMMENT - -channel names: -DEFAULT_TOKEN_CHANNEL -HIDDEN - -mode names: -DEFAULT_MODE - -atn: -[3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 2, 9, 165, 8, 1, 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, 3, 2, 3, 2, 3, 3, 6, 3, 29, 10, 3, 13, 3, 14, 3, 30, 3, 3, 3, 3, 3, 3, 3, 3, 6, 3, 37, 10, 3, 13, 3, 14, 3, 38, 3, 3, 3, 3, 3, 3, 3, 3, 6, 3, 45, 10, 3, 13, 3, 14, 3, 46, 5, 3, 49, 10, 3, 3, 4, 3, 4, 3, 4, 3, 4, 6, 4, 55, 10, 4, 13, 4, 14, 4, 56, 3, 4, 3, 4, 3, 4, 3, 4, 6, 4, 63, 10, 4, 13, 4, 14, 4, 64, 5, 4, 67, 10, 4, 3, 5, 3, 5, 3, 5, 6, 5, 72, 10, 5, 13, 5, 14, 5, 73, 3, 6, 7, 6, 77, 10, 6, 12, 6, 14, 6, 80, 11, 6, 3, 6, 3, 6, 6, 6, 84, 10, 6, 13, 6, 14, 6, 85, 3, 6, 6, 6, 89, 10, 6, 13, 6, 14, 6, 90, 3, 6, 5, 6, 94, 10, 6, 3, 7, 3, 7, 5, 7, 98, 10, 7, 3, 7, 6, 7, 101, 10, 7, 13, 7, 14, 7, 102, 3, 7, 3, 7, 5, 7, 107, 10, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 5, 7, 114, 10, 7, 3, 8, 3, 8, 3, 8, 7, 8, 119, 10, 8, 12, 8, 14, 8, 122, 11, 8, 3, 8, 3, 8, 3, 9, 3, 9, 3, 9, 3, 9, 5, 9, 130, 10, 9, 3, 10, 3, 10, 3, 10, 3, 10, 3, 11, 3, 11, 3, 11, 3, 11, 7, 11, 140, 10, 11, 12, 11, 14, 11, 143, 11, 11, 3, 11, 5, 11, 146, 10, 11, 3, 11, 3, 11, 3, 11, 3, 11, 3, 12, 3, 12, 3, 12, 3, 12, 7, 12, 156, 10, 12, 12, 12, 14, 12, 159, 11, 12, 3, 12, 3, 12, 3, 12, 3, 12, 3, 12, 5, 120, 141, 157, 2, 13, 3, 3, 5, 4, 7, 2, 9, 2, 11, 2, 13, 5, 15, 6, 17, 2, 19, 7, 21, 8, 23, 9, 3, 2, 7, 3, 2, 50, 59, 5, 2, 50, 59, 67, 72, 99, 104, 4, 2, 71, 71, 103, 103, 4, 2, 45, 45, 47, 47, 5, 2, 11, 12, 15, 15, 34, 34, 2, 185, 2, 3, 3, 2, 2, 2, 2, 5, 3, 2, 2, 2, 2, 13, 3, 2, 2, 2, 2, 15, 3, 2, 2, 2, 2, 19, 3, 2, 2, 2, 2, 21, 3, 2, 2, 2, 2, 23, 3, 2, 2, 2, 3, 25, 3, 2, 2, 2, 5, 48, 3, 2, 2, 2, 7, 66, 3, 2, 2, 2, 9, 68, 3, 2, 2, 2, 11, 93, 3, 2, 2, 2, 13, 113, 3, 2, 2, 2, 15, 115, 3, 2, 2, 2, 17, 129, 3, 2, 2, 2, 19, 131, 3, 2, 2, 2, 21, 135, 3, 2, 2, 2, 23, 151, 3, 2, 2, 2, 25, 26, 7, 46, 2, 2, 26, 4, 3, 2, 2, 2, 27, 29, 9, 2, 2, 2, 28, 27, 3, 2, 2, 2, 29, 30, 3, 2, 2, 2, 30, 28, 3, 2, 2, 2, 30, 31, 3, 2, 2, 2, 31, 49, 3, 2, 2, 2, 32, 33, 7, 50, 2, 2, 33, 34, 7, 122, 2, 2, 34, 36, 3, 2, 2, 2, 35, 37, 9, 3, 2, 2, 36, 35, 3, 2, 2, 2, 37, 38, 3, 2, 2, 2, 38, 36, 3, 2, 2, 2, 38, 39, 3, 2, 2, 2, 39, 49, 3, 2, 2, 2, 40, 41, 7, 50, 2, 2, 41, 42, 7, 90, 2, 2, 42, 44, 3, 2, 2, 2, 43, 45, 9, 3, 2, 2, 44, 43, 3, 2, 2, 2, 45, 46, 3, 2, 2, 2, 46, 44, 3, 2, 2, 2, 46, 47, 3, 2, 2, 2, 47, 49, 3, 2, 2, 2, 48, 28, 3, 2, 2, 2, 48, 32, 3, 2, 2, 2, 48, 40, 3, 2, 2, 2, 49, 6, 3, 2, 2, 2, 50, 51, 7, 50, 2, 2, 51, 52, 7, 122, 2, 2, 52, 54, 3, 2, 2, 2, 53, 55, 9, 3, 2, 2, 54, 53, 3, 2, 2, 2, 55, 56, 3, 2, 2, 2, 56, 54, 3, 2, 2, 2, 56, 57, 3, 2, 2, 2, 57, 67, 3, 2, 2, 2, 58, 59, 7, 50, 2, 2, 59, 60, 7, 90, 2, 2, 60, 62, 3, 2, 2, 2, 61, 63, 9, 3, 2, 2, 62, 61, 3, 2, 2, 2, 63, 64, 3, 2, 2, 2, 64, 62, 3, 2, 2, 2, 64, 65, 3, 2, 2, 2, 65, 67, 3, 2, 2, 2, 66, 50, 3, 2, 2, 2, 66, 58, 3, 2, 2, 2, 67, 8, 3, 2, 2, 2, 68, 69, 9, 4, 2, 2, 69, 71, 9, 5, 2, 2, 70, 72, 9, 2, 2, 2, 71, 70, 3, 2, 2, 2, 72, 73, 3, 2, 2, 2, 73, 71, 3, 2, 2, 2, 73, 74, 3, 2, 2, 2, 74, 10, 3, 2, 2, 2, 75, 77, 9, 2, 2, 2, 76, 75, 3, 2, 2, 2, 77, 80, 3, 2, 2, 2, 78, 76, 3, 2, 2, 2, 78, 79, 3, 2, 2, 2, 79, 81, 3, 2, 2, 2, 80, 78, 3, 2, 2, 2, 81, 83, 7, 48, 2, 2, 82, 84, 9, 2, 2, 2, 83, 82, 3, 2, 2, 2, 84, 85, 3, 2, 2, 2, 85, 83, 3, 2, 2, 2, 85, 86, 3, 2, 2, 2, 86, 94, 3, 2, 2, 2, 87, 89, 9, 2, 2, 2, 88, 87, 3, 2, 2, 2, 89, 90, 3, 2, 2, 2, 90, 88, 3, 2, 2, 2, 90, 91, 3, 2, 2, 2, 91, 92, 3, 2, 2, 2, 92, 94, 7, 48, 2, 2, 93, 78, 3, 2, 2, 2, 93, 88, 3, 2, 2, 2, 94, 12, 3, 2, 2, 2, 95, 97, 5, 11, 6, 2, 96, 98, 5, 9, 5, 2, 97, 96, 3, 2, 2, 2, 97, 98, 3, 2, 2, 2, 98, 114, 3, 2, 2, 2, 99, 101, 9, 2, 2, 2, 100, 99, 3, 2, 2, 2, 101, 102, 3, 2, 2, 2, 102, 100, 3, 2, 2, 2, 102, 103, 3, 2, 2, 2, 103, 104, 3, 2, 2, 2, 104, 114, 5, 9, 5, 2, 105, 107, 5, 7, 4, 2, 106, 105, 3, 2, 2, 2, 106, 107, 3, 2, 2, 2, 107, 108, 3, 2, 2, 2, 108, 109, 7, 48, 2, 2, 109, 114, 5, 7, 4, 2, 110, 111, 5, 7, 4, 2, 111, 112, 7, 48, 2, 2, 112, 114, 3, 2, 2, 2, 113, 95, 3, 2, 2, 2, 113, 100, 3, 2, 2, 2, 113, 106, 3, 2, 2, 2, 113, 110, 3, 2, 2, 2, 114, 14, 3, 2, 2, 2, 115, 120, 7, 36, 2, 2, 116, 119, 5, 17, 9, 2, 117, 119, 11, 2, 2, 2, 118, 116, 3, 2, 2, 2, 118, 117, 3, 2, 2, 2, 119, 122, 3, 2, 2, 2, 120, 121, 3, 2, 2, 2, 120, 118, 3, 2, 2, 2, 121, 123, 3, 2, 2, 2, 122, 120, 3, 2, 2, 2, 123, 124, 7, 36, 2, 2, 124, 16, 3, 2, 2, 2, 125, 126, 7, 94, 2, 2, 126, 130, 7, 36, 2, 2, 127, 128, 7, 94, 2, 2, 128, 130, 7, 94, 2, 2, 129, 125, 3, 2, 2, 2, 129, 127, 3, 2, 2, 2, 130, 18, 3, 2, 2, 2, 131, 132, 9, 6, 2, 2, 132, 133, 3, 2, 2, 2, 133, 134, 8, 10, 2, 2, 134, 20, 3, 2, 2, 2, 135, 136, 7, 49, 2, 2, 136, 137, 7, 49, 2, 2, 137, 141, 3, 2, 2, 2, 138, 140, 11, 2, 2, 2, 139, 138, 3, 2, 2, 2, 140, 143, 3, 2, 2, 2, 141, 142, 3, 2, 2, 2, 141, 139, 3, 2, 2, 2, 142, 145, 3, 2, 2, 2, 143, 141, 3, 2, 2, 2, 144, 146, 7, 15, 2, 2, 145, 144, 3, 2, 2, 2, 145, 146, 3, 2, 2, 2, 146, 147, 3, 2, 2, 2, 147, 148, 7, 12, 2, 2, 148, 149, 3, 2, 2, 2, 149, 150, 8, 11, 2, 2, 150, 22, 3, 2, 2, 2, 151, 152, 7, 49, 2, 2, 152, 153, 7, 44, 2, 2, 153, 157, 3, 2, 2, 2, 154, 156, 11, 2, 2, 2, 155, 154, 3, 2, 2, 2, 156, 159, 3, 2, 2, 2, 157, 158, 3, 2, 2, 2, 157, 155, 3, 2, 2, 2, 158, 160, 3, 2, 2, 2, 159, 157, 3, 2, 2, 2, 160, 161, 7, 44, 2, 2, 161, 162, 7, 49, 2, 2, 162, 163, 3, 2, 2, 2, 163, 164, 8, 12, 2, 2, 164, 24, 3, 2, 2, 2, 25, 2, 30, 38, 46, 48, 56, 64, 66, 73, 78, 85, 90, 93, 97, 102, 106, 113, 118, 120, 129, 141, 145, 157, 3, 8, 2, 2] \ No newline at end of file diff --git a/src/.antlr/SysYLexer.java b/src/.antlr/SysYLexer.java deleted file mode 100644 index e1fc747..0000000 --- a/src/.antlr/SysYLexer.java +++ /dev/null @@ -1,165 +0,0 @@ -// Generated from /home/xsu/workspace/sysy/sysy/src/SysY.g4 by ANTLR 4.9.2 -import org.antlr.v4.runtime.Lexer; -import org.antlr.v4.runtime.CharStream; -import org.antlr.v4.runtime.Token; -import org.antlr.v4.runtime.TokenStream; -import org.antlr.v4.runtime.*; -import org.antlr.v4.runtime.atn.*; -import org.antlr.v4.runtime.dfa.DFA; -import org.antlr.v4.runtime.misc.*; - -@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"}) -public class SysYLexer extends Lexer { - static { RuntimeMetaData.checkVersion("4.9.2", RuntimeMetaData.VERSION); } - - protected static final DFA[] _decisionToDFA; - protected static final PredictionContextCache _sharedContextCache = - new PredictionContextCache(); - public static final int - Comma=1, IntLiteral=2, FloatLiteral=3, STRING=4, WS=5, LINE_COMMENT=6, - COMMENT=7; - public static String[] channelNames = { - "DEFAULT_TOKEN_CHANNEL", "HIDDEN" - }; - - public static String[] modeNames = { - "DEFAULT_MODE" - }; - - private static String[] makeRuleNames() { - return new String[] { - "Comma", "IntLiteral", "HexadecimalDigits", "ExponentPart", "FractionPart", - "FloatLiteral", "STRING", "ESC", "WS", "LINE_COMMENT", "COMMENT" - }; - } - public static final String[] ruleNames = makeRuleNames(); - - private static String[] makeLiteralNames() { - return new String[] { - null, "','" - }; - } - private static final String[] _LITERAL_NAMES = makeLiteralNames(); - private static String[] makeSymbolicNames() { - return new String[] { - null, "Comma", "IntLiteral", "FloatLiteral", "STRING", "WS", "LINE_COMMENT", - "COMMENT" - }; - } - 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] = ""; - } - } - } - - @Override - @Deprecated - public String[] getTokenNames() { - return tokenNames; - } - - @Override - - public Vocabulary getVocabulary() { - return VOCABULARY; - } - - - public SysYLexer(CharStream input) { - super(input); - _interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache); - } - - @Override - public String getGrammarFileName() { return "SysY.g4"; } - - @Override - public String[] getRuleNames() { return ruleNames; } - - @Override - public String getSerializedATN() { return _serializedATN; } - - @Override - public String[] getChannelNames() { return channelNames; } - - @Override - public String[] getModeNames() { return modeNames; } - - @Override - public ATN getATN() { return _ATN; } - - public static final String _serializedATN = - "\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2\t\u00a5\b\1\4\2\t"+ - "\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"+ - "\t\13\4\f\t\f\3\2\3\2\3\3\6\3\35\n\3\r\3\16\3\36\3\3\3\3\3\3\3\3\6\3%"+ - "\n\3\r\3\16\3&\3\3\3\3\3\3\3\3\6\3-\n\3\r\3\16\3.\5\3\61\n\3\3\4\3\4\3"+ - "\4\3\4\6\4\67\n\4\r\4\16\48\3\4\3\4\3\4\3\4\6\4?\n\4\r\4\16\4@\5\4C\n"+ - "\4\3\5\3\5\3\5\6\5H\n\5\r\5\16\5I\3\6\7\6M\n\6\f\6\16\6P\13\6\3\6\3\6"+ - "\6\6T\n\6\r\6\16\6U\3\6\6\6Y\n\6\r\6\16\6Z\3\6\5\6^\n\6\3\7\3\7\5\7b\n"+ - "\7\3\7\6\7e\n\7\r\7\16\7f\3\7\3\7\5\7k\n\7\3\7\3\7\3\7\3\7\3\7\5\7r\n"+ - "\7\3\b\3\b\3\b\7\bw\n\b\f\b\16\bz\13\b\3\b\3\b\3\t\3\t\3\t\3\t\5\t\u0082"+ - "\n\t\3\n\3\n\3\n\3\n\3\13\3\13\3\13\3\13\7\13\u008c\n\13\f\13\16\13\u008f"+ - "\13\13\3\13\5\13\u0092\n\13\3\13\3\13\3\13\3\13\3\f\3\f\3\f\3\f\7\f\u009c"+ - "\n\f\f\f\16\f\u009f\13\f\3\f\3\f\3\f\3\f\3\f\5x\u008d\u009d\2\r\3\3\5"+ - "\4\7\2\t\2\13\2\r\5\17\6\21\2\23\7\25\b\27\t\3\2\7\3\2\62;\5\2\62;CHc"+ - "h\4\2GGgg\4\2--//\5\2\13\f\17\17\"\"\2\u00b9\2\3\3\2\2\2\2\5\3\2\2\2\2"+ - "\r\3\2\2\2\2\17\3\2\2\2\2\23\3\2\2\2\2\25\3\2\2\2\2\27\3\2\2\2\3\31\3"+ - "\2\2\2\5\60\3\2\2\2\7B\3\2\2\2\tD\3\2\2\2\13]\3\2\2\2\rq\3\2\2\2\17s\3"+ - "\2\2\2\21\u0081\3\2\2\2\23\u0083\3\2\2\2\25\u0087\3\2\2\2\27\u0097\3\2"+ - "\2\2\31\32\7.\2\2\32\4\3\2\2\2\33\35\t\2\2\2\34\33\3\2\2\2\35\36\3\2\2"+ - "\2\36\34\3\2\2\2\36\37\3\2\2\2\37\61\3\2\2\2 !\7\62\2\2!\"\7z\2\2\"$\3"+ - "\2\2\2#%\t\3\2\2$#\3\2\2\2%&\3\2\2\2&$\3\2\2\2&\'\3\2\2\2\'\61\3\2\2\2"+ - "()\7\62\2\2)*\7Z\2\2*,\3\2\2\2+-\t\3\2\2,+\3\2\2\2-.\3\2\2\2.,\3\2\2\2"+ - "./\3\2\2\2/\61\3\2\2\2\60\34\3\2\2\2\60 \3\2\2\2\60(\3\2\2\2\61\6\3\2"+ - "\2\2\62\63\7\62\2\2\63\64\7z\2\2\64\66\3\2\2\2\65\67\t\3\2\2\66\65\3\2"+ - "\2\2\678\3\2\2\28\66\3\2\2\289\3\2\2\29C\3\2\2\2:;\7\62\2\2;<\7Z\2\2<"+ - ">\3\2\2\2=?\t\3\2\2>=\3\2\2\2?@\3\2\2\2@>\3\2\2\2@A\3\2\2\2AC\3\2\2\2"+ - "B\62\3\2\2\2B:\3\2\2\2C\b\3\2\2\2DE\t\4\2\2EG\t\5\2\2FH\t\2\2\2GF\3\2"+ - "\2\2HI\3\2\2\2IG\3\2\2\2IJ\3\2\2\2J\n\3\2\2\2KM\t\2\2\2LK\3\2\2\2MP\3"+ - "\2\2\2NL\3\2\2\2NO\3\2\2\2OQ\3\2\2\2PN\3\2\2\2QS\7\60\2\2RT\t\2\2\2SR"+ - "\3\2\2\2TU\3\2\2\2US\3\2\2\2UV\3\2\2\2V^\3\2\2\2WY\t\2\2\2XW\3\2\2\2Y"+ - "Z\3\2\2\2ZX\3\2\2\2Z[\3\2\2\2[\\\3\2\2\2\\^\7\60\2\2]N\3\2\2\2]X\3\2\2"+ - "\2^\f\3\2\2\2_a\5\13\6\2`b\5\t\5\2a`\3\2\2\2ab\3\2\2\2br\3\2\2\2ce\t\2"+ - "\2\2dc\3\2\2\2ef\3\2\2\2fd\3\2\2\2fg\3\2\2\2gh\3\2\2\2hr\5\t\5\2ik\5\7"+ - "\4\2ji\3\2\2\2jk\3\2\2\2kl\3\2\2\2lm\7\60\2\2mr\5\7\4\2no\5\7\4\2op\7"+ - "\60\2\2pr\3\2\2\2q_\3\2\2\2qd\3\2\2\2qj\3\2\2\2qn\3\2\2\2r\16\3\2\2\2"+ - "sx\7$\2\2tw\5\21\t\2uw\13\2\2\2vt\3\2\2\2vu\3\2\2\2wz\3\2\2\2xy\3\2\2"+ - "\2xv\3\2\2\2y{\3\2\2\2zx\3\2\2\2{|\7$\2\2|\20\3\2\2\2}~\7^\2\2~\u0082"+ - "\7$\2\2\177\u0080\7^\2\2\u0080\u0082\7^\2\2\u0081}\3\2\2\2\u0081\177\3"+ - "\2\2\2\u0082\22\3\2\2\2\u0083\u0084\t\6\2\2\u0084\u0085\3\2\2\2\u0085"+ - "\u0086\b\n\2\2\u0086\24\3\2\2\2\u0087\u0088\7\61\2\2\u0088\u0089\7\61"+ - "\2\2\u0089\u008d\3\2\2\2\u008a\u008c\13\2\2\2\u008b\u008a\3\2\2\2\u008c"+ - "\u008f\3\2\2\2\u008d\u008e\3\2\2\2\u008d\u008b\3\2\2\2\u008e\u0091\3\2"+ - "\2\2\u008f\u008d\3\2\2\2\u0090\u0092\7\17\2\2\u0091\u0090\3\2\2\2\u0091"+ - "\u0092\3\2\2\2\u0092\u0093\3\2\2\2\u0093\u0094\7\f\2\2\u0094\u0095\3\2"+ - "\2\2\u0095\u0096\b\13\2\2\u0096\26\3\2\2\2\u0097\u0098\7\61\2\2\u0098"+ - "\u0099\7,\2\2\u0099\u009d\3\2\2\2\u009a\u009c\13\2\2\2\u009b\u009a\3\2"+ - "\2\2\u009c\u009f\3\2\2\2\u009d\u009e\3\2\2\2\u009d\u009b\3\2\2\2\u009e"+ - "\u00a0\3\2\2\2\u009f\u009d\3\2\2\2\u00a0\u00a1\7,\2\2\u00a1\u00a2\7\61"+ - "\2\2\u00a2\u00a3\3\2\2\2\u00a3\u00a4\b\f\2\2\u00a4\30\3\2\2\2\31\2\36"+ - "&.\608@BINUZ]afjqvx\u0081\u008d\u0091\u009d\3\b\2\2"; - 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); - } - } -} \ No newline at end of file diff --git a/src/.antlr/SysYLexer.tokens b/src/.antlr/SysYLexer.tokens deleted file mode 100644 index 600d554..0000000 --- a/src/.antlr/SysYLexer.tokens +++ /dev/null @@ -1,8 +0,0 @@ -Comma=1 -IntLiteral=2 -FloatLiteral=3 -STRING=4 -WS=5 -LINE_COMMENT=6 -COMMENT=7 -','=1 diff --git a/src/.antlr/SysYParser.java b/src/.antlr/SysYParser.java deleted file mode 100644 index 3fb6582..0000000 --- a/src/.antlr/SysYParser.java +++ /dev/null @@ -1,264 +0,0 @@ -// Generated from /home/xsu/workspace/sysy/sysy/src/SysY.g4 by ANTLR 4.9.2 -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"}) -public class SysYParser extends Parser { - static { RuntimeMetaData.checkVersion("4.9.2", RuntimeMetaData.VERSION); } - - protected static final DFA[] _decisionToDFA; - protected static final PredictionContextCache _sharedContextCache = - new PredictionContextCache(); - public static final int - Comma=1, IntLiteral=2, FloatLiteral=3, STRING=4, WS=5, LINE_COMMENT=6, - COMMENT=7; - public static final int - RULE_funcRParams = 0, RULE_funcRParam = 1, RULE_number = 2; - private static String[] makeRuleNames() { - return new String[] { - "funcRParams", "funcRParam", "number" - }; - } - public static final String[] ruleNames = makeRuleNames(); - - private static String[] makeLiteralNames() { - return new String[] { - null, "','" - }; - } - private static final String[] _LITERAL_NAMES = makeLiteralNames(); - private static String[] makeSymbolicNames() { - return new String[] { - null, "Comma", "IntLiteral", "FloatLiteral", "STRING", "WS", "LINE_COMMENT", - "COMMENT" - }; - } - 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] = ""; - } - } - } - - @Override - @Deprecated - public String[] getTokenNames() { - return tokenNames; - } - - @Override - - public Vocabulary getVocabulary() { - return VOCABULARY; - } - - @Override - public String getGrammarFileName() { return "SysY.g4"; } - - @Override - public String[] getRuleNames() { return ruleNames; } - - @Override - public String getSerializedATN() { return _serializedATN; } - - @Override - public ATN getATN() { return _ATN; } - - public SysYParser(TokenStream input) { - super(input); - _interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache); - } - - public static class FuncRParamsContext extends ParserRuleContext { - public List funcRParam() { - return getRuleContexts(FuncRParamContext.class); - } - public FuncRParamContext funcRParam(int i) { - return getRuleContext(FuncRParamContext.class,i); - } - public List Comma() { return getTokens(SysYParser.Comma); } - public TerminalNode Comma(int i) { - return getToken(SysYParser.Comma, i); - } - public FuncRParamsContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_funcRParams; } - } - - public final FuncRParamsContext funcRParams() throws RecognitionException { - FuncRParamsContext _localctx = new FuncRParamsContext(_ctx, getState()); - enterRule(_localctx, 0, RULE_funcRParams); - int _la; - try { - enterOuterAlt(_localctx, 1); - { - setState(6); - funcRParam(); - setState(11); - _errHandler.sync(this); - _la = _input.LA(1); - while (_la==Comma) { - { - { - setState(7); - match(Comma); - setState(8); - funcRParam(); - } - } - setState(13); - _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; - } - - public static class FuncRParamContext extends ParserRuleContext { - public FuncRParamContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_funcRParam; } - - public FuncRParamContext() { } - public void copyFrom(FuncRParamContext ctx) { - super.copyFrom(ctx); - } - } - public static class StringAsRParamContext extends FuncRParamContext { - public TerminalNode STRING() { return getToken(SysYParser.STRING, 0); } - public StringAsRParamContext(FuncRParamContext ctx) { copyFrom(ctx); } - } - public static class ExpAsRParamContext extends FuncRParamContext { - public NumberContext number() { - return getRuleContext(NumberContext.class,0); - } - public ExpAsRParamContext(FuncRParamContext ctx) { copyFrom(ctx); } - } - - public final FuncRParamContext funcRParam() throws RecognitionException { - FuncRParamContext _localctx = new FuncRParamContext(_ctx, getState()); - enterRule(_localctx, 2, RULE_funcRParam); - try { - setState(16); - _errHandler.sync(this); - switch (_input.LA(1)) { - case IntLiteral: - case FloatLiteral: - _localctx = new ExpAsRParamContext(_localctx); - enterOuterAlt(_localctx, 1); - { - setState(14); - number(); - } - break; - case STRING: - _localctx = new StringAsRParamContext(_localctx); - enterOuterAlt(_localctx, 2); - { - setState(15); - match(STRING); - } - 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 class NumberContext extends ParserRuleContext { - public TerminalNode IntLiteral() { return getToken(SysYParser.IntLiteral, 0); } - public TerminalNode FloatLiteral() { return getToken(SysYParser.FloatLiteral, 0); } - public NumberContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_number; } - } - - public final NumberContext number() throws RecognitionException { - NumberContext _localctx = new NumberContext(_ctx, getState()); - enterRule(_localctx, 4, RULE_number); - int _la; - try { - enterOuterAlt(_localctx, 1); - { - setState(18); - _la = _input.LA(1); - if ( !(_la==IntLiteral || _la==FloatLiteral) ) { - _errHandler.recoverInline(this); - } - else { - if ( _input.LA(1)==Token.EOF ) matchedEOF = true; - _errHandler.reportMatch(this); - consume(); - } - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static final String _serializedATN = - "\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\3\t\27\4\2\t\2\4\3"+ - "\t\3\4\4\t\4\3\2\3\2\3\2\7\2\f\n\2\f\2\16\2\17\13\2\3\3\3\3\5\3\23\n\3"+ - "\3\4\3\4\3\4\2\2\5\2\4\6\2\3\3\2\4\5\2\25\2\b\3\2\2\2\4\22\3\2\2\2\6\24"+ - "\3\2\2\2\b\r\5\4\3\2\t\n\7\3\2\2\n\f\5\4\3\2\13\t\3\2\2\2\f\17\3\2\2\2"+ - "\r\13\3\2\2\2\r\16\3\2\2\2\16\3\3\2\2\2\17\r\3\2\2\2\20\23\5\6\4\2\21"+ - "\23\7\6\2\2\22\20\3\2\2\2\22\21\3\2\2\2\23\5\3\2\2\2\24\25\t\2\2\2\25"+ - "\7\3\2\2\2\4\r\22"; - 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); - } - } -} \ No newline at end of file diff --git a/src/ASTPrinter.cpp b/src/ASTPrinter.cpp index 61cd69f..3ea7fbf 100644 --- a/src/ASTPrinter.cpp +++ b/src/ASTPrinter.cpp @@ -1,40 +1,29 @@ #include #include -#include using namespace std; -#include "SysYParser.h" #include "ASTPrinter.h" +#include "SysYParser.h" antlrcpp::Any ASTPrinter::visitNumber(SysYParser::NumberContext *ctx) { - if (auto iCtx = ctx->IntLiteral()) { - cout << iCtx->getText(); - } else if (auto fCtx = ctx->FloatLiteral()) { - cout << fCtx->getText(); - } + cout << ctx->IntConst()->getText(); return nullptr; } -antlrcpp::Any ASTPrinter::visitStringAsRParam(SysYParser::StringAsRParamContext *ctx) { - cout << ctx->getText(); +antlrcpp::Any ASTPrinter::visitString(SysYParser::StringContext *ctx) { + cout << ctx->String()->getText(); return nullptr; } -// antlrcpp::Any ASTPrinter::visitFuncRParam(SysYParser::FuncRParamContext *ctx) { -// if (auto exp = dynamic_cast(ctx)) -// return visitExpAsRParam(exp); -// else -// return visitStringAsRParam(static_cast(ctx)); -// } - -antlrcpp::Any ASTPrinter::visitFuncRParams(SysYParser::FuncRParamsContext *ctx) { +antlrcpp::Any +ASTPrinter::visitFuncRParams(SysYParser::FuncRParamsContext *ctx) { if (ctx->funcRParam().empty()) return nullptr; - ctx->funcRParam(0)->accept(this); auto numParams = ctx->funcRParam().size(); + ctx->funcRParam(0)->accept(this); for (int i = 1; i < numParams; ++i) { cout << ", "; ctx->funcRParam(i)->accept(this); } + cout << '\n'; return nullptr; } \ No newline at end of file diff --git a/src/ASTPrinter.h b/src/ASTPrinter.h index 1379c04..514340e 100644 --- a/src/ASTPrinter.h +++ b/src/ASTPrinter.h @@ -4,9 +4,9 @@ class ASTPrinter : public SysYBaseVisitor { public: - antlrcpp::Any visitFuncRParams(SysYParser::FuncRParamsContext *ctx) override; // antlrcpp::Any visitExpAsRParam(SysYParser::ExpAsRParamContext *ctx) override; - antlrcpp::Any visitStringAsRParam(SysYParser::StringAsRParamContext *ctx) override; +// antlrcpp::Any visitStringAsRParam(SysYParser::StringAsRParamContext *ctx) override; antlrcpp::Any visitNumber(SysYParser::NumberContext *ctx) override; + antlrcpp::Any visitString(SysYParser::StringContext *ctx) override; }; \ No newline at end of file diff --git a/src/SysY.g4 b/src/SysY.g4 index 787b0de..0f7790a 100644 --- a/src/SysY.g4 +++ b/src/SysY.g4 @@ -6,23 +6,16 @@ grammar SysY; Comma: ','; -IntLiteral: [0-9]+ | '0x' [0-9a-fA-F]+ | '0X' [0-9a-fA-F]+; +fragment Decimal: [0-9]; +fragment Octal: [0-7]; +fragment Heximal: [0-9a-fA-F]; +fragment NonZeroDecimal: [1-9]; -fragment HexadecimalDigits: - '0x' [0-9a-fA-F]+ - | '0X' [0-9a-fA-F]+; +IntConst: NonZeroDecimal Decimal* + | '0' Octal+ + | ('0x' | '0X') Heximal+; -fragment ExponentPart: [eE] [+-] [0-9]+; - -fragment FractionPart: [0-9]* '.' [0-9]+ | [0-9]+ '.'; - -FloatLiteral: - FractionPart (ExponentPart)? - | [0-9]+ ExponentPart - | (HexadecimalDigits)? '.' HexadecimalDigits - | HexadecimalDigits '.'; - -STRING: '"' (ESC | .)*? '"'; +String: '"' (ESC | .)*? '"'; fragment ESC: '\\"' | '\\\\'; @@ -35,8 +28,9 @@ COMMENT: '/*' .*? '*/' -> skip; /* Syntax rules */ /*===-------------------------------------------===*/ -funcRParams: funcRParam (Comma funcRParam)*; +funcRParams: funcRParam (Comma funcRParam)* EOF; -funcRParam: number # expAsRParam | STRING # stringAsRParam; +funcRParam: number # expAsRParam | string # stringAsRParam; -number: IntLiteral | FloatLiteral; +number: IntConst; +string: String; diff --git a/src/sysyc.cpp b/src/sysyc.cpp index 4c20466..b6bbc7a 100644 --- a/src/sysyc.cpp +++ b/src/sysyc.cpp @@ -18,7 +18,7 @@ int main(int argc, char **argv) { cerr << "Failed to open file " << argv[1]; return EXIT_FAILURE; } - ANTLRInputStream input("1,2,3",5); + ANTLRInputStream input(fin); SysYLexer lexer(&input); CommonTokenStream tokens(&lexer); SysYParser parser(&tokens);