diff --git a/.gitignore b/.gitignore index 81a5dc1..9c3e147 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ build/ -.antlr/ \ No newline at end of file +.antlr/ +*.log \ No newline at end of file diff --git a/Sysy.g4 b/Sysy.g4 index 52f5b53..8a3b45d 100644 --- a/Sysy.g4 +++ b/Sysy.g4 @@ -87,6 +87,40 @@ constExp: addExp; // 注:使用的 Ident 必须是常量 // -------- Terminals --------- +CONST: 'const'; +COMMA: ','; +SEMICOLON: ';'; +INT: 'int'; +LBRACKET: '['; +RBRACKET: ']'; +ASSIGN: '='; +LBRACE: '{'; +RBRACE: '}'; +LPAREN: '('; +RPAREN: ')'; +VOID: 'void'; +IF: 'if'; +ELSE: 'else'; +WHILE: 'while'; +BREAK: 'break'; +CONTINUE: 'continue'; +RETURN: 'return'; +ADD: '+'; +SUB: '-'; +NOT: '!'; +MUL: '*'; +DIV: '/'; +MOD: '%'; +LT: '<'; +GT: '>'; +LE: '<='; +GE: '>='; +EQ: '=='; +NE: '!='; +AND: '&&'; +OR: '||'; +DQUOTE: '"'; + IDENT: [_a-zA-Z] | [_a-zA-Z] [_a-zA-Z0-9]+; DECIMAL_CONST: [1-9] | [1-9] [0-9]+; @@ -110,40 +144,7 @@ fragment SChar: ~["\\\r\n] | EscapeSequence | '\\\n' // Added line - | '\\\r\n' ; // Added line + | '\\\r\n'; // Added line -StringLiteral: '"' (SChar+)? '"'; -// https://github.com/antlr/antlr4/blob/master/doc/lexer-rules.md - -CONST:'const'; -COMMA:','; -SEMICOLON:';'; -INT:'int'; -LBRACKET:'['; -RBRACKET:']'; -ASSING:'='; -LBRACE:'{'; -RBRACE:'}'; -LPAREN:'('; -RPAREN:')'; -VOID:'void'; -IF:'if'; -ELSE:'else'; -WHILE:'while'; -BREAK:'break'; -CONTINUE:'continue'; -RETURN:'return'; -ADD:'+'; -SUB:'-'; -NOT:'!'; -MUL:'*'; -DIV:'/'; -MOD:'%'; -LT:'<'; -GT:'>'; -LE:'<='; -GE:'>='; -EQ:'=='; -NE:'!='; -AND:'&&'; -OR:'||'; +StringLiteral: DQUOTE (SChar+)? DQUOTE; +// https://github.com/antlr/antlr4/blob/master/doc/lexer-rules.md \ No newline at end of file diff --git a/include/antlrgen/SysyLexer.h b/include/antlrgen/SysyLexer.h index 4b2dada..e1606f1 100644 --- a/include/antlrgen/SysyLexer.h +++ b/include/antlrgen/SysyLexer.h @@ -13,13 +13,13 @@ namespace antlrSysY { class SysyLexer : public antlr4::Lexer { public: enum { - IDENT = 1, DECIMAL_CONST = 2, OCTAL_CONST = 3, HEXADECIMAL_CONST = 4, - WS = 5, SINGLELINE_COMMENT = 6, MULTILINE_COMMENT = 7, StringLiteral = 8, - CONST = 9, COMMA = 10, SEMICOLON = 11, INT = 12, LBRACKET = 13, RBRACKET = 14, - ASSING = 15, LBRACE = 16, RBRACE = 17, LPAREN = 18, RPAREN = 19, VOID = 20, - IF = 21, ELSE = 22, WHILE = 23, BREAK = 24, CONTINUE = 25, RETURN = 26, - ADD = 27, SUB = 28, NOT = 29, MUL = 30, DIV = 31, MOD = 32, LT = 33, - GT = 34, LE = 35, GE = 36, EQ = 37, NE = 38, AND = 39, OR = 40 + CONST = 1, COMMA = 2, SEMICOLON = 3, INT = 4, LBRACKET = 5, RBRACKET = 6, + ASSIGN = 7, LBRACE = 8, RBRACE = 9, LPAREN = 10, RPAREN = 11, VOID = 12, + IF = 13, ELSE = 14, WHILE = 15, BREAK = 16, CONTINUE = 17, RETURN = 18, + ADD = 19, SUB = 20, NOT = 21, MUL = 22, DIV = 23, MOD = 24, LT = 25, + GT = 26, LE = 27, GE = 28, EQ = 29, NE = 30, AND = 31, OR = 32, DQUOTE = 33, + IDENT = 34, DECIMAL_CONST = 35, OCTAL_CONST = 36, HEXADECIMAL_CONST = 37, + WS = 38, SINGLELINE_COMMENT = 39, MULTILINE_COMMENT = 40, StringLiteral = 41 }; explicit SysyLexer(antlr4::CharStream *input); diff --git a/include/antlrgen/SysyParser.h b/include/antlrgen/SysyParser.h index 4e3acb0..63beae7 100644 --- a/include/antlrgen/SysyParser.h +++ b/include/antlrgen/SysyParser.h @@ -13,13 +13,13 @@ namespace antlrSysY { class SysyParser : public antlr4::Parser { public: enum { - IDENT = 1, DECIMAL_CONST = 2, OCTAL_CONST = 3, HEXADECIMAL_CONST = 4, - WS = 5, SINGLELINE_COMMENT = 6, MULTILINE_COMMENT = 7, StringLiteral = 8, - CONST = 9, COMMA = 10, SEMICOLON = 11, INT = 12, LBRACKET = 13, RBRACKET = 14, - ASSING = 15, LBRACE = 16, RBRACE = 17, LPAREN = 18, RPAREN = 19, VOID = 20, - IF = 21, ELSE = 22, WHILE = 23, BREAK = 24, CONTINUE = 25, RETURN = 26, - ADD = 27, SUB = 28, NOT = 29, MUL = 30, DIV = 31, MOD = 32, LT = 33, - GT = 34, LE = 35, GE = 36, EQ = 37, NE = 38, AND = 39, OR = 40 + CONST = 1, COMMA = 2, SEMICOLON = 3, INT = 4, LBRACKET = 5, RBRACKET = 6, + ASSIGN = 7, LBRACE = 8, RBRACE = 9, LPAREN = 10, RPAREN = 11, VOID = 12, + IF = 13, ELSE = 14, WHILE = 15, BREAK = 16, CONTINUE = 17, RETURN = 18, + ADD = 19, SUB = 20, NOT = 21, MUL = 22, DIV = 23, MOD = 24, LT = 25, + GT = 26, LE = 27, GE = 28, EQ = 29, NE = 30, AND = 31, OR = 32, DQUOTE = 33, + IDENT = 34, DECIMAL_CONST = 35, OCTAL_CONST = 36, HEXADECIMAL_CONST = 37, + WS = 38, SINGLELINE_COMMENT = 39, MULTILINE_COMMENT = 40, StringLiteral = 41 }; enum { @@ -166,7 +166,7 @@ public: ConstDefContext(antlr4::ParserRuleContext *parent, size_t invokingState); virtual size_t getRuleIndex() const override; antlr4::tree::TerminalNode *IDENT(); - antlr4::tree::TerminalNode *ASSING(); + antlr4::tree::TerminalNode *ASSIGN(); ConstInitValContext *constInitVal(); std::vector LBRACKET(); antlr4::tree::TerminalNode* LBRACKET(size_t i); @@ -196,8 +196,7 @@ public: virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; - public: - std::vector arrDim; + }; ConstInitValContext* constInitVal(); @@ -231,7 +230,7 @@ public: ConstExpContext* constExp(size_t i); std::vector RBRACKET(); antlr4::tree::TerminalNode* RBRACKET(size_t i); - antlr4::tree::TerminalNode *ASSING(); + antlr4::tree::TerminalNode *ASSIGN(); InitValContext *initVal(); @@ -413,7 +412,7 @@ public: AssignStmtContext(StmtContext *ctx); LValContext *lVal(); - antlr4::tree::TerminalNode *ASSING(); + antlr4::tree::TerminalNode *ASSIGN(); ExpContext *exp(); antlr4::tree::TerminalNode *SEMICOLON(); diff --git a/include/common.h b/include/common.h new file mode 100644 index 0000000..ca0390f --- /dev/null +++ b/include/common.h @@ -0,0 +1,43 @@ +#pragma once +#include "3rdparty/easylogging++.h" + +#include +#include +#include +#include +#include + +#define panic(message) \ + do { \ + throw GrammarException(__FILE__, __LINE__, message); \ + } while (0) + +#define sysy_assert(cond) \ + do { \ + if (!(cond)) \ + GrammarException(__FILE__, __LINE__, #cond); \ + } while (0) + +namespace antlrSysY { + +class GrammarException : public std::exception { +public: + GrammarException() : message("Unknown Grammar Exception") {} + GrammarException(const std::string &what_arg) : message(what_arg){}; + GrammarException(const char *what_arg) : message(what_arg){}; + GrammarException(const char *filename, int line, + const std::string &what_arg) { + std::stringstream ss; + ss << filename << ":" << line << ": " << what_arg; + ss >> message; + }; + + virtual const char *what() const noexcept { + return message.c_str(); + } + +private: + std::string message; +}; + +} // namespace antlrSysY \ No newline at end of file diff --git a/include/llir_type.h b/include/llir_type.h new file mode 100644 index 0000000..f8790d8 --- /dev/null +++ b/include/llir_type.h @@ -0,0 +1,13 @@ +#pragma once + +namespace antlrSysY { + +enum class Type { + IntegerType, + FunctionType, + ArrayType, + PointerType, + VectorType, +}; + +} // namespace antlrSysY \ No newline at end of file diff --git a/include/llir_value.h b/include/llir_value.h new file mode 100644 index 0000000..1071c9a --- /dev/null +++ b/include/llir_value.h @@ -0,0 +1,31 @@ +#pragma once + +#include +#include + +#include "llir_type.h" + +namespace antlrSysY { +class Value { +public: + std::string name; + Type type; + Value(const std::string &name, const Type &type) : name(name), type(type) {} + virtual ~Value() = default; +}; + +class Function : public Value {}; + +class BasicBlock : public Value {}; + +class ConstantInt : public Value { +public: + int value; + int is_bool; // bool 0 or int 1 + ConstantInt(const std::string &name, int value, int is_bool) + : Value(name, Type::IntegerType), value(value), is_bool(is_bool) {} +}; + +class ConstantArr : public Value {}; + +} // namespace antlrSysY \ No newline at end of file diff --git a/include/scopetable.h b/include/scopetable.h new file mode 100644 index 0000000..b8b99d3 --- /dev/null +++ b/include/scopetable.h @@ -0,0 +1,56 @@ +#pragma once +#include "common.h" + +namespace antlrSysY { +template class ScopeTable { + + typedef std::map ScopeTableEntry_t; + +private: + std::vector _scope_list; + +public: + // On init, there is already an empty scope + ScopeTable() { + _scope_list.push_back(ScopeTableEntry_t()); + } + ~ScopeTable() {} + + void enter_scope() { + _scope_list.push_back(ScopeTableEntry_t()); + }; + + void leave_scope() { + if (_scope_list.size() <= 1) + throw GrammarException("Unable to leave global scope"); + _scope_list.pop_back(); + }; + + void push_name(const std::string &name, const T_V &value) { + auto ¤t_scope = _scope_list.back(); + + if (current_scope.count(name)) + throw GrammarException("Duplicate name in current scope"); + current_scope[name] = value; + }; + + std::optional get_name(const std::string &name) { + for (auto i = _scope_list.size() - 1; i >= 0; --i) { + if (_scope_list[i].count(name)) { + return {_scope_list[i][name]}; + } + } + return {}; + }; + + std::optional get_name(const std::string &name, int level) { + if (_scope_list[level].count(name)) { + return {_scope_list[level][name]}; + } + return {}; + }; + int get_level() const { + return _scope_list.size() - 1; + } +}; +} \ No newline at end of file diff --git a/include/visitor.h b/include/visitor.h new file mode 100644 index 0000000..b166bf5 --- /dev/null +++ b/include/visitor.h @@ -0,0 +1,80 @@ +#pragma once +#include "3rdparty/easylogging++.h" +#include "antlrgen/SysyBaseVisitor.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "antlrgen/SysyLexer.h" +#include "antlrgen/SysyParser.h" +#include "common.h" +#include "llir_value.h" +#include "scopetable.h" + +namespace antlrSysY { + +class Visitor : public antlrSysY::SysyBaseVisitor { +private: + struct VisitorState { + + bool isConstInt = false; + }; + +private: + ScopeTable> _scope_tab; + VisitorState _state = {}; + std::map token_type_map; + +public: + Visitor(SysyLexer &lexer) { + for (auto item : lexer.getTokenTypeMap()) { + token_type_map[std::string(item.first)] = item.second; + } + } + std::any visitProgram(SysyParser::ProgramContext *ctx) override { + // before visiting, we add some lib functions + return this->SysyBaseVisitor::visitProgram(ctx); + } + + std::any visitCompUnit(SysyParser::CompUnitContext *ctx) override { + return this->visitChildren(ctx); + } + + std::any visitDecl(SysyParser::DeclContext *ctx) override { + return this->visitChildren(ctx); + } + + std::any visitConstDecl(SysyParser::ConstDeclContext *ctx) override; + + // constDef : IDENT ('[' constExp ']')* '=' constInitVal ';' + std::any visitConstDef(SysyParser::ConstDefContext *ctx) override; + + std::any visitConstInitVal(SysyParser::ConstInitValContext *ctx) override; + + std::any visitConstExp(SysyParser::ConstExpContext *ctx) override; + // addExp: mulExp | addExp ('+' | '-') mulExp; + std::any visitAddExp(SysyParser::AddExpContext *ctx) override; + + std::any visitMulExp(SysyParser::MulExpContext *ctx) override; + + // unaryExp: primaryExp | IDENT '(' (funcRParams)? ')' | unaryOp unaryExp; + std::any visitUnaryExp(SysyParser::UnaryExpContext *ctx) override; + + // primaryExp: ('(' exp ')') | lVal | number; + std::any visitPrimaryExp(SysyParser::PrimaryExpContext *ctx) override; + + // std::any visitExp(SysyParser::ExpContext *ctx) override { } + + std::any visitNumber(SysyParser::NumberContext *ctx) override; + + std::any visitIntConst(SysyParser::IntConstContext *ctx) override; + + std::any visitLVal(SysyParser::LValContext *) override; +}; + +} // namespace antlrSysY \ No newline at end of file diff --git a/scripts/antlr4-gen.sh b/scripts/antlr4-gen.sh index 4214116..be4afd2 100755 --- a/scripts/antlr4-gen.sh +++ b/scripts/antlr4-gen.sh @@ -4,6 +4,7 @@ mkdir -p build/antlr-gen mkdir -p include mkdir -p src rm -fv build/antlr-gen/* +cp $filename build/antlr-gen/ java -jar ./tools/antlr-4.12.0-complete.jar -no-listener -visitor -Dlanguage=Cpp -package antlrSysY -o build/antlr-gen $filename mkdir -p src/antlrgen mkdir -p include/antlrgen diff --git a/src/antlrgen/SysyLexer.cpp b/src/antlrgen/SysyLexer.cpp index 61cdff4..7429cbf 100644 --- a/src/antlrgen/SysyLexer.cpp +++ b/src/antlrgen/SysyLexer.cpp @@ -49,13 +49,13 @@ void sysylexerLexerInitialize() { assert(sysylexerLexerStaticData == nullptr); auto staticData = std::make_unique( std::vector{ + "CONST", "COMMA", "SEMICOLON", "INT", "LBRACKET", "RBRACKET", "ASSIGN", + "LBRACE", "RBRACE", "LPAREN", "RPAREN", "VOID", "IF", "ELSE", "WHILE", + "BREAK", "CONTINUE", "RETURN", "ADD", "SUB", "NOT", "MUL", "DIV", + "MOD", "LT", "GT", "LE", "GE", "EQ", "NE", "AND", "OR", "DQUOTE", "IDENT", "DECIMAL_CONST", "OCTAL_CONST", "HEXADECIMAL_CONST", "WS", "SINGLELINE_COMMENT", "MULTILINE_COMMENT", "EscapeSequence", "SChar", - "StringLiteral", "CONST", "COMMA", "SEMICOLON", "INT", "LBRACKET", - "RBRACKET", "ASSING", "LBRACE", "RBRACE", "LPAREN", "RPAREN", "VOID", - "IF", "ELSE", "WHILE", "BREAK", "CONTINUE", "RETURN", "ADD", "SUB", - "NOT", "MUL", "DIV", "MOD", "LT", "GT", "LE", "GE", "EQ", "NE", "AND", - "OR" + "StringLiteral" }, std::vector{ "DEFAULT_TOKEN_CHANNEL", "HIDDEN" @@ -64,123 +64,124 @@ void sysylexerLexerInitialize() { "DEFAULT_MODE" }, std::vector{ - "", "", "", "", "", "", "", "", "", "'const'", "','", "';'", "'int'", - "'['", "']'", "'='", "'{'", "'}'", "'('", "')'", "'void'", "'if'", - "'else'", "'while'", "'break'", "'continue'", "'return'", "'+'", "'-'", - "'!'", "'*'", "'/'", "'%'", "'<'", "'>'", "'<='", "'>='", "'=='", - "'!='", "'&&'", "'||'" + "", "'const'", "','", "';'", "'int'", "'['", "']'", "'='", "'{'", + "'}'", "'('", "')'", "'void'", "'if'", "'else'", "'while'", "'break'", + "'continue'", "'return'", "'+'", "'-'", "'!'", "'*'", "'/'", "'%'", + "'<'", "'>'", "'<='", "'>='", "'=='", "'!='", "'&&'", "'||'", "'\"'" }, std::vector{ - "", "IDENT", "DECIMAL_CONST", "OCTAL_CONST", "HEXADECIMAL_CONST", - "WS", "SINGLELINE_COMMENT", "MULTILINE_COMMENT", "StringLiteral", - "CONST", "COMMA", "SEMICOLON", "INT", "LBRACKET", "RBRACKET", "ASSING", - "LBRACE", "RBRACE", "LPAREN", "RPAREN", "VOID", "IF", "ELSE", "WHILE", - "BREAK", "CONTINUE", "RETURN", "ADD", "SUB", "NOT", "MUL", "DIV", - "MOD", "LT", "GT", "LE", "GE", "EQ", "NE", "AND", "OR" + "", "CONST", "COMMA", "SEMICOLON", "INT", "LBRACKET", "RBRACKET", + "ASSIGN", "LBRACE", "RBRACE", "LPAREN", "RPAREN", "VOID", "IF", "ELSE", + "WHILE", "BREAK", "CONTINUE", "RETURN", "ADD", "SUB", "NOT", "MUL", + "DIV", "MOD", "LT", "GT", "LE", "GE", "EQ", "NE", "AND", "OR", "DQUOTE", + "IDENT", "DECIMAL_CONST", "OCTAL_CONST", "HEXADECIMAL_CONST", "WS", + "SINGLELINE_COMMENT", "MULTILINE_COMMENT", "StringLiteral" } ); static const int32_t serializedATNSegment[] = { - 4,0,40,297,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7, + 4,0,41,301,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7, 6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,13,7,13,2,14, 7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7,19,2,20,7,20,2,21, 7,21,2,22,7,22,2,23,7,23,2,24,7,24,2,25,7,25,2,26,7,26,2,27,7,27,2,28, 7,28,2,29,7,29,2,30,7,30,2,31,7,31,2,32,7,32,2,33,7,33,2,34,7,34,2,35, - 7,35,2,36,7,36,2,37,7,37,2,38,7,38,2,39,7,39,2,40,7,40,2,41,7,41,1,0, - 1,0,1,0,4,0,89,8,0,11,0,12,0,90,3,0,93,8,0,1,1,1,1,1,1,4,1,98,8,1,11, - 1,12,1,99,3,1,102,8,1,1,2,1,2,1,2,4,2,107,8,2,11,2,12,2,108,3,2,111,8, - 2,1,3,1,3,1,3,1,3,3,3,117,8,3,1,3,4,3,120,8,3,11,3,12,3,121,1,4,4,4,125, - 8,4,11,4,12,4,126,1,4,1,4,1,5,1,5,1,5,1,5,5,5,135,8,5,10,5,12,5,138,9, - 5,1,5,1,5,1,6,1,6,1,6,1,6,5,6,146,8,6,10,6,12,6,149,9,6,1,6,1,6,1,6,1, - 6,1,6,1,7,1,7,1,7,1,7,1,7,3,7,161,8,7,1,7,3,7,164,8,7,1,7,1,7,1,7,1,7, - 4,7,170,8,7,11,7,12,7,171,3,7,174,8,7,1,8,1,8,1,8,1,8,1,8,1,8,1,8,3,8, - 183,8,8,1,9,1,9,4,9,187,8,9,11,9,12,9,188,3,9,191,8,9,1,9,1,9,1,10,1, - 10,1,10,1,10,1,10,1,10,1,11,1,11,1,12,1,12,1,13,1,13,1,13,1,13,1,14,1, - 14,1,15,1,15,1,16,1,16,1,17,1,17,1,18,1,18,1,19,1,19,1,20,1,20,1,21,1, - 21,1,21,1,21,1,21,1,22,1,22,1,22,1,23,1,23,1,23,1,23,1,23,1,24,1,24,1, - 24,1,24,1,24,1,24,1,25,1,25,1,25,1,25,1,25,1,25,1,26,1,26,1,26,1,26,1, - 26,1,26,1,26,1,26,1,26,1,27,1,27,1,27,1,27,1,27,1,27,1,27,1,28,1,28,1, - 29,1,29,1,30,1,30,1,31,1,31,1,32,1,32,1,33,1,33,1,34,1,34,1,35,1,35,1, - 36,1,36,1,36,1,37,1,37,1,37,1,38,1,38,1,38,1,39,1,39,1,39,1,40,1,40,1, - 40,1,41,1,41,1,41,1,147,0,42,1,1,3,2,5,3,7,4,9,5,11,6,13,7,15,0,17,0, - 19,8,21,9,23,10,25,11,27,12,29,13,31,14,33,15,35,16,37,17,39,18,41,19, - 43,20,45,21,47,22,49,23,51,24,53,25,55,26,57,27,59,28,61,29,63,30,65, - 31,67,32,69,33,71,34,73,35,75,36,77,37,79,38,81,39,83,40,1,0,10,3,0,65, - 90,95,95,97,122,4,0,48,57,65,90,95,95,97,122,1,0,49,57,1,0,48,57,1,0, - 48,55,3,0,48,57,65,70,97,102,3,0,9,10,13,13,32,32,2,0,10,10,13,13,10, - 0,34,34,39,39,63,63,92,92,97,98,102,102,110,110,114,114,116,116,118,118, - 4,0,10,10,13,13,34,34,92,92,315,0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0, - 7,1,0,0,0,0,9,1,0,0,0,0,11,1,0,0,0,0,13,1,0,0,0,0,19,1,0,0,0,0,21,1,0, + 7,35,2,36,7,36,2,37,7,37,2,38,7,38,2,39,7,39,2,40,7,40,2,41,7,41,2,42, + 7,42,1,0,1,0,1,0,1,0,1,0,1,0,1,1,1,1,1,2,1,2,1,3,1,3,1,3,1,3,1,4,1,4, + 1,5,1,5,1,6,1,6,1,7,1,7,1,8,1,8,1,9,1,9,1,10,1,10,1,11,1,11,1,11,1,11, + 1,11,1,12,1,12,1,12,1,13,1,13,1,13,1,13,1,13,1,14,1,14,1,14,1,14,1,14, + 1,14,1,15,1,15,1,15,1,15,1,15,1,15,1,16,1,16,1,16,1,16,1,16,1,16,1,16, + 1,16,1,16,1,17,1,17,1,17,1,17,1,17,1,17,1,17,1,18,1,18,1,19,1,19,1,20, + 1,20,1,21,1,21,1,22,1,22,1,23,1,23,1,24,1,24,1,25,1,25,1,26,1,26,1,26, + 1,27,1,27,1,27,1,28,1,28,1,28,1,29,1,29,1,29,1,30,1,30,1,30,1,31,1,31, + 1,31,1,32,1,32,1,33,1,33,1,33,4,33,196,8,33,11,33,12,33,197,3,33,200, + 8,33,1,34,1,34,1,34,4,34,205,8,34,11,34,12,34,206,3,34,209,8,34,1,35, + 1,35,1,35,4,35,214,8,35,11,35,12,35,215,3,35,218,8,35,1,36,1,36,1,36, + 1,36,3,36,224,8,36,1,36,4,36,227,8,36,11,36,12,36,228,1,37,4,37,232,8, + 37,11,37,12,37,233,1,37,1,37,1,38,1,38,1,38,1,38,5,38,242,8,38,10,38, + 12,38,245,9,38,1,38,1,38,1,39,1,39,1,39,1,39,5,39,253,8,39,10,39,12,39, + 256,9,39,1,39,1,39,1,39,1,39,1,39,1,40,1,40,1,40,1,40,1,40,3,40,268,8, + 40,1,40,3,40,271,8,40,1,40,1,40,1,40,1,40,4,40,277,8,40,11,40,12,40,278, + 3,40,281,8,40,1,41,1,41,1,41,1,41,1,41,1,41,1,41,3,41,290,8,41,1,42,1, + 42,4,42,294,8,42,11,42,12,42,295,3,42,298,8,42,1,42,1,42,1,254,0,43,1, + 1,3,2,5,3,7,4,9,5,11,6,13,7,15,8,17,9,19,10,21,11,23,12,25,13,27,14,29, + 15,31,16,33,17,35,18,37,19,39,20,41,21,43,22,45,23,47,24,49,25,51,26, + 53,27,55,28,57,29,59,30,61,31,63,32,65,33,67,34,69,35,71,36,73,37,75, + 38,77,39,79,40,81,0,83,0,85,41,1,0,10,3,0,65,90,95,95,97,122,4,0,48,57, + 65,90,95,95,97,122,1,0,49,57,1,0,48,57,1,0,48,55,3,0,48,57,65,70,97,102, + 3,0,9,10,13,13,32,32,2,0,10,10,13,13,10,0,34,34,39,39,63,63,92,92,97, + 98,102,102,110,110,114,114,116,116,118,118,4,0,10,10,13,13,34,34,92,92, + 319,0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,0,0,0,9,1,0,0,0,0,11, + 1,0,0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,17,1,0,0,0,0,19,1,0,0,0,0,21,1,0, 0,0,0,23,1,0,0,0,0,25,1,0,0,0,0,27,1,0,0,0,0,29,1,0,0,0,0,31,1,0,0,0, 0,33,1,0,0,0,0,35,1,0,0,0,0,37,1,0,0,0,0,39,1,0,0,0,0,41,1,0,0,0,0,43, 1,0,0,0,0,45,1,0,0,0,0,47,1,0,0,0,0,49,1,0,0,0,0,51,1,0,0,0,0,53,1,0, 0,0,0,55,1,0,0,0,0,57,1,0,0,0,0,59,1,0,0,0,0,61,1,0,0,0,0,63,1,0,0,0, 0,65,1,0,0,0,0,67,1,0,0,0,0,69,1,0,0,0,0,71,1,0,0,0,0,73,1,0,0,0,0,75, - 1,0,0,0,0,77,1,0,0,0,0,79,1,0,0,0,0,81,1,0,0,0,0,83,1,0,0,0,1,92,1,0, - 0,0,3,101,1,0,0,0,5,110,1,0,0,0,7,116,1,0,0,0,9,124,1,0,0,0,11,130,1, - 0,0,0,13,141,1,0,0,0,15,173,1,0,0,0,17,182,1,0,0,0,19,184,1,0,0,0,21, - 194,1,0,0,0,23,200,1,0,0,0,25,202,1,0,0,0,27,204,1,0,0,0,29,208,1,0,0, - 0,31,210,1,0,0,0,33,212,1,0,0,0,35,214,1,0,0,0,37,216,1,0,0,0,39,218, - 1,0,0,0,41,220,1,0,0,0,43,222,1,0,0,0,45,227,1,0,0,0,47,230,1,0,0,0,49, - 235,1,0,0,0,51,241,1,0,0,0,53,247,1,0,0,0,55,256,1,0,0,0,57,263,1,0,0, - 0,59,265,1,0,0,0,61,267,1,0,0,0,63,269,1,0,0,0,65,271,1,0,0,0,67,273, - 1,0,0,0,69,275,1,0,0,0,71,277,1,0,0,0,73,279,1,0,0,0,75,282,1,0,0,0,77, - 285,1,0,0,0,79,288,1,0,0,0,81,291,1,0,0,0,83,294,1,0,0,0,85,93,7,0,0, - 0,86,88,7,0,0,0,87,89,7,1,0,0,88,87,1,0,0,0,89,90,1,0,0,0,90,88,1,0,0, - 0,90,91,1,0,0,0,91,93,1,0,0,0,92,85,1,0,0,0,92,86,1,0,0,0,93,2,1,0,0, - 0,94,102,7,2,0,0,95,97,7,2,0,0,96,98,7,3,0,0,97,96,1,0,0,0,98,99,1,0, - 0,0,99,97,1,0,0,0,99,100,1,0,0,0,100,102,1,0,0,0,101,94,1,0,0,0,101,95, - 1,0,0,0,102,4,1,0,0,0,103,111,5,48,0,0,104,106,5,48,0,0,105,107,7,4,0, - 0,106,105,1,0,0,0,107,108,1,0,0,0,108,106,1,0,0,0,108,109,1,0,0,0,109, - 111,1,0,0,0,110,103,1,0,0,0,110,104,1,0,0,0,111,6,1,0,0,0,112,113,5,48, - 0,0,113,117,5,120,0,0,114,115,5,48,0,0,115,117,5,88,0,0,116,112,1,0,0, - 0,116,114,1,0,0,0,117,119,1,0,0,0,118,120,7,5,0,0,119,118,1,0,0,0,120, - 121,1,0,0,0,121,119,1,0,0,0,121,122,1,0,0,0,122,8,1,0,0,0,123,125,7,6, - 0,0,124,123,1,0,0,0,125,126,1,0,0,0,126,124,1,0,0,0,126,127,1,0,0,0,127, - 128,1,0,0,0,128,129,6,4,0,0,129,10,1,0,0,0,130,131,5,47,0,0,131,132,5, - 47,0,0,132,136,1,0,0,0,133,135,8,7,0,0,134,133,1,0,0,0,135,138,1,0,0, - 0,136,134,1,0,0,0,136,137,1,0,0,0,137,139,1,0,0,0,138,136,1,0,0,0,139, - 140,6,5,0,0,140,12,1,0,0,0,141,142,5,47,0,0,142,143,5,42,0,0,143,147, - 1,0,0,0,144,146,9,0,0,0,145,144,1,0,0,0,146,149,1,0,0,0,147,148,1,0,0, - 0,147,145,1,0,0,0,148,150,1,0,0,0,149,147,1,0,0,0,150,151,5,42,0,0,151, - 152,5,47,0,0,152,153,1,0,0,0,153,154,6,6,0,0,154,14,1,0,0,0,155,156,5, - 92,0,0,156,174,7,8,0,0,157,158,5,92,0,0,158,160,7,4,0,0,159,161,7,4,0, - 0,160,159,1,0,0,0,160,161,1,0,0,0,161,163,1,0,0,0,162,164,7,4,0,0,163, - 162,1,0,0,0,163,164,1,0,0,0,164,174,1,0,0,0,165,166,5,92,0,0,166,167, - 5,120,0,0,167,169,1,0,0,0,168,170,7,5,0,0,169,168,1,0,0,0,170,171,1,0, - 0,0,171,169,1,0,0,0,171,172,1,0,0,0,172,174,1,0,0,0,173,155,1,0,0,0,173, - 157,1,0,0,0,173,165,1,0,0,0,174,16,1,0,0,0,175,183,8,9,0,0,176,183,3, - 15,7,0,177,178,5,92,0,0,178,183,5,10,0,0,179,180,5,92,0,0,180,181,5,13, - 0,0,181,183,5,10,0,0,182,175,1,0,0,0,182,176,1,0,0,0,182,177,1,0,0,0, - 182,179,1,0,0,0,183,18,1,0,0,0,184,190,5,34,0,0,185,187,3,17,8,0,186, - 185,1,0,0,0,187,188,1,0,0,0,188,186,1,0,0,0,188,189,1,0,0,0,189,191,1, - 0,0,0,190,186,1,0,0,0,190,191,1,0,0,0,191,192,1,0,0,0,192,193,5,34,0, - 0,193,20,1,0,0,0,194,195,5,99,0,0,195,196,5,111,0,0,196,197,5,110,0,0, - 197,198,5,115,0,0,198,199,5,116,0,0,199,22,1,0,0,0,200,201,5,44,0,0,201, - 24,1,0,0,0,202,203,5,59,0,0,203,26,1,0,0,0,204,205,5,105,0,0,205,206, - 5,110,0,0,206,207,5,116,0,0,207,28,1,0,0,0,208,209,5,91,0,0,209,30,1, - 0,0,0,210,211,5,93,0,0,211,32,1,0,0,0,212,213,5,61,0,0,213,34,1,0,0,0, - 214,215,5,123,0,0,215,36,1,0,0,0,216,217,5,125,0,0,217,38,1,0,0,0,218, - 219,5,40,0,0,219,40,1,0,0,0,220,221,5,41,0,0,221,42,1,0,0,0,222,223,5, - 118,0,0,223,224,5,111,0,0,224,225,5,105,0,0,225,226,5,100,0,0,226,44, - 1,0,0,0,227,228,5,105,0,0,228,229,5,102,0,0,229,46,1,0,0,0,230,231,5, - 101,0,0,231,232,5,108,0,0,232,233,5,115,0,0,233,234,5,101,0,0,234,48, - 1,0,0,0,235,236,5,119,0,0,236,237,5,104,0,0,237,238,5,105,0,0,238,239, - 5,108,0,0,239,240,5,101,0,0,240,50,1,0,0,0,241,242,5,98,0,0,242,243,5, - 114,0,0,243,244,5,101,0,0,244,245,5,97,0,0,245,246,5,107,0,0,246,52,1, - 0,0,0,247,248,5,99,0,0,248,249,5,111,0,0,249,250,5,110,0,0,250,251,5, - 116,0,0,251,252,5,105,0,0,252,253,5,110,0,0,253,254,5,117,0,0,254,255, - 5,101,0,0,255,54,1,0,0,0,256,257,5,114,0,0,257,258,5,101,0,0,258,259, - 5,116,0,0,259,260,5,117,0,0,260,261,5,114,0,0,261,262,5,110,0,0,262,56, - 1,0,0,0,263,264,5,43,0,0,264,58,1,0,0,0,265,266,5,45,0,0,266,60,1,0,0, - 0,267,268,5,33,0,0,268,62,1,0,0,0,269,270,5,42,0,0,270,64,1,0,0,0,271, - 272,5,47,0,0,272,66,1,0,0,0,273,274,5,37,0,0,274,68,1,0,0,0,275,276,5, - 60,0,0,276,70,1,0,0,0,277,278,5,62,0,0,278,72,1,0,0,0,279,280,5,60,0, - 0,280,281,5,61,0,0,281,74,1,0,0,0,282,283,5,62,0,0,283,284,5,61,0,0,284, - 76,1,0,0,0,285,286,5,61,0,0,286,287,5,61,0,0,287,78,1,0,0,0,288,289,5, - 33,0,0,289,290,5,61,0,0,290,80,1,0,0,0,291,292,5,38,0,0,292,293,5,38, - 0,0,293,82,1,0,0,0,294,295,5,124,0,0,295,296,5,124,0,0,296,84,1,0,0,0, - 19,0,90,92,99,101,108,110,116,121,126,136,147,160,163,171,173,182,188, - 190,1,6,0,0 + 1,0,0,0,0,77,1,0,0,0,0,79,1,0,0,0,0,85,1,0,0,0,1,87,1,0,0,0,3,93,1,0, + 0,0,5,95,1,0,0,0,7,97,1,0,0,0,9,101,1,0,0,0,11,103,1,0,0,0,13,105,1,0, + 0,0,15,107,1,0,0,0,17,109,1,0,0,0,19,111,1,0,0,0,21,113,1,0,0,0,23,115, + 1,0,0,0,25,120,1,0,0,0,27,123,1,0,0,0,29,128,1,0,0,0,31,134,1,0,0,0,33, + 140,1,0,0,0,35,149,1,0,0,0,37,156,1,0,0,0,39,158,1,0,0,0,41,160,1,0,0, + 0,43,162,1,0,0,0,45,164,1,0,0,0,47,166,1,0,0,0,49,168,1,0,0,0,51,170, + 1,0,0,0,53,172,1,0,0,0,55,175,1,0,0,0,57,178,1,0,0,0,59,181,1,0,0,0,61, + 184,1,0,0,0,63,187,1,0,0,0,65,190,1,0,0,0,67,199,1,0,0,0,69,208,1,0,0, + 0,71,217,1,0,0,0,73,223,1,0,0,0,75,231,1,0,0,0,77,237,1,0,0,0,79,248, + 1,0,0,0,81,280,1,0,0,0,83,289,1,0,0,0,85,291,1,0,0,0,87,88,5,99,0,0,88, + 89,5,111,0,0,89,90,5,110,0,0,90,91,5,115,0,0,91,92,5,116,0,0,92,2,1,0, + 0,0,93,94,5,44,0,0,94,4,1,0,0,0,95,96,5,59,0,0,96,6,1,0,0,0,97,98,5,105, + 0,0,98,99,5,110,0,0,99,100,5,116,0,0,100,8,1,0,0,0,101,102,5,91,0,0,102, + 10,1,0,0,0,103,104,5,93,0,0,104,12,1,0,0,0,105,106,5,61,0,0,106,14,1, + 0,0,0,107,108,5,123,0,0,108,16,1,0,0,0,109,110,5,125,0,0,110,18,1,0,0, + 0,111,112,5,40,0,0,112,20,1,0,0,0,113,114,5,41,0,0,114,22,1,0,0,0,115, + 116,5,118,0,0,116,117,5,111,0,0,117,118,5,105,0,0,118,119,5,100,0,0,119, + 24,1,0,0,0,120,121,5,105,0,0,121,122,5,102,0,0,122,26,1,0,0,0,123,124, + 5,101,0,0,124,125,5,108,0,0,125,126,5,115,0,0,126,127,5,101,0,0,127,28, + 1,0,0,0,128,129,5,119,0,0,129,130,5,104,0,0,130,131,5,105,0,0,131,132, + 5,108,0,0,132,133,5,101,0,0,133,30,1,0,0,0,134,135,5,98,0,0,135,136,5, + 114,0,0,136,137,5,101,0,0,137,138,5,97,0,0,138,139,5,107,0,0,139,32,1, + 0,0,0,140,141,5,99,0,0,141,142,5,111,0,0,142,143,5,110,0,0,143,144,5, + 116,0,0,144,145,5,105,0,0,145,146,5,110,0,0,146,147,5,117,0,0,147,148, + 5,101,0,0,148,34,1,0,0,0,149,150,5,114,0,0,150,151,5,101,0,0,151,152, + 5,116,0,0,152,153,5,117,0,0,153,154,5,114,0,0,154,155,5,110,0,0,155,36, + 1,0,0,0,156,157,5,43,0,0,157,38,1,0,0,0,158,159,5,45,0,0,159,40,1,0,0, + 0,160,161,5,33,0,0,161,42,1,0,0,0,162,163,5,42,0,0,163,44,1,0,0,0,164, + 165,5,47,0,0,165,46,1,0,0,0,166,167,5,37,0,0,167,48,1,0,0,0,168,169,5, + 60,0,0,169,50,1,0,0,0,170,171,5,62,0,0,171,52,1,0,0,0,172,173,5,60,0, + 0,173,174,5,61,0,0,174,54,1,0,0,0,175,176,5,62,0,0,176,177,5,61,0,0,177, + 56,1,0,0,0,178,179,5,61,0,0,179,180,5,61,0,0,180,58,1,0,0,0,181,182,5, + 33,0,0,182,183,5,61,0,0,183,60,1,0,0,0,184,185,5,38,0,0,185,186,5,38, + 0,0,186,62,1,0,0,0,187,188,5,124,0,0,188,189,5,124,0,0,189,64,1,0,0,0, + 190,191,5,34,0,0,191,66,1,0,0,0,192,200,7,0,0,0,193,195,7,0,0,0,194,196, + 7,1,0,0,195,194,1,0,0,0,196,197,1,0,0,0,197,195,1,0,0,0,197,198,1,0,0, + 0,198,200,1,0,0,0,199,192,1,0,0,0,199,193,1,0,0,0,200,68,1,0,0,0,201, + 209,7,2,0,0,202,204,7,2,0,0,203,205,7,3,0,0,204,203,1,0,0,0,205,206,1, + 0,0,0,206,204,1,0,0,0,206,207,1,0,0,0,207,209,1,0,0,0,208,201,1,0,0,0, + 208,202,1,0,0,0,209,70,1,0,0,0,210,218,5,48,0,0,211,213,5,48,0,0,212, + 214,7,4,0,0,213,212,1,0,0,0,214,215,1,0,0,0,215,213,1,0,0,0,215,216,1, + 0,0,0,216,218,1,0,0,0,217,210,1,0,0,0,217,211,1,0,0,0,218,72,1,0,0,0, + 219,220,5,48,0,0,220,224,5,120,0,0,221,222,5,48,0,0,222,224,5,88,0,0, + 223,219,1,0,0,0,223,221,1,0,0,0,224,226,1,0,0,0,225,227,7,5,0,0,226,225, + 1,0,0,0,227,228,1,0,0,0,228,226,1,0,0,0,228,229,1,0,0,0,229,74,1,0,0, + 0,230,232,7,6,0,0,231,230,1,0,0,0,232,233,1,0,0,0,233,231,1,0,0,0,233, + 234,1,0,0,0,234,235,1,0,0,0,235,236,6,37,0,0,236,76,1,0,0,0,237,238,5, + 47,0,0,238,239,5,47,0,0,239,243,1,0,0,0,240,242,8,7,0,0,241,240,1,0,0, + 0,242,245,1,0,0,0,243,241,1,0,0,0,243,244,1,0,0,0,244,246,1,0,0,0,245, + 243,1,0,0,0,246,247,6,38,0,0,247,78,1,0,0,0,248,249,5,47,0,0,249,250, + 5,42,0,0,250,254,1,0,0,0,251,253,9,0,0,0,252,251,1,0,0,0,253,256,1,0, + 0,0,254,255,1,0,0,0,254,252,1,0,0,0,255,257,1,0,0,0,256,254,1,0,0,0,257, + 258,5,42,0,0,258,259,5,47,0,0,259,260,1,0,0,0,260,261,6,39,0,0,261,80, + 1,0,0,0,262,263,5,92,0,0,263,281,7,8,0,0,264,265,5,92,0,0,265,267,7,4, + 0,0,266,268,7,4,0,0,267,266,1,0,0,0,267,268,1,0,0,0,268,270,1,0,0,0,269, + 271,7,4,0,0,270,269,1,0,0,0,270,271,1,0,0,0,271,281,1,0,0,0,272,273,5, + 92,0,0,273,274,5,120,0,0,274,276,1,0,0,0,275,277,7,5,0,0,276,275,1,0, + 0,0,277,278,1,0,0,0,278,276,1,0,0,0,278,279,1,0,0,0,279,281,1,0,0,0,280, + 262,1,0,0,0,280,264,1,0,0,0,280,272,1,0,0,0,281,82,1,0,0,0,282,290,8, + 9,0,0,283,290,3,81,40,0,284,285,5,92,0,0,285,290,5,10,0,0,286,287,5,92, + 0,0,287,288,5,13,0,0,288,290,5,10,0,0,289,282,1,0,0,0,289,283,1,0,0,0, + 289,284,1,0,0,0,289,286,1,0,0,0,290,84,1,0,0,0,291,297,3,65,32,0,292, + 294,3,83,41,0,293,292,1,0,0,0,294,295,1,0,0,0,295,293,1,0,0,0,295,296, + 1,0,0,0,296,298,1,0,0,0,297,293,1,0,0,0,297,298,1,0,0,0,298,299,1,0,0, + 0,299,300,3,65,32,0,300,86,1,0,0,0,19,0,197,199,206,208,215,217,223,228, + 233,243,254,267,270,278,280,289,295,297,1,6,0,0 }; staticData->serializedATN = antlr4::atn::SerializedATNView(serializedATNSegment, sizeof(serializedATNSegment) / sizeof(serializedATNSegment[0])); diff --git a/src/antlrgen/SysyParser.cpp b/src/antlrgen/SysyParser.cpp index 42f6c86..ab8a178 100644 --- a/src/antlrgen/SysyParser.cpp +++ b/src/antlrgen/SysyParser.cpp @@ -52,23 +52,22 @@ void sysyParserInitialize() { "constExp" }, std::vector{ - "", "", "", "", "", "", "", "", "", "'const'", "','", "';'", "'int'", - "'['", "']'", "'='", "'{'", "'}'", "'('", "')'", "'void'", "'if'", - "'else'", "'while'", "'break'", "'continue'", "'return'", "'+'", "'-'", - "'!'", "'*'", "'/'", "'%'", "'<'", "'>'", "'<='", "'>='", "'=='", - "'!='", "'&&'", "'||'" + "", "'const'", "','", "';'", "'int'", "'['", "']'", "'='", "'{'", + "'}'", "'('", "')'", "'void'", "'if'", "'else'", "'while'", "'break'", + "'continue'", "'return'", "'+'", "'-'", "'!'", "'*'", "'/'", "'%'", + "'<'", "'>'", "'<='", "'>='", "'=='", "'!='", "'&&'", "'||'", "'\"'" }, std::vector{ - "", "IDENT", "DECIMAL_CONST", "OCTAL_CONST", "HEXADECIMAL_CONST", - "WS", "SINGLELINE_COMMENT", "MULTILINE_COMMENT", "StringLiteral", - "CONST", "COMMA", "SEMICOLON", "INT", "LBRACKET", "RBRACKET", "ASSING", - "LBRACE", "RBRACE", "LPAREN", "RPAREN", "VOID", "IF", "ELSE", "WHILE", - "BREAK", "CONTINUE", "RETURN", "ADD", "SUB", "NOT", "MUL", "DIV", - "MOD", "LT", "GT", "LE", "GE", "EQ", "NE", "AND", "OR" + "", "CONST", "COMMA", "SEMICOLON", "INT", "LBRACKET", "RBRACKET", + "ASSIGN", "LBRACE", "RBRACE", "LPAREN", "RPAREN", "VOID", "IF", "ELSE", + "WHILE", "BREAK", "CONTINUE", "RETURN", "ADD", "SUB", "NOT", "MUL", + "DIV", "MOD", "LT", "GT", "LE", "GE", "EQ", "NE", "AND", "OR", "DQUOTE", + "IDENT", "DECIMAL_CONST", "OCTAL_CONST", "HEXADECIMAL_CONST", "WS", + "SINGLELINE_COMMENT", "MULTILINE_COMMENT", "StringLiteral" } ); static const int32_t serializedATNSegment[] = { - 4,1,40,366,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, + 4,1,41,366,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7,6,2, 7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,13,7,13,2,14,7, 14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7,19,2,20,7,20,2,21,7, 21,2,22,7,22,2,23,7,23,2,24,7,24,2,25,7,25,2,26,7,26,2,27,7,27,2,28,7, @@ -98,8 +97,8 @@ void sysyParserInitialize() { 9,31,1,32,1,32,1,32,1,32,1,32,1,32,5,32,359,8,32,10,32,12,32,362,9,32, 1,33,1,33,1,33,0,6,54,56,58,60,62,64,34,0,2,4,6,8,10,12,14,16,18,20,22, 24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,0,7, - 2,0,12,12,20,20,1,0,2,4,1,0,27,29,1,0,30,32,1,0,27,28,1,0,33,36,1,0,37, - 38,375,0,68,1,0,0,0,2,72,1,0,0,0,4,78,1,0,0,0,6,80,1,0,0,0,8,92,1,0,0, + 2,0,4,4,12,12,1,0,35,37,1,0,19,21,1,0,22,24,1,0,19,20,1,0,25,28,1,0,29, + 30,375,0,68,1,0,0,0,2,72,1,0,0,0,4,78,1,0,0,0,6,80,1,0,0,0,8,92,1,0,0, 0,10,94,1,0,0,0,12,120,1,0,0,0,14,122,1,0,0,0,16,133,1,0,0,0,18,160,1, 0,0,0,20,162,1,0,0,0,22,171,1,0,0,0,24,173,1,0,0,0,26,181,1,0,0,0,28, 196,1,0,0,0,30,207,1,0,0,0,32,243,1,0,0,0,34,245,1,0,0,0,36,247,1,0,0, @@ -109,85 +108,84 @@ void sysyParserInitialize() { 0,66,363,1,0,0,0,68,69,3,2,1,0,69,1,1,0,0,0,70,73,3,20,10,0,71,73,3,4, 2,0,72,70,1,0,0,0,72,71,1,0,0,0,73,74,1,0,0,0,74,72,1,0,0,0,74,75,1,0, 0,0,75,3,1,0,0,0,76,79,3,6,3,0,77,79,3,14,7,0,78,76,1,0,0,0,78,77,1,0, - 0,0,79,5,1,0,0,0,80,81,5,9,0,0,81,82,3,8,4,0,82,87,3,10,5,0,83,84,5,10, + 0,0,79,5,1,0,0,0,80,81,5,1,0,0,81,82,3,8,4,0,82,87,3,10,5,0,83,84,5,2, 0,0,84,86,3,10,5,0,85,83,1,0,0,0,86,89,1,0,0,0,87,85,1,0,0,0,87,88,1, - 0,0,0,88,90,1,0,0,0,89,87,1,0,0,0,90,91,5,11,0,0,91,7,1,0,0,0,92,93,5, - 12,0,0,93,9,1,0,0,0,94,101,5,1,0,0,95,96,5,13,0,0,96,97,3,66,33,0,97, - 98,5,14,0,0,98,100,1,0,0,0,99,95,1,0,0,0,100,103,1,0,0,0,101,99,1,0,0, - 0,101,102,1,0,0,0,102,104,1,0,0,0,103,101,1,0,0,0,104,105,5,15,0,0,105, - 106,3,12,6,0,106,11,1,0,0,0,107,121,3,66,33,0,108,117,5,16,0,0,109,114, - 3,12,6,0,110,111,5,10,0,0,111,113,3,12,6,0,112,110,1,0,0,0,113,116,1, - 0,0,0,114,112,1,0,0,0,114,115,1,0,0,0,115,118,1,0,0,0,116,114,1,0,0,0, - 117,109,1,0,0,0,117,118,1,0,0,0,118,119,1,0,0,0,119,121,5,17,0,0,120, - 107,1,0,0,0,120,108,1,0,0,0,121,13,1,0,0,0,122,123,3,8,4,0,123,128,3, - 16,8,0,124,125,5,10,0,0,125,127,3,16,8,0,126,124,1,0,0,0,127,130,1,0, - 0,0,128,126,1,0,0,0,128,129,1,0,0,0,129,131,1,0,0,0,130,128,1,0,0,0,131, - 132,5,11,0,0,132,15,1,0,0,0,133,140,5,1,0,0,134,135,5,13,0,0,135,136, - 3,66,33,0,136,137,5,14,0,0,137,139,1,0,0,0,138,134,1,0,0,0,139,142,1, - 0,0,0,140,138,1,0,0,0,140,141,1,0,0,0,141,145,1,0,0,0,142,140,1,0,0,0, - 143,144,5,15,0,0,144,146,3,18,9,0,145,143,1,0,0,0,145,146,1,0,0,0,146, - 17,1,0,0,0,147,161,3,34,17,0,148,157,5,16,0,0,149,154,3,18,9,0,150,151, - 5,10,0,0,151,153,3,18,9,0,152,150,1,0,0,0,153,156,1,0,0,0,154,152,1,0, - 0,0,154,155,1,0,0,0,155,158,1,0,0,0,156,154,1,0,0,0,157,149,1,0,0,0,157, - 158,1,0,0,0,158,159,1,0,0,0,159,161,5,17,0,0,160,147,1,0,0,0,160,148, - 1,0,0,0,161,19,1,0,0,0,162,163,3,22,11,0,163,164,5,1,0,0,164,166,5,18, - 0,0,165,167,3,24,12,0,166,165,1,0,0,0,166,167,1,0,0,0,167,168,1,0,0,0, - 168,169,5,19,0,0,169,170,3,28,14,0,170,21,1,0,0,0,171,172,7,0,0,0,172, - 23,1,0,0,0,173,178,3,26,13,0,174,175,5,10,0,0,175,177,3,26,13,0,176,174, - 1,0,0,0,177,180,1,0,0,0,178,176,1,0,0,0,178,179,1,0,0,0,179,25,1,0,0, - 0,180,178,1,0,0,0,181,182,3,8,4,0,182,194,5,1,0,0,183,184,5,13,0,0,184, - 191,5,14,0,0,185,186,5,13,0,0,186,187,3,34,17,0,187,188,5,14,0,0,188, - 190,1,0,0,0,189,185,1,0,0,0,190,193,1,0,0,0,191,189,1,0,0,0,191,192,1, - 0,0,0,192,195,1,0,0,0,193,191,1,0,0,0,194,183,1,0,0,0,194,195,1,0,0,0, - 195,27,1,0,0,0,196,200,5,16,0,0,197,199,3,30,15,0,198,197,1,0,0,0,199, - 202,1,0,0,0,200,198,1,0,0,0,200,201,1,0,0,0,201,203,1,0,0,0,202,200,1, - 0,0,0,203,204,5,17,0,0,204,29,1,0,0,0,205,208,3,4,2,0,206,208,3,32,16, - 0,207,205,1,0,0,0,207,206,1,0,0,0,208,31,1,0,0,0,209,210,3,38,19,0,210, - 211,5,15,0,0,211,212,3,34,17,0,212,213,5,11,0,0,213,244,1,0,0,0,214,216, - 3,34,17,0,215,214,1,0,0,0,215,216,1,0,0,0,216,217,1,0,0,0,217,244,5,11, - 0,0,218,244,3,28,14,0,219,220,5,21,0,0,220,221,5,18,0,0,221,222,3,36, - 18,0,222,223,5,19,0,0,223,226,3,32,16,0,224,225,5,22,0,0,225,227,3,32, - 16,0,226,224,1,0,0,0,226,227,1,0,0,0,227,244,1,0,0,0,228,229,5,23,0,0, - 229,230,5,18,0,0,230,231,3,36,18,0,231,232,5,19,0,0,232,233,3,32,16,0, - 233,244,1,0,0,0,234,235,5,24,0,0,235,244,5,11,0,0,236,237,5,25,0,0,237, - 244,5,11,0,0,238,240,5,26,0,0,239,241,3,34,17,0,240,239,1,0,0,0,240,241, - 1,0,0,0,241,242,1,0,0,0,242,244,5,11,0,0,243,209,1,0,0,0,243,215,1,0, - 0,0,243,218,1,0,0,0,243,219,1,0,0,0,243,228,1,0,0,0,243,234,1,0,0,0,243, - 236,1,0,0,0,243,238,1,0,0,0,244,33,1,0,0,0,245,246,3,56,28,0,246,35,1, - 0,0,0,247,248,3,64,32,0,248,37,1,0,0,0,249,256,5,1,0,0,250,251,5,13,0, - 0,251,252,3,34,17,0,252,253,5,14,0,0,253,255,1,0,0,0,254,250,1,0,0,0, - 255,258,1,0,0,0,256,254,1,0,0,0,256,257,1,0,0,0,257,39,1,0,0,0,258,256, - 1,0,0,0,259,260,5,18,0,0,260,261,3,34,17,0,261,262,5,19,0,0,262,266,1, - 0,0,0,263,266,3,38,19,0,264,266,3,42,21,0,265,259,1,0,0,0,265,263,1,0, - 0,0,265,264,1,0,0,0,266,41,1,0,0,0,267,268,3,44,22,0,268,43,1,0,0,0,269, - 270,7,1,0,0,270,45,1,0,0,0,271,282,3,40,20,0,272,273,5,1,0,0,273,275, - 5,18,0,0,274,276,3,50,25,0,275,274,1,0,0,0,275,276,1,0,0,0,276,277,1, - 0,0,0,277,282,5,19,0,0,278,279,3,48,24,0,279,280,3,46,23,0,280,282,1, - 0,0,0,281,271,1,0,0,0,281,272,1,0,0,0,281,278,1,0,0,0,282,47,1,0,0,0, - 283,284,7,2,0,0,284,49,1,0,0,0,285,290,3,52,26,0,286,287,5,10,0,0,287, - 289,3,52,26,0,288,286,1,0,0,0,289,292,1,0,0,0,290,288,1,0,0,0,290,291, - 1,0,0,0,291,51,1,0,0,0,292,290,1,0,0,0,293,296,3,34,17,0,294,296,5,8, - 0,0,295,293,1,0,0,0,295,294,1,0,0,0,296,53,1,0,0,0,297,298,6,27,-1,0, - 298,299,3,46,23,0,299,305,1,0,0,0,300,301,10,1,0,0,301,302,7,3,0,0,302, - 304,3,46,23,0,303,300,1,0,0,0,304,307,1,0,0,0,305,303,1,0,0,0,305,306, - 1,0,0,0,306,55,1,0,0,0,307,305,1,0,0,0,308,309,6,28,-1,0,309,310,3,54, - 27,0,310,316,1,0,0,0,311,312,10,1,0,0,312,313,7,4,0,0,313,315,3,54,27, - 0,314,311,1,0,0,0,315,318,1,0,0,0,316,314,1,0,0,0,316,317,1,0,0,0,317, - 57,1,0,0,0,318,316,1,0,0,0,319,320,6,29,-1,0,320,321,3,56,28,0,321,327, - 1,0,0,0,322,323,10,1,0,0,323,324,7,5,0,0,324,326,3,56,28,0,325,322,1, - 0,0,0,326,329,1,0,0,0,327,325,1,0,0,0,327,328,1,0,0,0,328,59,1,0,0,0, - 329,327,1,0,0,0,330,331,6,30,-1,0,331,332,3,58,29,0,332,338,1,0,0,0,333, - 334,10,1,0,0,334,335,7,6,0,0,335,337,3,58,29,0,336,333,1,0,0,0,337,340, - 1,0,0,0,338,336,1,0,0,0,338,339,1,0,0,0,339,61,1,0,0,0,340,338,1,0,0, - 0,341,342,6,31,-1,0,342,343,3,60,30,0,343,349,1,0,0,0,344,345,10,1,0, - 0,345,346,5,39,0,0,346,348,3,60,30,0,347,344,1,0,0,0,348,351,1,0,0,0, - 349,347,1,0,0,0,349,350,1,0,0,0,350,63,1,0,0,0,351,349,1,0,0,0,352,353, - 6,32,-1,0,353,354,3,62,31,0,354,360,1,0,0,0,355,356,10,1,0,0,356,357, - 5,40,0,0,357,359,3,62,31,0,358,355,1,0,0,0,359,362,1,0,0,0,360,358,1, - 0,0,0,360,361,1,0,0,0,361,65,1,0,0,0,362,360,1,0,0,0,363,364,3,56,28, - 0,364,67,1,0,0,0,36,72,74,78,87,101,114,117,120,128,140,145,154,157,160, - 166,178,191,194,200,207,215,226,240,243,256,265,275,281,290,295,305,316, - 327,338,349,360 + 0,0,0,88,90,1,0,0,0,89,87,1,0,0,0,90,91,5,3,0,0,91,7,1,0,0,0,92,93,5, + 4,0,0,93,9,1,0,0,0,94,101,5,34,0,0,95,96,5,5,0,0,96,97,3,66,33,0,97,98, + 5,6,0,0,98,100,1,0,0,0,99,95,1,0,0,0,100,103,1,0,0,0,101,99,1,0,0,0,101, + 102,1,0,0,0,102,104,1,0,0,0,103,101,1,0,0,0,104,105,5,7,0,0,105,106,3, + 12,6,0,106,11,1,0,0,0,107,121,3,66,33,0,108,117,5,8,0,0,109,114,3,12, + 6,0,110,111,5,2,0,0,111,113,3,12,6,0,112,110,1,0,0,0,113,116,1,0,0,0, + 114,112,1,0,0,0,114,115,1,0,0,0,115,118,1,0,0,0,116,114,1,0,0,0,117,109, + 1,0,0,0,117,118,1,0,0,0,118,119,1,0,0,0,119,121,5,9,0,0,120,107,1,0,0, + 0,120,108,1,0,0,0,121,13,1,0,0,0,122,123,3,8,4,0,123,128,3,16,8,0,124, + 125,5,2,0,0,125,127,3,16,8,0,126,124,1,0,0,0,127,130,1,0,0,0,128,126, + 1,0,0,0,128,129,1,0,0,0,129,131,1,0,0,0,130,128,1,0,0,0,131,132,5,3,0, + 0,132,15,1,0,0,0,133,140,5,34,0,0,134,135,5,5,0,0,135,136,3,66,33,0,136, + 137,5,6,0,0,137,139,1,0,0,0,138,134,1,0,0,0,139,142,1,0,0,0,140,138,1, + 0,0,0,140,141,1,0,0,0,141,145,1,0,0,0,142,140,1,0,0,0,143,144,5,7,0,0, + 144,146,3,18,9,0,145,143,1,0,0,0,145,146,1,0,0,0,146,17,1,0,0,0,147,161, + 3,34,17,0,148,157,5,8,0,0,149,154,3,18,9,0,150,151,5,2,0,0,151,153,3, + 18,9,0,152,150,1,0,0,0,153,156,1,0,0,0,154,152,1,0,0,0,154,155,1,0,0, + 0,155,158,1,0,0,0,156,154,1,0,0,0,157,149,1,0,0,0,157,158,1,0,0,0,158, + 159,1,0,0,0,159,161,5,9,0,0,160,147,1,0,0,0,160,148,1,0,0,0,161,19,1, + 0,0,0,162,163,3,22,11,0,163,164,5,34,0,0,164,166,5,10,0,0,165,167,3,24, + 12,0,166,165,1,0,0,0,166,167,1,0,0,0,167,168,1,0,0,0,168,169,5,11,0,0, + 169,170,3,28,14,0,170,21,1,0,0,0,171,172,7,0,0,0,172,23,1,0,0,0,173,178, + 3,26,13,0,174,175,5,2,0,0,175,177,3,26,13,0,176,174,1,0,0,0,177,180,1, + 0,0,0,178,176,1,0,0,0,178,179,1,0,0,0,179,25,1,0,0,0,180,178,1,0,0,0, + 181,182,3,8,4,0,182,194,5,34,0,0,183,184,5,5,0,0,184,191,5,6,0,0,185, + 186,5,5,0,0,186,187,3,34,17,0,187,188,5,6,0,0,188,190,1,0,0,0,189,185, + 1,0,0,0,190,193,1,0,0,0,191,189,1,0,0,0,191,192,1,0,0,0,192,195,1,0,0, + 0,193,191,1,0,0,0,194,183,1,0,0,0,194,195,1,0,0,0,195,27,1,0,0,0,196, + 200,5,8,0,0,197,199,3,30,15,0,198,197,1,0,0,0,199,202,1,0,0,0,200,198, + 1,0,0,0,200,201,1,0,0,0,201,203,1,0,0,0,202,200,1,0,0,0,203,204,5,9,0, + 0,204,29,1,0,0,0,205,208,3,4,2,0,206,208,3,32,16,0,207,205,1,0,0,0,207, + 206,1,0,0,0,208,31,1,0,0,0,209,210,3,38,19,0,210,211,5,7,0,0,211,212, + 3,34,17,0,212,213,5,3,0,0,213,244,1,0,0,0,214,216,3,34,17,0,215,214,1, + 0,0,0,215,216,1,0,0,0,216,217,1,0,0,0,217,244,5,3,0,0,218,244,3,28,14, + 0,219,220,5,13,0,0,220,221,5,10,0,0,221,222,3,36,18,0,222,223,5,11,0, + 0,223,226,3,32,16,0,224,225,5,14,0,0,225,227,3,32,16,0,226,224,1,0,0, + 0,226,227,1,0,0,0,227,244,1,0,0,0,228,229,5,15,0,0,229,230,5,10,0,0,230, + 231,3,36,18,0,231,232,5,11,0,0,232,233,3,32,16,0,233,244,1,0,0,0,234, + 235,5,16,0,0,235,244,5,3,0,0,236,237,5,17,0,0,237,244,5,3,0,0,238,240, + 5,18,0,0,239,241,3,34,17,0,240,239,1,0,0,0,240,241,1,0,0,0,241,242,1, + 0,0,0,242,244,5,3,0,0,243,209,1,0,0,0,243,215,1,0,0,0,243,218,1,0,0,0, + 243,219,1,0,0,0,243,228,1,0,0,0,243,234,1,0,0,0,243,236,1,0,0,0,243,238, + 1,0,0,0,244,33,1,0,0,0,245,246,3,56,28,0,246,35,1,0,0,0,247,248,3,64, + 32,0,248,37,1,0,0,0,249,256,5,34,0,0,250,251,5,5,0,0,251,252,3,34,17, + 0,252,253,5,6,0,0,253,255,1,0,0,0,254,250,1,0,0,0,255,258,1,0,0,0,256, + 254,1,0,0,0,256,257,1,0,0,0,257,39,1,0,0,0,258,256,1,0,0,0,259,260,5, + 10,0,0,260,261,3,34,17,0,261,262,5,11,0,0,262,266,1,0,0,0,263,266,3,38, + 19,0,264,266,3,42,21,0,265,259,1,0,0,0,265,263,1,0,0,0,265,264,1,0,0, + 0,266,41,1,0,0,0,267,268,3,44,22,0,268,43,1,0,0,0,269,270,7,1,0,0,270, + 45,1,0,0,0,271,282,3,40,20,0,272,273,5,34,0,0,273,275,5,10,0,0,274,276, + 3,50,25,0,275,274,1,0,0,0,275,276,1,0,0,0,276,277,1,0,0,0,277,282,5,11, + 0,0,278,279,3,48,24,0,279,280,3,46,23,0,280,282,1,0,0,0,281,271,1,0,0, + 0,281,272,1,0,0,0,281,278,1,0,0,0,282,47,1,0,0,0,283,284,7,2,0,0,284, + 49,1,0,0,0,285,290,3,52,26,0,286,287,5,2,0,0,287,289,3,52,26,0,288,286, + 1,0,0,0,289,292,1,0,0,0,290,288,1,0,0,0,290,291,1,0,0,0,291,51,1,0,0, + 0,292,290,1,0,0,0,293,296,3,34,17,0,294,296,5,41,0,0,295,293,1,0,0,0, + 295,294,1,0,0,0,296,53,1,0,0,0,297,298,6,27,-1,0,298,299,3,46,23,0,299, + 305,1,0,0,0,300,301,10,1,0,0,301,302,7,3,0,0,302,304,3,46,23,0,303,300, + 1,0,0,0,304,307,1,0,0,0,305,303,1,0,0,0,305,306,1,0,0,0,306,55,1,0,0, + 0,307,305,1,0,0,0,308,309,6,28,-1,0,309,310,3,54,27,0,310,316,1,0,0,0, + 311,312,10,1,0,0,312,313,7,4,0,0,313,315,3,54,27,0,314,311,1,0,0,0,315, + 318,1,0,0,0,316,314,1,0,0,0,316,317,1,0,0,0,317,57,1,0,0,0,318,316,1, + 0,0,0,319,320,6,29,-1,0,320,321,3,56,28,0,321,327,1,0,0,0,322,323,10, + 1,0,0,323,324,7,5,0,0,324,326,3,56,28,0,325,322,1,0,0,0,326,329,1,0,0, + 0,327,325,1,0,0,0,327,328,1,0,0,0,328,59,1,0,0,0,329,327,1,0,0,0,330, + 331,6,30,-1,0,331,332,3,58,29,0,332,338,1,0,0,0,333,334,10,1,0,0,334, + 335,7,6,0,0,335,337,3,58,29,0,336,333,1,0,0,0,337,340,1,0,0,0,338,336, + 1,0,0,0,338,339,1,0,0,0,339,61,1,0,0,0,340,338,1,0,0,0,341,342,6,31,-1, + 0,342,343,3,60,30,0,343,349,1,0,0,0,344,345,10,1,0,0,345,346,5,31,0,0, + 346,348,3,60,30,0,347,344,1,0,0,0,348,351,1,0,0,0,349,347,1,0,0,0,349, + 350,1,0,0,0,350,63,1,0,0,0,351,349,1,0,0,0,352,353,6,32,-1,0,353,354, + 3,62,31,0,354,360,1,0,0,0,355,356,10,1,0,0,356,357,5,32,0,0,357,359,3, + 62,31,0,358,355,1,0,0,0,359,362,1,0,0,0,360,358,1,0,0,0,360,361,1,0,0, + 0,361,65,1,0,0,0,362,360,1,0,0,0,363,364,3,56,28,0,364,67,1,0,0,0,36, + 72,74,78,87,101,114,117,120,128,140,145,154,157,160,166,178,191,194,200, + 207,215,226,240,243,256,265,275,281,290,295,305,316,327,338,349,360 }; staticData->serializedATN = antlr4::atn::SerializedATNView(serializedATNSegment, sizeof(serializedATNSegment) / sizeof(serializedATNSegment[0])); @@ -360,7 +358,7 @@ SysyParser::CompUnitContext* SysyParser::compUnit() { _errHandler->sync(this); _la = _input->LA(1); } while ((((_la & ~ 0x3fULL) == 0) && - ((1ULL << _la) & 1053184) != 0)); + ((1ULL << _la) & 4114) != 0)); } catch (RecognitionException &e) { @@ -593,8 +591,8 @@ tree::TerminalNode* SysyParser::ConstDefContext::IDENT() { return getToken(SysyParser::IDENT, 0); } -tree::TerminalNode* SysyParser::ConstDefContext::ASSING() { - return getToken(SysyParser::ASSING, 0); +tree::TerminalNode* SysyParser::ConstDefContext::ASSIGN() { + return getToken(SysyParser::ASSIGN, 0); } SysyParser::ConstInitValContext* SysyParser::ConstDefContext::constInitVal() { @@ -669,7 +667,7 @@ SysyParser::ConstDefContext* SysyParser::constDef() { _la = _input->LA(1); } setState(104); - match(SysyParser::ASSING); + match(SysyParser::ASSIGN); setState(105); constInitVal(); @@ -746,14 +744,14 @@ SysyParser::ConstInitValContext* SysyParser::constInitVal() { setState(120); _errHandler->sync(this); switch (_input->LA(1)) { - case SysyParser::IDENT: - case SysyParser::DECIMAL_CONST: - case SysyParser::OCTAL_CONST: - case SysyParser::HEXADECIMAL_CONST: case SysyParser::LPAREN: case SysyParser::ADD: case SysyParser::SUB: - case SysyParser::NOT: { + case SysyParser::NOT: + case SysyParser::IDENT: + case SysyParser::DECIMAL_CONST: + case SysyParser::OCTAL_CONST: + case SysyParser::HEXADECIMAL_CONST: { enterOuterAlt(_localctx, 1); setState(107); constExp(); @@ -769,7 +767,7 @@ SysyParser::ConstInitValContext* SysyParser::constInitVal() { _la = _input->LA(1); if ((((_la & ~ 0x3fULL) == 0) && - ((1ULL << _la) & 939851806) != 0)) { + ((1ULL << _la) & 257701709056) != 0)) { setState(109); constInitVal(); setState(114); @@ -924,8 +922,8 @@ tree::TerminalNode* SysyParser::VarDefContext::RBRACKET(size_t i) { return getToken(SysyParser::RBRACKET, i); } -tree::TerminalNode* SysyParser::VarDefContext::ASSING() { - return getToken(SysyParser::ASSING, 0); +tree::TerminalNode* SysyParser::VarDefContext::ASSIGN() { + return getToken(SysyParser::ASSIGN, 0); } SysyParser::InitValContext* SysyParser::VarDefContext::initVal() { @@ -979,9 +977,9 @@ SysyParser::VarDefContext* SysyParser::varDef() { _errHandler->sync(this); _la = _input->LA(1); - if (_la == SysyParser::ASSING) { + if (_la == SysyParser::ASSIGN) { setState(143); - match(SysyParser::ASSING); + match(SysyParser::ASSIGN); setState(144); initVal(); } @@ -1059,14 +1057,14 @@ SysyParser::InitValContext* SysyParser::initVal() { setState(160); _errHandler->sync(this); switch (_input->LA(1)) { - case SysyParser::IDENT: - case SysyParser::DECIMAL_CONST: - case SysyParser::OCTAL_CONST: - case SysyParser::HEXADECIMAL_CONST: case SysyParser::LPAREN: case SysyParser::ADD: case SysyParser::SUB: - case SysyParser::NOT: { + case SysyParser::NOT: + case SysyParser::IDENT: + case SysyParser::DECIMAL_CONST: + case SysyParser::OCTAL_CONST: + case SysyParser::HEXADECIMAL_CONST: { enterOuterAlt(_localctx, 1); setState(147); exp(); @@ -1082,7 +1080,7 @@ SysyParser::InitValContext* SysyParser::initVal() { _la = _input->LA(1); if ((((_la & ~ 0x3fULL) == 0) && - ((1ULL << _la) & 939851806) != 0)) { + ((1ULL << _la) & 257701709056) != 0)) { setState(149); initVal(); setState(154); @@ -1499,7 +1497,7 @@ SysyParser::BlockContext* SysyParser::block() { _errHandler->sync(this); _la = _input->LA(1); while ((((_la & ~ 0x3fULL) == 0) && - ((1ULL << _la) & 1067784734) != 0)) { + ((1ULL << _la) & 257702208794) != 0)) { setState(197); blockItem(); setState(202); @@ -1569,10 +1567,6 @@ SysyParser::BlockItemContext* SysyParser::blockItem() { break; } - case SysyParser::IDENT: - case SysyParser::DECIMAL_CONST: - case SysyParser::OCTAL_CONST: - case SysyParser::HEXADECIMAL_CONST: case SysyParser::SEMICOLON: case SysyParser::LBRACE: case SysyParser::LPAREN: @@ -1583,7 +1577,11 @@ SysyParser::BlockItemContext* SysyParser::blockItem() { case SysyParser::RETURN: case SysyParser::ADD: case SysyParser::SUB: - case SysyParser::NOT: { + case SysyParser::NOT: + case SysyParser::IDENT: + case SysyParser::DECIMAL_CONST: + case SysyParser::OCTAL_CONST: + case SysyParser::HEXADECIMAL_CONST: { enterOuterAlt(_localctx, 2); setState(206); stmt(); @@ -1710,8 +1708,8 @@ SysyParser::LValContext* SysyParser::AssignStmtContext::lVal() { return getRuleContext(0); } -tree::TerminalNode* SysyParser::AssignStmtContext::ASSING() { - return getToken(SysyParser::ASSING, 0); +tree::TerminalNode* SysyParser::AssignStmtContext::ASSIGN() { + return getToken(SysyParser::ASSIGN, 0); } SysyParser::ExpContext* SysyParser::AssignStmtContext::exp() { @@ -1833,7 +1831,7 @@ SysyParser::StmtContext* SysyParser::stmt() { setState(209); lVal(); setState(210); - match(SysyParser::ASSING); + match(SysyParser::ASSIGN); setState(211); exp(); setState(212); @@ -1849,7 +1847,7 @@ SysyParser::StmtContext* SysyParser::stmt() { _la = _input->LA(1); if ((((_la & ~ 0x3fULL) == 0) && - ((1ULL << _la) & 939786270) != 0)) { + ((1ULL << _la) & 257701708800) != 0)) { setState(214); exp(); } @@ -1943,7 +1941,7 @@ SysyParser::StmtContext* SysyParser::stmt() { _la = _input->LA(1); if ((((_la & ~ 0x3fULL) == 0) && - ((1ULL << _la) & 939786270) != 0)) { + ((1ULL << _la) & 257701708800) != 0)) { setState(239); exp(); } @@ -2346,7 +2344,7 @@ SysyParser::IntConstContext* SysyParser::intConst() { setState(269); _la = _input->LA(1); if (!((((_la & ~ 0x3fULL) == 0) && - ((1ULL << _la) & 28) != 0))) { + ((1ULL << _la) & 240518168576) != 0))) { _errHandler->recoverInline(this); } else { @@ -2445,7 +2443,7 @@ SysyParser::UnaryExpContext* SysyParser::unaryExp() { _la = _input->LA(1); if ((((_la & ~ 0x3fULL) == 0) && - ((1ULL << _la) & 939786526) != 0)) { + ((1ULL << _la) & 2456724964352) != 0)) { setState(274); funcRParams(); } @@ -2525,7 +2523,7 @@ SysyParser::UnaryOpContext* SysyParser::unaryOp() { setState(283); _la = _input->LA(1); if (!((((_la & ~ 0x3fULL) == 0) && - ((1ULL << _la) & 939524096) != 0))) { + ((1ULL << _la) & 3670016) != 0))) { _errHandler->recoverInline(this); } else { @@ -2659,14 +2657,14 @@ SysyParser::FuncRParamContext* SysyParser::funcRParam() { setState(295); _errHandler->sync(this); switch (_input->LA(1)) { - case SysyParser::IDENT: - case SysyParser::DECIMAL_CONST: - case SysyParser::OCTAL_CONST: - case SysyParser::HEXADECIMAL_CONST: case SysyParser::LPAREN: case SysyParser::ADD: case SysyParser::SUB: - case SysyParser::NOT: { + case SysyParser::NOT: + case SysyParser::IDENT: + case SysyParser::DECIMAL_CONST: + case SysyParser::OCTAL_CONST: + case SysyParser::HEXADECIMAL_CONST: { enterOuterAlt(_localctx, 1); setState(293); exp(); @@ -2778,7 +2776,7 @@ SysyParser::MulExpContext* SysyParser::mulExp(int precedence) { setState(301); _la = _input->LA(1); if (!((((_la & ~ 0x3fULL) == 0) && - ((1ULL << _la) & 7516192768) != 0))) { + ((1ULL << _la) & 29360128) != 0))) { _errHandler->recoverInline(this); } else { @@ -2993,7 +2991,7 @@ SysyParser::RelExpContext* SysyParser::relExp(int precedence) { setState(323); _la = _input->LA(1); if (!((((_la & ~ 0x3fULL) == 0) && - ((1ULL << _la) & 128849018880) != 0))) { + ((1ULL << _la) & 503316480) != 0))) { _errHandler->recoverInline(this); } else { diff --git a/src/main.cpp b/src/main.cpp index 7bd2088..1c86d15 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,11 +1,16 @@ -#include #include +#include #include -#include "SysyLexer.h" -#include "SysyParser.h" #include "antlr4-runtime.h" -#include +#include "antlrgen/SysyLexer.h" +#include "antlrgen/SysyParser.h" +#include <3rdparty/argparse.hpp> + +#include "common.h" +#include "visitor.h" + +INITIALIZE_EASYLOGGINGPP using namespace antlrSysY; using namespace antlr4; @@ -31,23 +36,25 @@ int main(int argc, const char **argv) { auto source_file = arg_parser.get("source"); auto output_file = arg_parser.get("-o"); auto flg_O1 = arg_parser["-O1"] == true; - // std::cout << source_file << " " << output_file << " " << flg_O1 << std::endl; + // std::cout << source_file << " " << output_file << " " << flg_O1 << + // std::endl; #pragma endregion std::ifstream ifs_source_file(source_file); ANTLRInputStream input(ifs_source_file); SysyLexer lexer(&input); CommonTokenStream tokens(&lexer); - - tokens.fill(); #if 0 + tokens.fill(); for (auto token : tokens.getTokens()) { std::cout << token->toString() << std::endl; } #endif SysyParser parser(&tokens); - tree::ParseTree *tree = parser.program(); + auto tree = parser.program(); + Visitor visitor(lexer); + visitor.visitProgram(tree); #if 0 std::cout << tree->toStringTree(&parser) << std::endl << std::endl; #endif diff --git a/src/visitor.cpp b/src/visitor.cpp new file mode 100644 index 0000000..0812e5c --- /dev/null +++ b/src/visitor.cpp @@ -0,0 +1,173 @@ +#include "visitor.h" +#include "common.h" +#include "llir_value.h" +#include +#include + +namespace antlrSysY { + +std::any Visitor::visitConstDecl(SysyParser::ConstDeclContext *ctx) { + for (auto constDef : ctx->constDef()) { + visitConstDef(constDef); + } + return {}; +} + +// constDef : IDENT ('[' constExp ']')* '=' constInitVal ';' +std::any Visitor::visitConstDef(SysyParser::ConstDefContext *ctx) { + auto name = ctx->IDENT()->getText(); + LOG(DEBUG) << "Visiting ConstDef " << name; + if (_scope_tab.get_name(name, _scope_tab.get_level()).has_value()) + throw GrammarException("Duplicate const def"); + if (ctx->constExp().empty()) { + // not array define + if (ctx->constInitVal() != nullptr) { + auto result = std::any_cast>(visit(ctx->constInitVal())); + // _scope_tab.push_name(name, Value *const &&value) + _scope_tab.push_name(name, result); + } + } + return {}; +} + +std::any Visitor::visitConstInitVal(SysyParser::ConstInitValContext *ctx) { + if (ctx->constExp() != nullptr /*&& ctx->arrDim.size() == 0*/) { + return visit(ctx->constExp()); + } + return {}; +} + +std::any Visitor::visitConstExp(SysyParser::ConstExpContext *ctx) { + if (ctx->addExp() == nullptr) + panic("missing element"); + _state.isConstInt = true; + int result = std::any_cast(visit(ctx->addExp())); + _state.isConstInt = false; + LOG(DEBUG) << "ConstExp Eval to " << result; + auto constint = std::make_shared("", result, 1); + return {constint}; +} + +// addExp: mulExp | addExp ('+' | '-') mulExp; +std::any Visitor::visitAddExp(SysyParser::AddExpContext *ctx) { + if (_state.isConstInt) { + if (ctx->mulExp() == nullptr) + panic("missing element"); + int result = std::any_cast(visit(ctx->mulExp())); + int add_result = 0; + if (ctx->addExp()) { + add_result = std::any_cast(visit(ctx->addExp())); + if (ctx->ADD()) + result = add_result + result; + else if (ctx->SUB()) + result = add_result - result; + else + panic("missing operator"); + } + return {result}; + } else { + panic("To be implemented"); + } + return {}; +} + +std::any Visitor::visitMulExp(SysyParser::MulExpContext *ctx) { + if (_state.isConstInt) { + if (ctx->unaryExp() == nullptr) + panic("missing element"); + int result = std::any_cast(visit(ctx->unaryExp())); + if (ctx->mulExp()) { + int mul_result = std::any_cast(visit(ctx->mulExp())); + if (ctx->MUL()) { + result = mul_result * result; + } else if (ctx->DIV()) { + result = mul_result / result; + } else if (ctx->MOD()) { + result = mul_result % result; + } else + panic("missing operator"); + } + return {result}; + } else { + panic("To be implemented"); + } + return {}; +} +// unaryExp: primaryExp | IDENT '(' (funcRParams)? ')' | unaryOp unaryExp; +std::any Visitor::visitUnaryExp(SysyParser::UnaryExpContext *ctx) { + if (_state.isConstInt) { + if (ctx->unaryExp()) { + int result = std::any_cast(visit(ctx->unaryExp())); + if (ctx->unaryOp()->ADD()) + result = +result; + else if (ctx->unaryOp()->SUB()) + result = -result; + else if (ctx->unaryOp()->NOT()) + result = !result; + else + panic("Missing operator"); + return {result}; + } else if (ctx->primaryExp()) { + return visitPrimaryExp(ctx->primaryExp()); + } else if (ctx->IDENT()) { + panic("Unexpected func call in const expr"); + } + panic("missing element"); + } else { + panic("To be implemented"); + } + return {}; +} + +// primaryExp: ('(' exp ')') | lVal | number; +std::any Visitor::visitPrimaryExp(SysyParser::PrimaryExpContext *ctx) { + if (_state.isConstInt) { + if (ctx->exp()) { + return visitExp(ctx->exp()); + } else if (ctx->lVal()) { + auto value = std::any_cast>(visit(ctx->lVal())); + auto constint = std::dynamic_pointer_cast(value); + return constint->value; + } else if (ctx->number()) { + return visitNumber(ctx->number()); + } + panic("missing element"); + } else { + panic("To be implemented"); + } + return {}; +} + +std::any Visitor::visitNumber(SysyParser::NumberContext *ctx) { + sysy_assert(ctx->intConst()); + if (_state.isConstInt) { + return visit(ctx->intConst()); + } + panic("To be implemented"); +} + +std::any Visitor::visitIntConst(SysyParser::IntConstContext *ctx) { + if (ctx->DECIMAL_CONST()) { + return std::stoi(ctx->DECIMAL_CONST()->getText(), nullptr, 10); + } else if (ctx->HEXADECIMAL_CONST()) { + return std::stoi(ctx->HEXADECIMAL_CONST()->getText(), nullptr, 16); + + } else if (ctx->OCTAL_CONST()) { + return std::stoi(ctx->OCTAL_CONST()->getText(), nullptr, 8); + } + panic("missing element"); +} + +std::any Visitor::visitLVal(SysyParser::LValContext *ctx) { + auto name = ctx->IDENT()->getText(); + LOG(DEBUG) << "Eval to lVal " << name; + auto _lval = _scope_tab.get_name(name); + sysy_assert(_lval.has_value()); + auto lval = _lval.value(); + if (lval->type == Type::IntegerType) { + return {lval}; + } + panic("To be implemented"); +} + +} // namespace antlrSysY \ No newline at end of file