basically finish AST build
This commit is contained in:
@ -27,7 +27,7 @@ statement
|
||||
define_statement : type (LBRACKET RBRACKET)* ID (ASSIGN expr)? (COMMA ID (ASSIGN expr)?)* SEMICOLON;
|
||||
expr
|
||||
: basic_expr #basic_expression
|
||||
| NEW type (LBRACKET expr? RBRACKET)*constant? #new_array_expression
|
||||
| NEW type (LBRACKET expr? RBRACKET)+constant? #new_array_expression
|
||||
| NEW type LPAREN RPAREN #new_construct_expression
|
||||
| NEW type #new_expression
|
||||
| expr DOT (ID|(ID LPAREN (expr (COMMA expr)*)? RPAREN)) #access_expression
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "astnode.h"
|
||||
|
||||
class Expr_ASTNode : public ASTNodeBase {
|
||||
friend Visitor;
|
||||
ExprTypeInfo expr_type_info;
|
||||
|
||||
public:
|
||||
@ -16,6 +17,7 @@ class BasicExpr_ASTNode : public Expr_ASTNode {}; // This is a virtual class
|
||||
class NewArrayExpr_ASTNode : public Expr_ASTNode {
|
||||
friend Visitor;
|
||||
bool has_initial_value;
|
||||
std::vector<std::shared_ptr<Expr_ASTNode>> dim_size;
|
||||
std::shared_ptr<class ConstantExpr_ASTNode> initial_value;
|
||||
};
|
||||
class NewConstructExpr_ASTNode : public Expr_ASTNode {
|
||||
@ -28,12 +30,7 @@ class AccessExpr_ASTNode : public Expr_ASTNode {
|
||||
friend Visitor;
|
||||
std::shared_ptr<Expr_ASTNode> base;
|
||||
IdentifierType member;
|
||||
};
|
||||
class MemberVariableAccessExpr_ASTNode : public AccessExpr_ASTNode {
|
||||
friend Visitor;
|
||||
};
|
||||
class MemberFunctionAccessExpr_ASTNode : public AccessExpr_ASTNode {
|
||||
friend Visitor;
|
||||
bool is_function;
|
||||
std::vector<std::shared_ptr<Expr_ASTNode>> arguments;
|
||||
};
|
||||
class IndexExpr_ASTNode : public Expr_ASTNode {
|
||||
@ -43,10 +40,12 @@ class IndexExpr_ASTNode : public Expr_ASTNode {
|
||||
};
|
||||
class SuffixExpr_ASTNode : public Expr_ASTNode {
|
||||
friend Visitor;
|
||||
std::string op;
|
||||
std::shared_ptr<Expr_ASTNode> base;
|
||||
};
|
||||
class PrefixExpr_ASTNode : public Expr_ASTNode {
|
||||
friend Visitor;
|
||||
std::string op;
|
||||
std::shared_ptr<Expr_ASTNode> base;
|
||||
};
|
||||
class OppositeExpr_ASTNode : public Expr_ASTNode {
|
||||
@ -55,61 +54,69 @@ class OppositeExpr_ASTNode : public Expr_ASTNode {
|
||||
};
|
||||
class LNotExpr_ASTNode : public Expr_ASTNode {
|
||||
friend Visitor;
|
||||
std::shared_ptr<Expr_ASTNode> left;
|
||||
std::shared_ptr<Expr_ASTNode> right;
|
||||
std::shared_ptr<Expr_ASTNode> base;
|
||||
};
|
||||
class BNotExpr_ASTNode : public Expr_ASTNode {
|
||||
friend Visitor;
|
||||
std::shared_ptr<Expr_ASTNode> left;
|
||||
std::shared_ptr<Expr_ASTNode> right;
|
||||
std::shared_ptr<Expr_ASTNode> base;
|
||||
};
|
||||
class MDMExpr_ASTNode : public Expr_ASTNode {
|
||||
friend Visitor;
|
||||
std::string op;
|
||||
std::shared_ptr<Expr_ASTNode> left;
|
||||
std::shared_ptr<Expr_ASTNode> right;
|
||||
};
|
||||
class PMExpr_ASTNode : public Expr_ASTNode {
|
||||
friend Visitor;
|
||||
std::string op;
|
||||
std::shared_ptr<Expr_ASTNode> left;
|
||||
std::shared_ptr<Expr_ASTNode> right;
|
||||
};
|
||||
class RLExpr_ASTNode : public Expr_ASTNode {
|
||||
friend Visitor;
|
||||
std::string op;
|
||||
std::shared_ptr<Expr_ASTNode> left;
|
||||
std::shared_ptr<Expr_ASTNode> right;
|
||||
};
|
||||
class GGLLExpr_ASTNode : public Expr_ASTNode {
|
||||
friend Visitor;
|
||||
std::string op;
|
||||
std::shared_ptr<Expr_ASTNode> left;
|
||||
std::shared_ptr<Expr_ASTNode> right;
|
||||
};
|
||||
class NEExpr_ASTNode : public Expr_ASTNode {
|
||||
friend Visitor;
|
||||
std::string op;
|
||||
std::shared_ptr<Expr_ASTNode> left;
|
||||
std::shared_ptr<Expr_ASTNode> right;
|
||||
};
|
||||
class BAndExpr_ASTNode : public Expr_ASTNode {
|
||||
friend Visitor;
|
||||
std::string op;
|
||||
std::shared_ptr<Expr_ASTNode> left;
|
||||
std::shared_ptr<Expr_ASTNode> right;
|
||||
};
|
||||
class BXorExpr_ASTNode : public Expr_ASTNode {
|
||||
friend Visitor;
|
||||
std::string op;
|
||||
std::shared_ptr<Expr_ASTNode> left;
|
||||
std::shared_ptr<Expr_ASTNode> right;
|
||||
};
|
||||
class BOrExpr_ASTNode : public Expr_ASTNode {
|
||||
friend Visitor;
|
||||
std::string op;
|
||||
std::shared_ptr<Expr_ASTNode> left;
|
||||
std::shared_ptr<Expr_ASTNode> right;
|
||||
};
|
||||
class LAndExpr_ASTNode : public Expr_ASTNode {
|
||||
friend Visitor;
|
||||
std::string op;
|
||||
std::shared_ptr<Expr_ASTNode> left;
|
||||
std::shared_ptr<Expr_ASTNode> right;
|
||||
};
|
||||
class LOrExpr_ASTNode : public Expr_ASTNode {
|
||||
friend Visitor;
|
||||
std::string op;
|
||||
std::shared_ptr<Expr_ASTNode> left;
|
||||
std::shared_ptr<Expr_ASTNode> right;
|
||||
};
|
||||
@ -121,6 +128,7 @@ class TernaryExpr_ASTNode : public Expr_ASTNode {
|
||||
};
|
||||
class AssignExpr_ASTNode : public Expr_ASTNode {
|
||||
friend Visitor;
|
||||
std::string op;
|
||||
std::shared_ptr<Expr_ASTNode> dest;
|
||||
std::shared_ptr<Expr_ASTNode> src;
|
||||
};
|
||||
@ -143,8 +151,8 @@ class FunctionCallExpr_ASTNode : public BasicExpr_ASTNode {
|
||||
};
|
||||
class FormattedStringExpr_ASTNode : public BasicExpr_ASTNode {
|
||||
friend Visitor;
|
||||
using SegmentType = std::variant<std::string, std::shared_ptr<Expr_ASTNode>>;
|
||||
std::vector<SegmentType> segments;
|
||||
std::vector<std::string> literals;
|
||||
std::vector<std::shared_ptr<Expr_ASTNode>> exprs;
|
||||
};
|
||||
struct NullType {};
|
||||
using AtomicConstantType = std::variant<uint32_t, bool, std::string, NullType>;
|
||||
|
@ -41,6 +41,7 @@ class ForStatement_ASTNode : public Statement_ASTNode {
|
||||
};
|
||||
class JmpStatement_ASTNode : public Statement_ASTNode {
|
||||
friend Visitor;
|
||||
uint8_t jmp_type; // 0: return, 1: break, 2: continue
|
||||
std::shared_ptr<Expr_ASTNode> return_value;
|
||||
};
|
||||
class SuiteStatement_ASTNode : public Statement_ASTNode {
|
||||
|
@ -4,6 +4,6 @@
|
||||
#include "ast/ast.h"
|
||||
#include "visitor.h"
|
||||
|
||||
std::shared_ptr<ASTNodeBase> BuildAST(Visitor *visitor, antlr4::tree::ParseTree *tree);
|
||||
void SemanticCheck(std::istream &fin, std::shared_ptr<ASTNodeBase> &ast);
|
||||
std::shared_ptr<Program_ASTNode> BuildAST(Visitor *visitor, antlr4::tree::ParseTree *tree);
|
||||
void SemanticCheck(std::istream &fin, std::shared_ptr<Program_ASTNode> &ast);
|
||||
#endif
|
@ -21,7 +21,7 @@ int main(int argc, char **argv) {
|
||||
auto input_file = program.get<std::string>("input");
|
||||
auto output_file = program.get<std::string>("output");
|
||||
std::ifstream fin(input_file);
|
||||
std::shared_ptr<ASTNodeBase> ast;
|
||||
std::shared_ptr<Program_ASTNode> ast;
|
||||
try {
|
||||
SemanticCheck(fin, ast);
|
||||
} catch (const SemanticError &err) {
|
||||
|
@ -78,7 +78,7 @@ void mxparserParserInitialize() {
|
||||
}
|
||||
);
|
||||
static const int32_t serializedATNSegment[] = {
|
||||
4,1,61,365,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,61,364,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,1,0,1,0,1,0,4,0,30,
|
||||
8,0,11,0,12,0,31,1,0,1,0,1,1,1,1,1,1,5,1,39,8,1,10,1,12,1,42,9,1,1,1,
|
||||
1,1,1,1,1,1,1,1,5,1,49,8,1,10,1,12,1,52,9,1,1,1,1,1,1,1,1,1,1,1,1,1,5,
|
||||
@ -92,22 +92,22 @@ void mxparserParserInitialize() {
|
||||
1,6,3,6,166,8,6,3,6,168,8,6,1,6,1,6,3,6,172,8,6,1,7,1,7,1,7,5,7,177,8,
|
||||
7,10,7,12,7,180,9,7,1,7,1,7,1,7,3,7,185,8,7,1,7,1,7,1,7,1,7,3,7,191,8,
|
||||
7,5,7,193,8,7,10,7,12,7,196,9,7,1,7,1,7,1,8,1,8,1,8,1,8,1,8,1,8,3,8,206,
|
||||
8,8,1,8,5,8,209,8,8,10,8,12,8,212,9,8,1,8,3,8,215,8,8,1,8,1,8,1,8,1,8,
|
||||
1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,3,8,232,8,8,1,8,1,8,1,8,1,
|
||||
8,8,1,8,4,8,209,8,8,11,8,12,8,210,1,8,3,8,214,8,8,1,8,1,8,1,8,1,8,1,8,
|
||||
1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,3,8,231,8,8,1,8,1,8,1,8,1,8,1,
|
||||
8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,
|
||||
1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,
|
||||
8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,5,8,281,8,8,10,8,12,8,284,9,8,3,8,286,
|
||||
8,8,1,8,3,8,289,8,8,1,8,1,8,1,8,1,8,1,8,4,8,296,8,8,11,8,12,8,297,1,8,
|
||||
1,8,5,8,302,8,8,10,8,12,8,305,9,8,1,9,1,9,1,9,1,9,1,9,1,9,1,9,1,9,1,9,
|
||||
1,9,1,9,5,9,318,8,9,10,9,12,9,321,9,9,3,9,323,8,9,1,9,1,9,1,9,3,9,328,
|
||||
8,9,1,10,1,10,1,10,1,10,1,10,5,10,335,8,10,10,10,12,10,338,9,10,1,10,
|
||||
1,10,3,10,342,8,10,1,11,1,11,1,11,1,11,1,11,1,11,1,11,1,11,1,11,5,11,
|
||||
353,8,11,10,11,12,11,356,9,11,3,11,358,8,11,1,11,3,11,361,8,11,1,12,1,
|
||||
12,1,12,1,336,1,16,13,0,2,4,6,8,10,12,14,16,18,20,22,24,0,7,1,0,39,40,
|
||||
1,0,20,22,1,0,18,19,1,0,32,33,1,0,23,26,1,0,27,28,2,0,1,4,56,56,430,0,
|
||||
29,1,0,0,0,2,35,1,0,0,0,4,76,1,0,0,0,6,90,1,0,0,0,8,108,1,0,0,0,10,113,
|
||||
1,0,0,0,12,171,1,0,0,0,14,173,1,0,0,0,16,231,1,0,0,0,18,327,1,0,0,0,20,
|
||||
341,1,0,0,0,22,360,1,0,0,0,24,362,1,0,0,0,26,30,3,4,2,0,27,30,3,14,7,
|
||||
8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,5,8,280,8,8,10,8,12,8,283,9,8,3,8,285,8,
|
||||
8,1,8,3,8,288,8,8,1,8,1,8,1,8,1,8,1,8,4,8,295,8,8,11,8,12,8,296,1,8,1,
|
||||
8,5,8,301,8,8,10,8,12,8,304,9,8,1,9,1,9,1,9,1,9,1,9,1,9,1,9,1,9,1,9,1,
|
||||
9,1,9,5,9,317,8,9,10,9,12,9,320,9,9,3,9,322,8,9,1,9,1,9,1,9,3,9,327,8,
|
||||
9,1,10,1,10,1,10,1,10,1,10,5,10,334,8,10,10,10,12,10,337,9,10,1,10,1,
|
||||
10,3,10,341,8,10,1,11,1,11,1,11,1,11,1,11,1,11,1,11,1,11,1,11,5,11,352,
|
||||
8,11,10,11,12,11,355,9,11,3,11,357,8,11,1,11,3,11,360,8,11,1,12,1,12,
|
||||
1,12,1,335,1,16,13,0,2,4,6,8,10,12,14,16,18,20,22,24,0,7,1,0,39,40,1,
|
||||
0,20,22,1,0,18,19,1,0,32,33,1,0,23,26,1,0,27,28,2,0,1,4,56,56,429,0,29,
|
||||
1,0,0,0,2,35,1,0,0,0,4,76,1,0,0,0,6,90,1,0,0,0,8,108,1,0,0,0,10,113,1,
|
||||
0,0,0,12,171,1,0,0,0,14,173,1,0,0,0,16,230,1,0,0,0,18,326,1,0,0,0,20,
|
||||
340,1,0,0,0,22,359,1,0,0,0,24,361,1,0,0,0,26,30,3,4,2,0,27,30,3,14,7,
|
||||
0,28,30,3,2,1,0,29,26,1,0,0,0,29,27,1,0,0,0,29,28,1,0,0,0,30,31,1,0,0,
|
||||
0,31,29,1,0,0,0,31,32,1,0,0,0,32,33,1,0,0,0,33,34,5,0,0,1,34,1,1,0,0,
|
||||
0,35,40,3,24,12,0,36,37,5,46,0,0,37,39,5,47,0,0,38,36,1,0,0,0,39,42,1,
|
||||
@ -153,59 +153,58 @@ void mxparserParserInitialize() {
|
||||
186,187,5,51,0,0,187,190,5,56,0,0,188,189,5,38,0,0,189,191,3,16,8,0,190,
|
||||
188,1,0,0,0,190,191,1,0,0,0,191,193,1,0,0,0,192,186,1,0,0,0,193,196,1,
|
||||
0,0,0,194,192,1,0,0,0,194,195,1,0,0,0,195,197,1,0,0,0,196,194,1,0,0,0,
|
||||
197,198,5,50,0,0,198,15,1,0,0,0,199,200,6,8,-1,0,200,232,3,18,9,0,201,
|
||||
202,5,5,0,0,202,210,3,24,12,0,203,205,5,46,0,0,204,206,3,16,8,0,205,204,
|
||||
197,198,5,50,0,0,198,15,1,0,0,0,199,200,6,8,-1,0,200,231,3,18,9,0,201,
|
||||
202,5,5,0,0,202,208,3,24,12,0,203,205,5,46,0,0,204,206,3,16,8,0,205,204,
|
||||
1,0,0,0,205,206,1,0,0,0,206,207,1,0,0,0,207,209,5,47,0,0,208,203,1,0,
|
||||
0,0,209,212,1,0,0,0,210,208,1,0,0,0,210,211,1,0,0,0,211,214,1,0,0,0,212,
|
||||
210,1,0,0,0,213,215,3,22,11,0,214,213,1,0,0,0,214,215,1,0,0,0,215,232,
|
||||
1,0,0,0,216,217,5,5,0,0,217,218,3,24,12,0,218,219,5,44,0,0,219,220,5,
|
||||
45,0,0,220,232,1,0,0,0,221,222,5,5,0,0,222,232,3,24,12,0,223,224,7,0,
|
||||
0,0,224,232,3,16,8,16,225,226,5,19,0,0,226,232,3,16,8,15,227,228,5,31,
|
||||
0,0,228,232,3,16,8,14,229,230,5,37,0,0,230,232,3,16,8,13,231,199,1,0,
|
||||
0,0,231,201,1,0,0,0,231,216,1,0,0,0,231,221,1,0,0,0,231,223,1,0,0,0,231,
|
||||
225,1,0,0,0,231,227,1,0,0,0,231,229,1,0,0,0,232,303,1,0,0,0,233,234,10,
|
||||
12,0,0,234,235,7,1,0,0,235,302,3,16,8,13,236,237,10,11,0,0,237,238,7,
|
||||
2,0,0,238,302,3,16,8,12,239,240,10,10,0,0,240,241,7,3,0,0,241,302,3,16,
|
||||
8,11,242,243,10,9,0,0,243,244,7,4,0,0,244,302,3,16,8,10,245,246,10,8,
|
||||
0,0,246,247,7,5,0,0,247,302,3,16,8,9,248,249,10,7,0,0,249,250,5,34,0,
|
||||
0,250,302,3,16,8,8,251,252,10,6,0,0,252,253,5,36,0,0,253,302,3,16,8,7,
|
||||
254,255,10,5,0,0,255,256,5,35,0,0,256,302,3,16,8,6,257,258,10,4,0,0,258,
|
||||
259,5,29,0,0,259,302,3,16,8,5,260,261,10,3,0,0,261,262,5,30,0,0,262,302,
|
||||
3,16,8,4,263,264,10,2,0,0,264,265,5,42,0,0,265,266,3,16,8,0,266,267,5,
|
||||
43,0,0,267,268,3,16,8,2,268,302,1,0,0,0,269,270,10,1,0,0,270,271,5,38,
|
||||
0,0,271,302,3,16,8,1,272,273,10,19,0,0,273,288,5,41,0,0,274,289,5,56,
|
||||
0,0,275,276,5,56,0,0,276,285,5,44,0,0,277,282,3,16,8,0,278,279,5,51,0,
|
||||
0,279,281,3,16,8,0,280,278,1,0,0,0,281,284,1,0,0,0,282,280,1,0,0,0,282,
|
||||
283,1,0,0,0,283,286,1,0,0,0,284,282,1,0,0,0,285,277,1,0,0,0,285,286,1,
|
||||
0,0,0,286,287,1,0,0,0,287,289,5,45,0,0,288,274,1,0,0,0,288,275,1,0,0,
|
||||
0,289,302,1,0,0,0,290,295,10,18,0,0,291,292,5,46,0,0,292,293,3,16,8,0,
|
||||
293,294,5,47,0,0,294,296,1,0,0,0,295,291,1,0,0,0,296,297,1,0,0,0,297,
|
||||
295,1,0,0,0,297,298,1,0,0,0,298,302,1,0,0,0,299,300,10,17,0,0,300,302,
|
||||
7,0,0,0,301,233,1,0,0,0,301,236,1,0,0,0,301,239,1,0,0,0,301,242,1,0,0,
|
||||
0,301,245,1,0,0,0,301,248,1,0,0,0,301,251,1,0,0,0,301,254,1,0,0,0,301,
|
||||
257,1,0,0,0,301,260,1,0,0,0,301,263,1,0,0,0,301,269,1,0,0,0,301,272,1,
|
||||
0,0,0,301,290,1,0,0,0,301,299,1,0,0,0,302,305,1,0,0,0,303,301,1,0,0,0,
|
||||
303,304,1,0,0,0,304,17,1,0,0,0,305,303,1,0,0,0,306,328,5,10,0,0,307,308,
|
||||
5,44,0,0,308,309,3,16,8,0,309,310,5,45,0,0,310,328,1,0,0,0,311,328,5,
|
||||
56,0,0,312,313,5,56,0,0,313,322,5,44,0,0,314,319,3,16,8,0,315,316,5,51,
|
||||
0,0,316,318,3,16,8,0,317,315,1,0,0,0,318,321,1,0,0,0,319,317,1,0,0,0,
|
||||
319,320,1,0,0,0,320,323,1,0,0,0,321,319,1,0,0,0,322,314,1,0,0,0,322,323,
|
||||
1,0,0,0,323,324,1,0,0,0,324,328,5,45,0,0,325,328,3,20,10,0,326,328,3,
|
||||
22,11,0,327,306,1,0,0,0,327,307,1,0,0,0,327,311,1,0,0,0,327,312,1,0,0,
|
||||
0,327,325,1,0,0,0,327,326,1,0,0,0,328,19,1,0,0,0,329,342,5,52,0,0,330,
|
||||
331,5,53,0,0,331,336,3,16,8,0,332,333,5,55,0,0,333,335,3,16,8,0,334,332,
|
||||
1,0,0,0,335,338,1,0,0,0,336,337,1,0,0,0,336,334,1,0,0,0,337,339,1,0,0,
|
||||
0,338,336,1,0,0,0,339,340,5,54,0,0,340,342,1,0,0,0,341,329,1,0,0,0,341,
|
||||
330,1,0,0,0,342,21,1,0,0,0,343,361,5,8,0,0,344,361,5,9,0,0,345,361,5,
|
||||
57,0,0,346,361,5,58,0,0,347,361,5,7,0,0,348,357,5,48,0,0,349,354,3,22,
|
||||
11,0,350,351,5,51,0,0,351,353,3,22,11,0,352,350,1,0,0,0,353,356,1,0,0,
|
||||
0,354,352,1,0,0,0,354,355,1,0,0,0,355,358,1,0,0,0,356,354,1,0,0,0,357,
|
||||
349,1,0,0,0,357,358,1,0,0,0,358,359,1,0,0,0,359,361,5,49,0,0,360,343,
|
||||
1,0,0,0,360,344,1,0,0,0,360,345,1,0,0,0,360,346,1,0,0,0,360,347,1,0,0,
|
||||
0,360,348,1,0,0,0,361,23,1,0,0,0,362,363,7,6,0,0,363,25,1,0,0,0,41,29,
|
||||
31,40,50,61,68,71,82,84,95,103,117,134,149,152,157,165,167,171,178,184,
|
||||
190,194,205,210,214,231,282,285,288,297,301,303,319,322,327,336,341,354,
|
||||
357,360
|
||||
0,0,209,210,1,0,0,0,210,208,1,0,0,0,210,211,1,0,0,0,211,213,1,0,0,0,212,
|
||||
214,3,22,11,0,213,212,1,0,0,0,213,214,1,0,0,0,214,231,1,0,0,0,215,216,
|
||||
5,5,0,0,216,217,3,24,12,0,217,218,5,44,0,0,218,219,5,45,0,0,219,231,1,
|
||||
0,0,0,220,221,5,5,0,0,221,231,3,24,12,0,222,223,7,0,0,0,223,231,3,16,
|
||||
8,16,224,225,5,19,0,0,225,231,3,16,8,15,226,227,5,31,0,0,227,231,3,16,
|
||||
8,14,228,229,5,37,0,0,229,231,3,16,8,13,230,199,1,0,0,0,230,201,1,0,0,
|
||||
0,230,215,1,0,0,0,230,220,1,0,0,0,230,222,1,0,0,0,230,224,1,0,0,0,230,
|
||||
226,1,0,0,0,230,228,1,0,0,0,231,302,1,0,0,0,232,233,10,12,0,0,233,234,
|
||||
7,1,0,0,234,301,3,16,8,13,235,236,10,11,0,0,236,237,7,2,0,0,237,301,3,
|
||||
16,8,12,238,239,10,10,0,0,239,240,7,3,0,0,240,301,3,16,8,11,241,242,10,
|
||||
9,0,0,242,243,7,4,0,0,243,301,3,16,8,10,244,245,10,8,0,0,245,246,7,5,
|
||||
0,0,246,301,3,16,8,9,247,248,10,7,0,0,248,249,5,34,0,0,249,301,3,16,8,
|
||||
8,250,251,10,6,0,0,251,252,5,36,0,0,252,301,3,16,8,7,253,254,10,5,0,0,
|
||||
254,255,5,35,0,0,255,301,3,16,8,6,256,257,10,4,0,0,257,258,5,29,0,0,258,
|
||||
301,3,16,8,5,259,260,10,3,0,0,260,261,5,30,0,0,261,301,3,16,8,4,262,263,
|
||||
10,2,0,0,263,264,5,42,0,0,264,265,3,16,8,0,265,266,5,43,0,0,266,267,3,
|
||||
16,8,2,267,301,1,0,0,0,268,269,10,1,0,0,269,270,5,38,0,0,270,301,3,16,
|
||||
8,1,271,272,10,19,0,0,272,287,5,41,0,0,273,288,5,56,0,0,274,275,5,56,
|
||||
0,0,275,284,5,44,0,0,276,281,3,16,8,0,277,278,5,51,0,0,278,280,3,16,8,
|
||||
0,279,277,1,0,0,0,280,283,1,0,0,0,281,279,1,0,0,0,281,282,1,0,0,0,282,
|
||||
285,1,0,0,0,283,281,1,0,0,0,284,276,1,0,0,0,284,285,1,0,0,0,285,286,1,
|
||||
0,0,0,286,288,5,45,0,0,287,273,1,0,0,0,287,274,1,0,0,0,288,301,1,0,0,
|
||||
0,289,294,10,18,0,0,290,291,5,46,0,0,291,292,3,16,8,0,292,293,5,47,0,
|
||||
0,293,295,1,0,0,0,294,290,1,0,0,0,295,296,1,0,0,0,296,294,1,0,0,0,296,
|
||||
297,1,0,0,0,297,301,1,0,0,0,298,299,10,17,0,0,299,301,7,0,0,0,300,232,
|
||||
1,0,0,0,300,235,1,0,0,0,300,238,1,0,0,0,300,241,1,0,0,0,300,244,1,0,0,
|
||||
0,300,247,1,0,0,0,300,250,1,0,0,0,300,253,1,0,0,0,300,256,1,0,0,0,300,
|
||||
259,1,0,0,0,300,262,1,0,0,0,300,268,1,0,0,0,300,271,1,0,0,0,300,289,1,
|
||||
0,0,0,300,298,1,0,0,0,301,304,1,0,0,0,302,300,1,0,0,0,302,303,1,0,0,0,
|
||||
303,17,1,0,0,0,304,302,1,0,0,0,305,327,5,10,0,0,306,307,5,44,0,0,307,
|
||||
308,3,16,8,0,308,309,5,45,0,0,309,327,1,0,0,0,310,327,5,56,0,0,311,312,
|
||||
5,56,0,0,312,321,5,44,0,0,313,318,3,16,8,0,314,315,5,51,0,0,315,317,3,
|
||||
16,8,0,316,314,1,0,0,0,317,320,1,0,0,0,318,316,1,0,0,0,318,319,1,0,0,
|
||||
0,319,322,1,0,0,0,320,318,1,0,0,0,321,313,1,0,0,0,321,322,1,0,0,0,322,
|
||||
323,1,0,0,0,323,327,5,45,0,0,324,327,3,20,10,0,325,327,3,22,11,0,326,
|
||||
305,1,0,0,0,326,306,1,0,0,0,326,310,1,0,0,0,326,311,1,0,0,0,326,324,1,
|
||||
0,0,0,326,325,1,0,0,0,327,19,1,0,0,0,328,341,5,52,0,0,329,330,5,53,0,
|
||||
0,330,335,3,16,8,0,331,332,5,55,0,0,332,334,3,16,8,0,333,331,1,0,0,0,
|
||||
334,337,1,0,0,0,335,336,1,0,0,0,335,333,1,0,0,0,336,338,1,0,0,0,337,335,
|
||||
1,0,0,0,338,339,5,54,0,0,339,341,1,0,0,0,340,328,1,0,0,0,340,329,1,0,
|
||||
0,0,341,21,1,0,0,0,342,360,5,8,0,0,343,360,5,9,0,0,344,360,5,57,0,0,345,
|
||||
360,5,58,0,0,346,360,5,7,0,0,347,356,5,48,0,0,348,353,3,22,11,0,349,350,
|
||||
5,51,0,0,350,352,3,22,11,0,351,349,1,0,0,0,352,355,1,0,0,0,353,351,1,
|
||||
0,0,0,353,354,1,0,0,0,354,357,1,0,0,0,355,353,1,0,0,0,356,348,1,0,0,0,
|
||||
356,357,1,0,0,0,357,358,1,0,0,0,358,360,5,49,0,0,359,342,1,0,0,0,359,
|
||||
343,1,0,0,0,359,344,1,0,0,0,359,345,1,0,0,0,359,346,1,0,0,0,359,347,1,
|
||||
0,0,0,360,23,1,0,0,0,361,362,7,6,0,0,362,25,1,0,0,0,41,29,31,40,50,61,
|
||||
68,71,82,84,95,103,117,134,149,152,157,165,167,171,178,184,190,194,205,
|
||||
210,213,230,281,284,287,296,300,302,318,321,326,335,340,353,356,359
|
||||
};
|
||||
staticData->serializedATN = antlr4::atn::SerializedATNView(serializedATNSegment, sizeof(serializedATNSegment) / sizeof(serializedATNSegment[0]));
|
||||
|
||||
@ -2160,7 +2159,7 @@ MXParser::ExprContext* MXParser::expr(int precedence) {
|
||||
try {
|
||||
size_t alt;
|
||||
enterOuterAlt(_localctx, 1);
|
||||
setState(231);
|
||||
setState(230);
|
||||
_errHandler->sync(this);
|
||||
switch (getInterpreter<atn::ParserATNSimulator>()->adaptivePredict(_input, 26, _ctx)) {
|
||||
case 1: {
|
||||
@ -2181,35 +2180,41 @@ MXParser::ExprContext* MXParser::expr(int precedence) {
|
||||
match(MXParser::NEW);
|
||||
setState(202);
|
||||
type();
|
||||
setState(210);
|
||||
setState(208);
|
||||
_errHandler->sync(this);
|
||||
alt = getInterpreter<atn::ParserATNSimulator>()->adaptivePredict(_input, 24, _ctx);
|
||||
while (alt != 2 && alt != atn::ATN::INVALID_ALT_NUMBER) {
|
||||
if (alt == 1) {
|
||||
setState(203);
|
||||
match(MXParser::LBRACKET);
|
||||
setState(205);
|
||||
_errHandler->sync(this);
|
||||
alt = 1;
|
||||
do {
|
||||
switch (alt) {
|
||||
case 1: {
|
||||
setState(203);
|
||||
match(MXParser::LBRACKET);
|
||||
setState(205);
|
||||
_errHandler->sync(this);
|
||||
|
||||
_la = _input->LA(1);
|
||||
if ((((_la & ~ 0x3fULL) == 0) &&
|
||||
((1ULL << _la) & 518214813164767136) != 0)) {
|
||||
setState(204);
|
||||
expr(0);
|
||||
}
|
||||
setState(207);
|
||||
match(MXParser::RBRACKET);
|
||||
_la = _input->LA(1);
|
||||
if ((((_la & ~ 0x3fULL) == 0) &&
|
||||
((1ULL << _la) & 518214813164767136) != 0)) {
|
||||
setState(204);
|
||||
expr(0);
|
||||
}
|
||||
setState(207);
|
||||
match(MXParser::RBRACKET);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
throw NoViableAltException(this);
|
||||
}
|
||||
setState(212);
|
||||
setState(210);
|
||||
_errHandler->sync(this);
|
||||
alt = getInterpreter<atn::ParserATNSimulator>()->adaptivePredict(_input, 24, _ctx);
|
||||
}
|
||||
setState(214);
|
||||
} while (alt != 2 && alt != atn::ATN::INVALID_ALT_NUMBER);
|
||||
setState(213);
|
||||
_errHandler->sync(this);
|
||||
|
||||
switch (getInterpreter<atn::ParserATNSimulator>()->adaptivePredict(_input, 25, _ctx)) {
|
||||
case 1: {
|
||||
setState(213);
|
||||
setState(212);
|
||||
constant();
|
||||
break;
|
||||
}
|
||||
@ -2224,13 +2229,13 @@ MXParser::ExprContext* MXParser::expr(int precedence) {
|
||||
_localctx = _tracker.createInstance<New_construct_expressionContext>(_localctx);
|
||||
_ctx = _localctx;
|
||||
previousContext = _localctx;
|
||||
setState(216);
|
||||
setState(215);
|
||||
match(MXParser::NEW);
|
||||
setState(217);
|
||||
setState(216);
|
||||
type();
|
||||
setState(218);
|
||||
setState(217);
|
||||
match(MXParser::LPAREN);
|
||||
setState(219);
|
||||
setState(218);
|
||||
match(MXParser::RPAREN);
|
||||
break;
|
||||
}
|
||||
@ -2239,9 +2244,9 @@ MXParser::ExprContext* MXParser::expr(int precedence) {
|
||||
_localctx = _tracker.createInstance<New_expressionContext>(_localctx);
|
||||
_ctx = _localctx;
|
||||
previousContext = _localctx;
|
||||
setState(221);
|
||||
setState(220);
|
||||
match(MXParser::NEW);
|
||||
setState(222);
|
||||
setState(221);
|
||||
type();
|
||||
break;
|
||||
}
|
||||
@ -2250,7 +2255,7 @@ MXParser::ExprContext* MXParser::expr(int precedence) {
|
||||
_localctx = _tracker.createInstance<Prefix_expressionContext>(_localctx);
|
||||
_ctx = _localctx;
|
||||
previousContext = _localctx;
|
||||
setState(223);
|
||||
setState(222);
|
||||
_la = _input->LA(1);
|
||||
if (!(_la == MXParser::SELF_PLUS
|
||||
|
||||
@ -2261,7 +2266,7 @@ MXParser::ExprContext* MXParser::expr(int precedence) {
|
||||
_errHandler->reportMatch(this);
|
||||
consume();
|
||||
}
|
||||
setState(224);
|
||||
setState(223);
|
||||
expr(16);
|
||||
break;
|
||||
}
|
||||
@ -2270,9 +2275,9 @@ MXParser::ExprContext* MXParser::expr(int precedence) {
|
||||
_localctx = _tracker.createInstance<Opposite_expressionContext>(_localctx);
|
||||
_ctx = _localctx;
|
||||
previousContext = _localctx;
|
||||
setState(225);
|
||||
setState(224);
|
||||
match(MXParser::MINUS);
|
||||
setState(226);
|
||||
setState(225);
|
||||
expr(15);
|
||||
break;
|
||||
}
|
||||
@ -2281,9 +2286,9 @@ MXParser::ExprContext* MXParser::expr(int precedence) {
|
||||
_localctx = _tracker.createInstance<Lnot_expressionContext>(_localctx);
|
||||
_ctx = _localctx;
|
||||
previousContext = _localctx;
|
||||
setState(227);
|
||||
setState(226);
|
||||
match(MXParser::LNOT);
|
||||
setState(228);
|
||||
setState(227);
|
||||
expr(14);
|
||||
break;
|
||||
}
|
||||
@ -2292,9 +2297,9 @@ MXParser::ExprContext* MXParser::expr(int precedence) {
|
||||
_localctx = _tracker.createInstance<Bnot_expressionContext>(_localctx);
|
||||
_ctx = _localctx;
|
||||
previousContext = _localctx;
|
||||
setState(229);
|
||||
setState(228);
|
||||
match(MXParser::BNOT);
|
||||
setState(230);
|
||||
setState(229);
|
||||
expr(13);
|
||||
break;
|
||||
}
|
||||
@ -2303,7 +2308,7 @@ MXParser::ExprContext* MXParser::expr(int precedence) {
|
||||
break;
|
||||
}
|
||||
_ctx->stop = _input->LT(-1);
|
||||
setState(303);
|
||||
setState(302);
|
||||
_errHandler->sync(this);
|
||||
alt = getInterpreter<atn::ParserATNSimulator>()->adaptivePredict(_input, 32, _ctx);
|
||||
while (alt != 2 && alt != atn::ATN::INVALID_ALT_NUMBER) {
|
||||
@ -2311,17 +2316,17 @@ MXParser::ExprContext* MXParser::expr(int precedence) {
|
||||
if (!_parseListeners.empty())
|
||||
triggerExitRuleEvent();
|
||||
previousContext = _localctx;
|
||||
setState(301);
|
||||
setState(300);
|
||||
_errHandler->sync(this);
|
||||
switch (getInterpreter<atn::ParserATNSimulator>()->adaptivePredict(_input, 31, _ctx)) {
|
||||
case 1: {
|
||||
auto newContext = _tracker.createInstance<Mdm_expressionContext>(_tracker.createInstance<ExprContext>(parentContext, parentState));
|
||||
_localctx = newContext;
|
||||
pushNewRecursionContext(newContext, startState, RuleExpr);
|
||||
setState(233);
|
||||
setState(232);
|
||||
|
||||
if (!(precpred(_ctx, 12))) throw FailedPredicateException(this, "precpred(_ctx, 12)");
|
||||
setState(234);
|
||||
setState(233);
|
||||
_la = _input->LA(1);
|
||||
if (!((((_la & ~ 0x3fULL) == 0) &&
|
||||
((1ULL << _la) & 7340032) != 0))) {
|
||||
@ -2331,7 +2336,7 @@ MXParser::ExprContext* MXParser::expr(int precedence) {
|
||||
_errHandler->reportMatch(this);
|
||||
consume();
|
||||
}
|
||||
setState(235);
|
||||
setState(234);
|
||||
expr(13);
|
||||
break;
|
||||
}
|
||||
@ -2340,10 +2345,10 @@ MXParser::ExprContext* MXParser::expr(int precedence) {
|
||||
auto newContext = _tracker.createInstance<Pm_expressionContext>(_tracker.createInstance<ExprContext>(parentContext, parentState));
|
||||
_localctx = newContext;
|
||||
pushNewRecursionContext(newContext, startState, RuleExpr);
|
||||
setState(236);
|
||||
setState(235);
|
||||
|
||||
if (!(precpred(_ctx, 11))) throw FailedPredicateException(this, "precpred(_ctx, 11)");
|
||||
setState(237);
|
||||
setState(236);
|
||||
_la = _input->LA(1);
|
||||
if (!(_la == MXParser::PLUS
|
||||
|
||||
@ -2354,7 +2359,7 @@ MXParser::ExprContext* MXParser::expr(int precedence) {
|
||||
_errHandler->reportMatch(this);
|
||||
consume();
|
||||
}
|
||||
setState(238);
|
||||
setState(237);
|
||||
expr(12);
|
||||
break;
|
||||
}
|
||||
@ -2363,10 +2368,10 @@ MXParser::ExprContext* MXParser::expr(int precedence) {
|
||||
auto newContext = _tracker.createInstance<Rl_expressionContext>(_tracker.createInstance<ExprContext>(parentContext, parentState));
|
||||
_localctx = newContext;
|
||||
pushNewRecursionContext(newContext, startState, RuleExpr);
|
||||
setState(239);
|
||||
setState(238);
|
||||
|
||||
if (!(precpred(_ctx, 10))) throw FailedPredicateException(this, "precpred(_ctx, 10)");
|
||||
setState(240);
|
||||
setState(239);
|
||||
_la = _input->LA(1);
|
||||
if (!(_la == MXParser::ARS
|
||||
|
||||
@ -2377,7 +2382,7 @@ MXParser::ExprContext* MXParser::expr(int precedence) {
|
||||
_errHandler->reportMatch(this);
|
||||
consume();
|
||||
}
|
||||
setState(241);
|
||||
setState(240);
|
||||
expr(11);
|
||||
break;
|
||||
}
|
||||
@ -2386,10 +2391,10 @@ MXParser::ExprContext* MXParser::expr(int precedence) {
|
||||
auto newContext = _tracker.createInstance<Ggll_expressionContext>(_tracker.createInstance<ExprContext>(parentContext, parentState));
|
||||
_localctx = newContext;
|
||||
pushNewRecursionContext(newContext, startState, RuleExpr);
|
||||
setState(242);
|
||||
setState(241);
|
||||
|
||||
if (!(precpred(_ctx, 9))) throw FailedPredicateException(this, "precpred(_ctx, 9)");
|
||||
setState(243);
|
||||
setState(242);
|
||||
_la = _input->LA(1);
|
||||
if (!((((_la & ~ 0x3fULL) == 0) &&
|
||||
((1ULL << _la) & 125829120) != 0))) {
|
||||
@ -2399,7 +2404,7 @@ MXParser::ExprContext* MXParser::expr(int precedence) {
|
||||
_errHandler->reportMatch(this);
|
||||
consume();
|
||||
}
|
||||
setState(244);
|
||||
setState(243);
|
||||
expr(10);
|
||||
break;
|
||||
}
|
||||
@ -2408,10 +2413,10 @@ MXParser::ExprContext* MXParser::expr(int precedence) {
|
||||
auto newContext = _tracker.createInstance<Ne_expressionContext>(_tracker.createInstance<ExprContext>(parentContext, parentState));
|
||||
_localctx = newContext;
|
||||
pushNewRecursionContext(newContext, startState, RuleExpr);
|
||||
setState(245);
|
||||
setState(244);
|
||||
|
||||
if (!(precpred(_ctx, 8))) throw FailedPredicateException(this, "precpred(_ctx, 8)");
|
||||
setState(246);
|
||||
setState(245);
|
||||
_la = _input->LA(1);
|
||||
if (!(_la == MXParser::NE
|
||||
|
||||
@ -2422,7 +2427,7 @@ MXParser::ExprContext* MXParser::expr(int precedence) {
|
||||
_errHandler->reportMatch(this);
|
||||
consume();
|
||||
}
|
||||
setState(247);
|
||||
setState(246);
|
||||
expr(9);
|
||||
break;
|
||||
}
|
||||
@ -2431,12 +2436,12 @@ MXParser::ExprContext* MXParser::expr(int precedence) {
|
||||
auto newContext = _tracker.createInstance<Band_expressionContext>(_tracker.createInstance<ExprContext>(parentContext, parentState));
|
||||
_localctx = newContext;
|
||||
pushNewRecursionContext(newContext, startState, RuleExpr);
|
||||
setState(248);
|
||||
setState(247);
|
||||
|
||||
if (!(precpred(_ctx, 7))) throw FailedPredicateException(this, "precpred(_ctx, 7)");
|
||||
setState(249);
|
||||
setState(248);
|
||||
match(MXParser::BAND);
|
||||
setState(250);
|
||||
setState(249);
|
||||
expr(8);
|
||||
break;
|
||||
}
|
||||
@ -2445,12 +2450,12 @@ MXParser::ExprContext* MXParser::expr(int precedence) {
|
||||
auto newContext = _tracker.createInstance<Bxor_expressionContext>(_tracker.createInstance<ExprContext>(parentContext, parentState));
|
||||
_localctx = newContext;
|
||||
pushNewRecursionContext(newContext, startState, RuleExpr);
|
||||
setState(251);
|
||||
setState(250);
|
||||
|
||||
if (!(precpred(_ctx, 6))) throw FailedPredicateException(this, "precpred(_ctx, 6)");
|
||||
setState(252);
|
||||
setState(251);
|
||||
match(MXParser::BXOR);
|
||||
setState(253);
|
||||
setState(252);
|
||||
expr(7);
|
||||
break;
|
||||
}
|
||||
@ -2459,12 +2464,12 @@ MXParser::ExprContext* MXParser::expr(int precedence) {
|
||||
auto newContext = _tracker.createInstance<Bor_expressionContext>(_tracker.createInstance<ExprContext>(parentContext, parentState));
|
||||
_localctx = newContext;
|
||||
pushNewRecursionContext(newContext, startState, RuleExpr);
|
||||
setState(254);
|
||||
setState(253);
|
||||
|
||||
if (!(precpred(_ctx, 5))) throw FailedPredicateException(this, "precpred(_ctx, 5)");
|
||||
setState(255);
|
||||
setState(254);
|
||||
match(MXParser::BOR);
|
||||
setState(256);
|
||||
setState(255);
|
||||
expr(6);
|
||||
break;
|
||||
}
|
||||
@ -2473,12 +2478,12 @@ MXParser::ExprContext* MXParser::expr(int precedence) {
|
||||
auto newContext = _tracker.createInstance<Land_expressionContext>(_tracker.createInstance<ExprContext>(parentContext, parentState));
|
||||
_localctx = newContext;
|
||||
pushNewRecursionContext(newContext, startState, RuleExpr);
|
||||
setState(257);
|
||||
setState(256);
|
||||
|
||||
if (!(precpred(_ctx, 4))) throw FailedPredicateException(this, "precpred(_ctx, 4)");
|
||||
setState(258);
|
||||
setState(257);
|
||||
match(MXParser::LAND);
|
||||
setState(259);
|
||||
setState(258);
|
||||
expr(5);
|
||||
break;
|
||||
}
|
||||
@ -2487,12 +2492,12 @@ MXParser::ExprContext* MXParser::expr(int precedence) {
|
||||
auto newContext = _tracker.createInstance<Lor_expressionContext>(_tracker.createInstance<ExprContext>(parentContext, parentState));
|
||||
_localctx = newContext;
|
||||
pushNewRecursionContext(newContext, startState, RuleExpr);
|
||||
setState(260);
|
||||
setState(259);
|
||||
|
||||
if (!(precpred(_ctx, 3))) throw FailedPredicateException(this, "precpred(_ctx, 3)");
|
||||
setState(261);
|
||||
setState(260);
|
||||
match(MXParser::LOR);
|
||||
setState(262);
|
||||
setState(261);
|
||||
expr(4);
|
||||
break;
|
||||
}
|
||||
@ -2501,16 +2506,16 @@ MXParser::ExprContext* MXParser::expr(int precedence) {
|
||||
auto newContext = _tracker.createInstance<Ternary_expressionContext>(_tracker.createInstance<ExprContext>(parentContext, parentState));
|
||||
_localctx = newContext;
|
||||
pushNewRecursionContext(newContext, startState, RuleExpr);
|
||||
setState(263);
|
||||
setState(262);
|
||||
|
||||
if (!(precpred(_ctx, 2))) throw FailedPredicateException(this, "precpred(_ctx, 2)");
|
||||
setState(264);
|
||||
setState(263);
|
||||
match(MXParser::QUESTION_MARK);
|
||||
setState(265);
|
||||
setState(264);
|
||||
expr(0);
|
||||
setState(266);
|
||||
setState(265);
|
||||
match(MXParser::COLON);
|
||||
setState(267);
|
||||
setState(266);
|
||||
expr(2);
|
||||
break;
|
||||
}
|
||||
@ -2519,12 +2524,12 @@ MXParser::ExprContext* MXParser::expr(int precedence) {
|
||||
auto newContext = _tracker.createInstance<Assign_expressionContext>(_tracker.createInstance<ExprContext>(parentContext, parentState));
|
||||
_localctx = newContext;
|
||||
pushNewRecursionContext(newContext, startState, RuleExpr);
|
||||
setState(269);
|
||||
setState(268);
|
||||
|
||||
if (!(precpred(_ctx, 1))) throw FailedPredicateException(this, "precpred(_ctx, 1)");
|
||||
setState(270);
|
||||
setState(269);
|
||||
match(MXParser::ASSIGN);
|
||||
setState(271);
|
||||
setState(270);
|
||||
expr(1);
|
||||
break;
|
||||
}
|
||||
@ -2533,47 +2538,47 @@ MXParser::ExprContext* MXParser::expr(int precedence) {
|
||||
auto newContext = _tracker.createInstance<Access_expressionContext>(_tracker.createInstance<ExprContext>(parentContext, parentState));
|
||||
_localctx = newContext;
|
||||
pushNewRecursionContext(newContext, startState, RuleExpr);
|
||||
setState(272);
|
||||
setState(271);
|
||||
|
||||
if (!(precpred(_ctx, 19))) throw FailedPredicateException(this, "precpred(_ctx, 19)");
|
||||
setState(273);
|
||||
setState(272);
|
||||
match(MXParser::DOT);
|
||||
setState(288);
|
||||
setState(287);
|
||||
_errHandler->sync(this);
|
||||
switch (getInterpreter<atn::ParserATNSimulator>()->adaptivePredict(_input, 29, _ctx)) {
|
||||
case 1: {
|
||||
setState(274);
|
||||
setState(273);
|
||||
match(MXParser::ID);
|
||||
break;
|
||||
}
|
||||
|
||||
case 2: {
|
||||
setState(275);
|
||||
setState(274);
|
||||
match(MXParser::ID);
|
||||
setState(276);
|
||||
setState(275);
|
||||
match(MXParser::LPAREN);
|
||||
setState(285);
|
||||
setState(284);
|
||||
_errHandler->sync(this);
|
||||
|
||||
_la = _input->LA(1);
|
||||
if ((((_la & ~ 0x3fULL) == 0) &&
|
||||
((1ULL << _la) & 518214813164767136) != 0)) {
|
||||
setState(277);
|
||||
setState(276);
|
||||
expr(0);
|
||||
setState(282);
|
||||
setState(281);
|
||||
_errHandler->sync(this);
|
||||
_la = _input->LA(1);
|
||||
while (_la == MXParser::COMMA) {
|
||||
setState(278);
|
||||
setState(277);
|
||||
match(MXParser::COMMA);
|
||||
setState(279);
|
||||
setState(278);
|
||||
expr(0);
|
||||
setState(284);
|
||||
setState(283);
|
||||
_errHandler->sync(this);
|
||||
_la = _input->LA(1);
|
||||
}
|
||||
}
|
||||
setState(287);
|
||||
setState(286);
|
||||
match(MXParser::RPAREN);
|
||||
break;
|
||||
}
|
||||
@ -2588,20 +2593,20 @@ MXParser::ExprContext* MXParser::expr(int precedence) {
|
||||
auto newContext = _tracker.createInstance<Index_expressionContext>(_tracker.createInstance<ExprContext>(parentContext, parentState));
|
||||
_localctx = newContext;
|
||||
pushNewRecursionContext(newContext, startState, RuleExpr);
|
||||
setState(290);
|
||||
setState(289);
|
||||
|
||||
if (!(precpred(_ctx, 18))) throw FailedPredicateException(this, "precpred(_ctx, 18)");
|
||||
setState(295);
|
||||
setState(294);
|
||||
_errHandler->sync(this);
|
||||
alt = 1;
|
||||
do {
|
||||
switch (alt) {
|
||||
case 1: {
|
||||
setState(291);
|
||||
setState(290);
|
||||
match(MXParser::LBRACKET);
|
||||
setState(292);
|
||||
setState(291);
|
||||
expr(0);
|
||||
setState(293);
|
||||
setState(292);
|
||||
match(MXParser::RBRACKET);
|
||||
break;
|
||||
}
|
||||
@ -2609,7 +2614,7 @@ MXParser::ExprContext* MXParser::expr(int precedence) {
|
||||
default:
|
||||
throw NoViableAltException(this);
|
||||
}
|
||||
setState(297);
|
||||
setState(296);
|
||||
_errHandler->sync(this);
|
||||
alt = getInterpreter<atn::ParserATNSimulator>()->adaptivePredict(_input, 30, _ctx);
|
||||
} while (alt != 2 && alt != atn::ATN::INVALID_ALT_NUMBER);
|
||||
@ -2620,10 +2625,10 @@ MXParser::ExprContext* MXParser::expr(int precedence) {
|
||||
auto newContext = _tracker.createInstance<Suffix_expressionContext>(_tracker.createInstance<ExprContext>(parentContext, parentState));
|
||||
_localctx = newContext;
|
||||
pushNewRecursionContext(newContext, startState, RuleExpr);
|
||||
setState(299);
|
||||
setState(298);
|
||||
|
||||
if (!(precpred(_ctx, 17))) throw FailedPredicateException(this, "precpred(_ctx, 17)");
|
||||
setState(300);
|
||||
setState(299);
|
||||
_la = _input->LA(1);
|
||||
if (!(_la == MXParser::SELF_PLUS
|
||||
|
||||
@ -2641,7 +2646,7 @@ MXParser::ExprContext* MXParser::expr(int precedence) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
setState(305);
|
||||
setState(304);
|
||||
_errHandler->sync(this);
|
||||
alt = getInterpreter<atn::ParserATNSimulator>()->adaptivePredict(_input, 32, _ctx);
|
||||
}
|
||||
@ -2804,13 +2809,13 @@ MXParser::Basic_exprContext* MXParser::basic_expr() {
|
||||
exitRule();
|
||||
});
|
||||
try {
|
||||
setState(327);
|
||||
setState(326);
|
||||
_errHandler->sync(this);
|
||||
switch (getInterpreter<atn::ParserATNSimulator>()->adaptivePredict(_input, 35, _ctx)) {
|
||||
case 1: {
|
||||
_localctx = _tracker.createInstance<MXParser::This_exprContext>(_localctx);
|
||||
enterOuterAlt(_localctx, 1);
|
||||
setState(306);
|
||||
setState(305);
|
||||
match(MXParser::THIS);
|
||||
break;
|
||||
}
|
||||
@ -2818,11 +2823,11 @@ MXParser::Basic_exprContext* MXParser::basic_expr() {
|
||||
case 2: {
|
||||
_localctx = _tracker.createInstance<MXParser::Paren_exprContext>(_localctx);
|
||||
enterOuterAlt(_localctx, 2);
|
||||
setState(307);
|
||||
setState(306);
|
||||
match(MXParser::LPAREN);
|
||||
setState(308);
|
||||
setState(307);
|
||||
expr(0);
|
||||
setState(309);
|
||||
setState(308);
|
||||
match(MXParser::RPAREN);
|
||||
break;
|
||||
}
|
||||
@ -2830,7 +2835,7 @@ MXParser::Basic_exprContext* MXParser::basic_expr() {
|
||||
case 3: {
|
||||
_localctx = _tracker.createInstance<MXParser::Id_exprContext>(_localctx);
|
||||
enterOuterAlt(_localctx, 3);
|
||||
setState(311);
|
||||
setState(310);
|
||||
match(MXParser::ID);
|
||||
break;
|
||||
}
|
||||
@ -2838,32 +2843,32 @@ MXParser::Basic_exprContext* MXParser::basic_expr() {
|
||||
case 4: {
|
||||
_localctx = _tracker.createInstance<MXParser::Function_call_exprContext>(_localctx);
|
||||
enterOuterAlt(_localctx, 4);
|
||||
setState(312);
|
||||
setState(311);
|
||||
match(MXParser::ID);
|
||||
setState(313);
|
||||
setState(312);
|
||||
match(MXParser::LPAREN);
|
||||
setState(322);
|
||||
setState(321);
|
||||
_errHandler->sync(this);
|
||||
|
||||
_la = _input->LA(1);
|
||||
if ((((_la & ~ 0x3fULL) == 0) &&
|
||||
((1ULL << _la) & 518214813164767136) != 0)) {
|
||||
setState(314);
|
||||
setState(313);
|
||||
expr(0);
|
||||
setState(319);
|
||||
setState(318);
|
||||
_errHandler->sync(this);
|
||||
_la = _input->LA(1);
|
||||
while (_la == MXParser::COMMA) {
|
||||
setState(315);
|
||||
setState(314);
|
||||
match(MXParser::COMMA);
|
||||
setState(316);
|
||||
setState(315);
|
||||
expr(0);
|
||||
setState(321);
|
||||
setState(320);
|
||||
_errHandler->sync(this);
|
||||
_la = _input->LA(1);
|
||||
}
|
||||
}
|
||||
setState(324);
|
||||
setState(323);
|
||||
match(MXParser::RPAREN);
|
||||
break;
|
||||
}
|
||||
@ -2871,7 +2876,7 @@ MXParser::Basic_exprContext* MXParser::basic_expr() {
|
||||
case 5: {
|
||||
_localctx = _tracker.createInstance<MXParser::Formatted_string_exprContext>(_localctx);
|
||||
enterOuterAlt(_localctx, 5);
|
||||
setState(325);
|
||||
setState(324);
|
||||
formatted_string();
|
||||
break;
|
||||
}
|
||||
@ -2879,7 +2884,7 @@ MXParser::Basic_exprContext* MXParser::basic_expr() {
|
||||
case 6: {
|
||||
_localctx = _tracker.createInstance<MXParser::Constant_exprContext>(_localctx);
|
||||
enterOuterAlt(_localctx, 6);
|
||||
setState(326);
|
||||
setState(325);
|
||||
constant();
|
||||
break;
|
||||
}
|
||||
@ -2958,37 +2963,37 @@ MXParser::Formatted_stringContext* MXParser::formatted_string() {
|
||||
});
|
||||
try {
|
||||
size_t alt;
|
||||
setState(341);
|
||||
setState(340);
|
||||
_errHandler->sync(this);
|
||||
switch (_input->LA(1)) {
|
||||
case MXParser::FORMAT_STRING_WHOLE: {
|
||||
enterOuterAlt(_localctx, 1);
|
||||
setState(329);
|
||||
setState(328);
|
||||
match(MXParser::FORMAT_STRING_WHOLE);
|
||||
break;
|
||||
}
|
||||
|
||||
case MXParser::FORMAT_STRING_HEAD: {
|
||||
enterOuterAlt(_localctx, 2);
|
||||
setState(330);
|
||||
setState(329);
|
||||
match(MXParser::FORMAT_STRING_HEAD);
|
||||
setState(331);
|
||||
setState(330);
|
||||
expr(0);
|
||||
setState(336);
|
||||
setState(335);
|
||||
_errHandler->sync(this);
|
||||
alt = getInterpreter<atn::ParserATNSimulator>()->adaptivePredict(_input, 36, _ctx);
|
||||
while (alt != 1 && alt != atn::ATN::INVALID_ALT_NUMBER) {
|
||||
if (alt == 1 + 1) {
|
||||
setState(332);
|
||||
setState(331);
|
||||
match(MXParser::FORMAT_STRING_BODY);
|
||||
setState(333);
|
||||
setState(332);
|
||||
expr(0);
|
||||
}
|
||||
setState(338);
|
||||
setState(337);
|
||||
_errHandler->sync(this);
|
||||
alt = getInterpreter<atn::ParserATNSimulator>()->adaptivePredict(_input, 36, _ctx);
|
||||
}
|
||||
setState(339);
|
||||
setState(338);
|
||||
match(MXParser::FORMAT_STRING_TAIL);
|
||||
break;
|
||||
}
|
||||
@ -3083,70 +3088,70 @@ MXParser::ConstantContext* MXParser::constant() {
|
||||
exitRule();
|
||||
});
|
||||
try {
|
||||
setState(360);
|
||||
setState(359);
|
||||
_errHandler->sync(this);
|
||||
switch (_input->LA(1)) {
|
||||
case MXParser::TRUE: {
|
||||
enterOuterAlt(_localctx, 1);
|
||||
setState(343);
|
||||
setState(342);
|
||||
match(MXParser::TRUE);
|
||||
break;
|
||||
}
|
||||
|
||||
case MXParser::FALSE: {
|
||||
enterOuterAlt(_localctx, 2);
|
||||
setState(344);
|
||||
setState(343);
|
||||
match(MXParser::FALSE);
|
||||
break;
|
||||
}
|
||||
|
||||
case MXParser::INT_LITERAL: {
|
||||
enterOuterAlt(_localctx, 3);
|
||||
setState(345);
|
||||
setState(344);
|
||||
match(MXParser::INT_LITERAL);
|
||||
break;
|
||||
}
|
||||
|
||||
case MXParser::STRING_LITERAL: {
|
||||
enterOuterAlt(_localctx, 4);
|
||||
setState(346);
|
||||
setState(345);
|
||||
match(MXParser::STRING_LITERAL);
|
||||
break;
|
||||
}
|
||||
|
||||
case MXParser::NULL_: {
|
||||
enterOuterAlt(_localctx, 5);
|
||||
setState(347);
|
||||
setState(346);
|
||||
match(MXParser::NULL_);
|
||||
break;
|
||||
}
|
||||
|
||||
case MXParser::LBRACE: {
|
||||
enterOuterAlt(_localctx, 6);
|
||||
setState(348);
|
||||
setState(347);
|
||||
match(MXParser::LBRACE);
|
||||
setState(357);
|
||||
setState(356);
|
||||
_errHandler->sync(this);
|
||||
|
||||
_la = _input->LA(1);
|
||||
if ((((_la & ~ 0x3fULL) == 0) &&
|
||||
((1ULL << _la) & 432627039204279168) != 0)) {
|
||||
setState(349);
|
||||
setState(348);
|
||||
constant();
|
||||
setState(354);
|
||||
setState(353);
|
||||
_errHandler->sync(this);
|
||||
_la = _input->LA(1);
|
||||
while (_la == MXParser::COMMA) {
|
||||
setState(350);
|
||||
setState(349);
|
||||
match(MXParser::COMMA);
|
||||
setState(351);
|
||||
setState(350);
|
||||
constant();
|
||||
setState(356);
|
||||
setState(355);
|
||||
_errHandler->sync(this);
|
||||
_la = _input->LA(1);
|
||||
}
|
||||
}
|
||||
setState(359);
|
||||
setState(358);
|
||||
match(MXParser::RBRACE);
|
||||
break;
|
||||
}
|
||||
@ -3218,7 +3223,7 @@ MXParser::TypeContext* MXParser::type() {
|
||||
});
|
||||
try {
|
||||
enterOuterAlt(_localctx, 1);
|
||||
setState(362);
|
||||
setState(361);
|
||||
_la = _input->LA(1);
|
||||
if (!((((_la & ~ 0x3fULL) == 0) &&
|
||||
((1ULL << _la) & 72057594037927966) != 0))) {
|
||||
|
File diff suppressed because one or more lines are too long
@ -19,12 +19,12 @@ class MXErrorListener : public antlr4::BaseErrorListener {
|
||||
}
|
||||
bool IsOk() { return no_problem; }
|
||||
};
|
||||
std::shared_ptr<ASTNodeBase> BuildAST(Visitor *visitor, antlr4::tree::ParseTree *tree) {
|
||||
std::shared_ptr<Program_ASTNode> BuildAST(Visitor *visitor, antlr4::tree::ParseTree *tree) {
|
||||
return std::any_cast<std::shared_ptr<Program_ASTNode>>(visitor->visit(tree));
|
||||
}
|
||||
std::shared_ptr<ASTNodeBase> CheckAndDecorate(std::shared_ptr<ASTNodeBase> src) { ; }
|
||||
std::shared_ptr<Program_ASTNode> CheckAndDecorate(std::shared_ptr<Program_ASTNode> src) { return nullptr; }
|
||||
|
||||
void SemanticCheck(std::istream &fin, std::shared_ptr<ASTNodeBase> &ast_out) {
|
||||
void SemanticCheck(std::istream &fin, std::shared_ptr<Program_ASTNode> &ast_out) {
|
||||
antlr4::ANTLRInputStream input(fin);
|
||||
MXLexer lexer(&input);
|
||||
antlr4::CommonTokenStream tokens(&lexer);
|
||||
@ -36,6 +36,6 @@ void SemanticCheck(std::istream &fin, std::shared_ptr<ASTNodeBase> &ast_out) {
|
||||
antlr4::tree::ParseTree *tree = parser.mxprog();
|
||||
if (!error_listener.IsOk()) throw SemanticError("Fatal error: syntax error", 1);
|
||||
Visitor visitor;
|
||||
std::shared_ptr<ASTNodeBase> ast = BuildAST(&visitor, tree);
|
||||
std::shared_ptr<Program_ASTNode> ast = BuildAST(&visitor, tree);
|
||||
ast_out = CheckAndDecorate(ast);
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
#include "MXParser.h"
|
||||
#include "MXParserVisitor.h"
|
||||
#include "ast/ast.h"
|
||||
#include "tools.h"
|
||||
|
||||
std::any Visitor::visitMxprog(MXParser::MxprogContext *context) {
|
||||
auto program = std::make_shared<Program_ASTNode>();
|
||||
@ -19,7 +20,8 @@ std::any Visitor::visitMxprog(MXParser::MxprogContext *context) {
|
||||
auto classNode = std::any_cast<std::shared_ptr<ClassDef_ASTNode>>(visit(classDefContext));
|
||||
program->classes.push_back(classNode);
|
||||
} else if (auto defineStmtContext = dynamic_cast<MXParser::Define_statementContext *>(def)) {
|
||||
auto defineNode = std::any_cast<std::shared_ptr<DefinitionStatement_ASTNode>>(visit(defineStmtContext));
|
||||
auto defineNode = std::dynamic_pointer_cast<DefinitionStatement_ASTNode>(
|
||||
std::any_cast<std::shared_ptr<Statement_ASTNode>>(visit(defineStmtContext)));
|
||||
program->global_variables.push_back(defineNode);
|
||||
} else if (auto funcDefContext = dynamic_cast<MXParser::Function_defContext *>(def)) {
|
||||
auto funcNode = std::any_cast<std::shared_ptr<FuncDef_ASTNode>>(visit(funcDefContext));
|
||||
@ -115,7 +117,8 @@ std::any Visitor::visitFunction_def(MXParser::Function_defContext *context) {
|
||||
func->params.push_back(std::make_pair(cur_para_name, cur_para_type));
|
||||
cur++;
|
||||
}
|
||||
func->func_body = std::any_cast<std::shared_ptr<SuiteStatement_ASTNode>>(visit(context->suite()));
|
||||
func->func_body = std::dynamic_pointer_cast<SuiteStatement_ASTNode>(
|
||||
std::any_cast<std::shared_ptr<Statement_ASTNode>>(visit(context->suite())));
|
||||
nodetype_stk.pop_back();
|
||||
return func;
|
||||
}
|
||||
@ -140,6 +143,12 @@ std::any Visitor::visitClass_def(MXParser::Class_defContext *context) {
|
||||
auto func_node = std::any_cast<std::shared_ptr<FuncDef_ASTNode>>(visit(func));
|
||||
class_def->member_functions.push_back(func_node);
|
||||
}
|
||||
std::vector<MXParser::Class_var_defContext *> vars = context->class_var_def();
|
||||
for (auto var : vars) {
|
||||
auto var_node = std::dynamic_pointer_cast<DefinitionStatement_ASTNode>(
|
||||
std::any_cast<std::shared_ptr<Statement_ASTNode>>(visit(var)));
|
||||
class_def->member_variables.push_back(var_node);
|
||||
}
|
||||
|
||||
nodetype_stk.pop_back();
|
||||
return class_def;
|
||||
@ -184,7 +193,7 @@ std::any Visitor::visitClass_var_def(MXParser::Class_var_defContext *context) {
|
||||
}
|
||||
|
||||
nodetype_stk.pop_back();
|
||||
return member_var_def;
|
||||
return std::static_pointer_cast<Statement_ASTNode>(member_var_def);
|
||||
}
|
||||
std::any Visitor::visitClass_constructor(MXParser::Class_constructorContext *context) {
|
||||
auto construct_func = std::make_shared<FuncDef_ASTNode>();
|
||||
@ -196,122 +205,648 @@ std::any Visitor::visitClass_constructor(MXParser::Class_constructorContext *con
|
||||
construct_func->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::Constructor);
|
||||
|
||||
construct_func->func_body = std::any_cast<std::shared_ptr<SuiteStatement_ASTNode>>(visit(context->suite()));
|
||||
construct_func->func_body = std::dynamic_pointer_cast<SuiteStatement_ASTNode>(
|
||||
std::any_cast<std::shared_ptr<Statement_ASTNode>>(visit(context->suite())));
|
||||
|
||||
nodetype_stk.pop_back();
|
||||
return construct_func;
|
||||
}
|
||||
std::any Visitor::visitSuite(MXParser::SuiteContext *context) { throw std::runtime_error("Not implemented"); }
|
||||
std::any Visitor::visitSuite(MXParser::SuiteContext *context) {
|
||||
auto suite_node = std::make_shared<SuiteStatement_ASTNode>();
|
||||
suite_node->type = ASTNodeType::SuiteStatement;
|
||||
suite_node->start_line = context->getStart()->getLine();
|
||||
suite_node->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
suite_node->end_line = context->getStop()->getLine();
|
||||
suite_node->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::SuiteStatement);
|
||||
|
||||
std::vector<MXParser::StatementContext *> stmts = context->statement();
|
||||
for (auto stmt : stmts) {
|
||||
auto stmt_node = std::any_cast<std::shared_ptr<Statement_ASTNode>>(visit(stmt));
|
||||
suite_node->statements.push_back(stmt_node);
|
||||
}
|
||||
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Statement_ASTNode>(suite_node);
|
||||
}
|
||||
std::any Visitor::visitEmpty_statement(MXParser::Empty_statementContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
auto stmt = std::make_shared<EmptyStatement_ASTNode>();
|
||||
stmt->type = ASTNodeType::EmptyStatement;
|
||||
stmt->start_line = context->getStart()->getLine();
|
||||
stmt->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
stmt->end_line = context->getStop()->getLine();
|
||||
stmt->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
return std::static_pointer_cast<Statement_ASTNode>(stmt);
|
||||
}
|
||||
std::any Visitor::visitDefinition_statement(MXParser::Definition_statementContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
return visit(context->define_statement());
|
||||
}
|
||||
std::any Visitor::visitExpr_statement(MXParser::Expr_statementContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
auto expr_stmt = std::make_shared<ExprStatement_ASTNode>();
|
||||
expr_stmt->type = ASTNodeType::ExprStatement;
|
||||
expr_stmt->start_line = context->getStart()->getLine();
|
||||
expr_stmt->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
expr_stmt->end_line = context->getStop()->getLine();
|
||||
expr_stmt->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::ExprStatement);
|
||||
expr_stmt->expr = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->expr()));
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Statement_ASTNode>(expr_stmt);
|
||||
}
|
||||
std::any Visitor::visitIf_statement(MXParser::If_statementContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
auto if_stmt = std::make_shared<IfStatement_ASTNode>();
|
||||
if_stmt->type = ASTNodeType::IfStatement;
|
||||
if_stmt->start_line = context->getStart()->getLine();
|
||||
if_stmt->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
if_stmt->end_line = context->getStop()->getLine();
|
||||
if_stmt->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::IfStatement);
|
||||
if_stmt->condition = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->expr()));
|
||||
std::vector<MXParser::StatementContext *> sub_stmts = context->statement();
|
||||
if_stmt->if_clause = std::any_cast<std::shared_ptr<Statement_ASTNode>>(visit(sub_stmts[0]));
|
||||
if (sub_stmts.size() > 1) {
|
||||
if_stmt->has_else_clause = true;
|
||||
if_stmt->else_clause = std::any_cast<std::shared_ptr<Statement_ASTNode>>(visit(sub_stmts[1]));
|
||||
} else {
|
||||
if_stmt->has_else_clause = false;
|
||||
if_stmt->else_clause = nullptr;
|
||||
}
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Statement_ASTNode>(if_stmt);
|
||||
}
|
||||
std::any Visitor::visitWhile_statement(MXParser::While_statementContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
auto while_stmt = std::make_shared<WhileStatement_ASTNode>();
|
||||
while_stmt->type = ASTNodeType::WhileStatement;
|
||||
while_stmt->start_line = context->getStart()->getLine();
|
||||
while_stmt->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
while_stmt->end_line = context->getStop()->getLine();
|
||||
while_stmt->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::WhileStatement);
|
||||
while_stmt->condition = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->expr()));
|
||||
while_stmt->loop_body = std::any_cast<std::shared_ptr<Statement_ASTNode>>(visit(context->statement()));
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Statement_ASTNode>(while_stmt);
|
||||
}
|
||||
std::any Visitor::visitFor_statement(MXParser::For_statementContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
auto for_stmt = std::make_shared<ForStatement_ASTNode>();
|
||||
for_stmt->type = ASTNodeType::ForStatement;
|
||||
for_stmt->start_line = context->getStart()->getLine();
|
||||
for_stmt->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
for_stmt->end_line = context->getStop()->getLine();
|
||||
for_stmt->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::ForStatement);
|
||||
size_t cur = 2;
|
||||
if (dynamic_cast<antlr4::tree::TerminalNode *>(context->children[cur]) != nullptr &&
|
||||
dynamic_cast<antlr4::tree::TerminalNode *>(context->children[cur])->getSymbol()->getType() ==
|
||||
MXParser::SEMICOLON) {
|
||||
for_stmt->initial = nullptr;
|
||||
cur += 1;
|
||||
} else if (dynamic_cast<MXParser::Define_statementContext *>(context->children[cur]) != nullptr) {
|
||||
for_stmt->initial = std::dynamic_pointer_cast<Statement_ASTNode>(
|
||||
std::any_cast<std::shared_ptr<Statement_ASTNode>>(visit(context->children[cur])));
|
||||
cur += 1;
|
||||
} else if (dynamic_cast<MXParser::ExprContext *>(context->children[cur]) != nullptr) {
|
||||
auto expr = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->children[cur]));
|
||||
auto expr_stmt = std::make_shared<ExprStatement_ASTNode>();
|
||||
expr_stmt->type = ASTNodeType::ExprStatement;
|
||||
expr_stmt->start_line = expr->start_line;
|
||||
expr_stmt->start_char_pos = expr->start_char_pos;
|
||||
expr_stmt->end_line = expr->end_line;
|
||||
expr_stmt->end_char_pos = expr->end_char_pos;
|
||||
expr_stmt->expr = expr;
|
||||
for_stmt->initial = std::static_pointer_cast<Statement_ASTNode>(expr_stmt);
|
||||
cur += 2;
|
||||
} else {
|
||||
throw std::runtime_error("unknown subnode occurred in visitFor_statement");
|
||||
}
|
||||
if (dynamic_cast<antlr4::tree::TerminalNode *>(context->children[cur]) != nullptr &&
|
||||
dynamic_cast<antlr4::tree::TerminalNode *>(context->children[cur])->getSymbol()->getType() ==
|
||||
MXParser::SEMICOLON) {
|
||||
for_stmt->condition = nullptr;
|
||||
cur += 1;
|
||||
} else {
|
||||
for_stmt->condition = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->children[cur]));
|
||||
cur += 2;
|
||||
}
|
||||
if (dynamic_cast<MXParser::Define_statementContext *>(context->children[cur]) != nullptr) {
|
||||
for_stmt->update = std::dynamic_pointer_cast<Statement_ASTNode>(
|
||||
std::any_cast<std::shared_ptr<Statement_ASTNode>>(visit(context->children[cur])));
|
||||
cur += 1;
|
||||
} else if (dynamic_cast<MXParser::ExprContext *>(context->children[cur]) != nullptr) {
|
||||
auto expr = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->children[cur]));
|
||||
auto expr_stmt = std::make_shared<ExprStatement_ASTNode>();
|
||||
expr_stmt->type = ASTNodeType::ExprStatement;
|
||||
expr_stmt->start_line = expr->start_line;
|
||||
expr_stmt->start_char_pos = expr->start_char_pos;
|
||||
expr_stmt->end_line = expr->end_line;
|
||||
expr_stmt->end_char_pos = expr->end_char_pos;
|
||||
expr_stmt->expr = expr;
|
||||
for_stmt->update = std::static_pointer_cast<Statement_ASTNode>(expr_stmt);
|
||||
cur += 2;
|
||||
} else {
|
||||
throw std::runtime_error("unknown subnode occurred in visitFor_statement");
|
||||
}
|
||||
for_stmt->loop_body = std::any_cast<std::shared_ptr<Statement_ASTNode>>(visit(context->children[cur]));
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Statement_ASTNode>(for_stmt);
|
||||
}
|
||||
std::any Visitor::visitJmp_statement(MXParser::Jmp_statementContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
}
|
||||
std::any Visitor::visitSuite_statement(MXParser::Suite_statementContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
auto jmp_stmt = std::make_shared<JmpStatement_ASTNode>();
|
||||
jmp_stmt->type = ASTNodeType::JmpStatement;
|
||||
jmp_stmt->start_line = context->getStart()->getLine();
|
||||
jmp_stmt->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
jmp_stmt->end_line = context->getStop()->getLine();
|
||||
jmp_stmt->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::JmpStatement);
|
||||
if (context->RETURN() != nullptr) {
|
||||
jmp_stmt->jmp_type = 0;
|
||||
if (context->expr() != nullptr) {
|
||||
jmp_stmt->return_value = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->expr()));
|
||||
} else {
|
||||
jmp_stmt->return_value = nullptr;
|
||||
}
|
||||
} else if (context->BREAK() != nullptr) {
|
||||
jmp_stmt->jmp_type = 1;
|
||||
jmp_stmt->return_value = nullptr;
|
||||
} else if (context->CONTINUE() != nullptr) {
|
||||
jmp_stmt->jmp_type = 2;
|
||||
jmp_stmt->return_value = nullptr;
|
||||
} else {
|
||||
throw std::runtime_error("unknown jmp statement type");
|
||||
}
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Statement_ASTNode>(jmp_stmt);
|
||||
}
|
||||
std::any Visitor::visitSuite_statement(MXParser::Suite_statementContext *context) { return visit(context->suite()); }
|
||||
std::any Visitor::visitDefine_statement(MXParser::Define_statementContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
// define_statement : type (LBRACKET RBRACKET)* ID (ASSIGN expr)? (COMMA ID (ASSIGN expr)?)* SEMICOLON;
|
||||
auto def_stmt = std::make_shared<DefinitionStatement_ASTNode>();
|
||||
def_stmt->type = ASTNodeType::DefinitionStatement;
|
||||
def_stmt->start_line = context->getStart()->getLine();
|
||||
def_stmt->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
def_stmt->end_line = context->getStop()->getLine();
|
||||
def_stmt->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::DefinitionStatement);
|
||||
std::string define_type_base;
|
||||
if (auto type_context = dynamic_cast<MXParser::TypeContext *>(context->children[0])) {
|
||||
define_type_base = type_context->getText();
|
||||
} else
|
||||
throw std::runtime_error("unknown subnode occurred in visitDefine_statement");
|
||||
size_t define_dimensions = 0;
|
||||
for (size_t i = 1; i < context->children.size(); i++) {
|
||||
if (dynamic_cast<antlr4::tree::TerminalNode *>(context->children[i]) != nullptr &&
|
||||
dynamic_cast<antlr4::tree::TerminalNode *>(context->children[i])->getSymbol()->getType() == MXParser::ID) {
|
||||
break;
|
||||
}
|
||||
define_dimensions++;
|
||||
}
|
||||
define_dimensions >>= 1;
|
||||
if (define_dimensions == 0) {
|
||||
def_stmt->var_type = define_type_base;
|
||||
std::cerr << std::string(nodetype_stk.size() * 2, ' ') << "recorded member variable type is [none-array]"
|
||||
<< define_type_base << std::endl;
|
||||
} else {
|
||||
def_stmt->var_type = ArrayType{true, define_type_base, static_cast<size_t>(define_dimensions)};
|
||||
std::cerr << std::string(nodetype_stk.size() * 2, ' ') << "recorded member variable type is [array]"
|
||||
<< define_type_base << " with dimensions=" << define_dimensions << std::endl;
|
||||
}
|
||||
for (size_t i = 1 + 2 * define_dimensions; i < context->children.size();) {
|
||||
if (dynamic_cast<antlr4::tree::TerminalNode *>(context->children[i]) != nullptr &&
|
||||
dynamic_cast<antlr4::tree::TerminalNode *>(context->children[i])->getSymbol()->getType() ==
|
||||
MXParser::SEMICOLON) {
|
||||
break;
|
||||
}
|
||||
if (i != 1 + 2 * define_dimensions) i++;
|
||||
if (dynamic_cast<antlr4::tree::TerminalNode *>(context->children[i]) != nullptr &&
|
||||
dynamic_cast<antlr4::tree::TerminalNode *>(context->children[i])->getSymbol()->getType() == MXParser::ID) {
|
||||
def_stmt->vars.push_back(std::make_pair(context->children[i]->getText(), nullptr));
|
||||
} else
|
||||
throw std::runtime_error("unknown subnode occurred in visitDefine_statement");
|
||||
i++;
|
||||
if (dynamic_cast<antlr4::tree::TerminalNode *>(context->children[i]) != nullptr &&
|
||||
dynamic_cast<antlr4::tree::TerminalNode *>(context->children[i])->getSymbol()->getType() == MXParser::ASSIGN) {
|
||||
i++;
|
||||
def_stmt->vars.back().second = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->children[i]));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Statement_ASTNode>(def_stmt);
|
||||
}
|
||||
std::any Visitor::visitGgll_expression(MXParser::Ggll_expressionContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
auto ggll_expr = std::make_shared<GGLLExpr_ASTNode>();
|
||||
ggll_expr->type = ASTNodeType::GGLLExpr;
|
||||
ggll_expr->start_line = context->getStart()->getLine();
|
||||
ggll_expr->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
ggll_expr->end_line = context->getStop()->getLine();
|
||||
ggll_expr->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::GGLLExpr);
|
||||
ggll_expr->op = context->children[1]->getText();
|
||||
ggll_expr->left = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->children[0]));
|
||||
ggll_expr->right = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->children[2]));
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Expr_ASTNode>(ggll_expr);
|
||||
}
|
||||
std::any Visitor::visitBxor_expression(MXParser::Bxor_expressionContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
auto bxor_expr = std::make_shared<BXorExpr_ASTNode>();
|
||||
bxor_expr->type = ASTNodeType::BXorExpr;
|
||||
bxor_expr->start_line = context->getStart()->getLine();
|
||||
bxor_expr->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
bxor_expr->end_line = context->getStop()->getLine();
|
||||
bxor_expr->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::BXorExpr);
|
||||
bxor_expr->op = context->children[1]->getText();
|
||||
bxor_expr->left = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->children[0]));
|
||||
bxor_expr->right = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->children[2]));
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Expr_ASTNode>(bxor_expr);
|
||||
}
|
||||
std::any Visitor::visitSuffix_expression(MXParser::Suffix_expressionContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
auto suffix_expr = std::make_shared<SuffixExpr_ASTNode>();
|
||||
suffix_expr->type = ASTNodeType::SuffixExpr;
|
||||
suffix_expr->start_line = context->getStart()->getLine();
|
||||
suffix_expr->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
suffix_expr->end_line = context->getStop()->getLine();
|
||||
suffix_expr->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::SuffixExpr);
|
||||
suffix_expr->op = context->children[1]->getText();
|
||||
suffix_expr->base = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->expr()));
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Expr_ASTNode>(suffix_expr);
|
||||
}
|
||||
std::any Visitor::visitLand_expression(MXParser::Land_expressionContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
auto land_expr = std::make_shared<LAndExpr_ASTNode>();
|
||||
land_expr->type = ASTNodeType::LAndExpr;
|
||||
land_expr->start_line = context->getStart()->getLine();
|
||||
land_expr->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
land_expr->end_line = context->getStop()->getLine();
|
||||
land_expr->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::LAndExpr);
|
||||
land_expr->op = context->children[1]->getText();
|
||||
land_expr->left = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->children[0]));
|
||||
land_expr->right = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->children[2]));
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Expr_ASTNode>(land_expr);
|
||||
}
|
||||
std::any Visitor::visitPm_expression(MXParser::Pm_expressionContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
auto pm_expr = std::make_shared<PMExpr_ASTNode>();
|
||||
pm_expr->type = ASTNodeType::PMExpr;
|
||||
pm_expr->start_line = context->getStart()->getLine();
|
||||
pm_expr->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
pm_expr->end_line = context->getStop()->getLine();
|
||||
pm_expr->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::PMExpr);
|
||||
pm_expr->op = context->children[1]->getText();
|
||||
pm_expr->left = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->children[0]));
|
||||
pm_expr->right = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->children[2]));
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Expr_ASTNode>(pm_expr);
|
||||
}
|
||||
std::any Visitor::visitIndex_expression(MXParser::Index_expressionContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
auto idx_expr = std::make_shared<IndexExpr_ASTNode>();
|
||||
idx_expr->type = ASTNodeType::IndexExpr;
|
||||
idx_expr->start_line = context->getStart()->getLine();
|
||||
idx_expr->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
idx_expr->end_line = context->getStop()->getLine();
|
||||
idx_expr->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::IndexExpr);
|
||||
auto sub_exprs = context->expr();
|
||||
idx_expr->base = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(sub_exprs[0]));
|
||||
for (size_t i = 1; i < sub_exprs.size(); i++) {
|
||||
idx_expr->indices.push_back(std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(sub_exprs[i])));
|
||||
}
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Expr_ASTNode>(idx_expr);
|
||||
}
|
||||
std::any Visitor::visitOpposite_expression(MXParser::Opposite_expressionContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
auto oppsite_expr = std::make_shared<OppositeExpr_ASTNode>();
|
||||
oppsite_expr->type = ASTNodeType::OppositeExpr;
|
||||
oppsite_expr->start_line = context->getStart()->getLine();
|
||||
oppsite_expr->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
oppsite_expr->end_line = context->getStop()->getLine();
|
||||
oppsite_expr->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::OppositeExpr);
|
||||
oppsite_expr->base = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->expr()));
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Expr_ASTNode>(oppsite_expr);
|
||||
}
|
||||
std::any Visitor::visitNew_array_expression(MXParser::New_array_expressionContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
auto new_array = std::make_shared<NewArrayExpr_ASTNode>();
|
||||
new_array->type = ASTNodeType::NewArrayExpr;
|
||||
new_array->start_line = context->getStart()->getLine();
|
||||
new_array->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
new_array->end_line = context->getStop()->getLine();
|
||||
new_array->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::NewArrayExpr);
|
||||
|
||||
size_t total_dimensions = context->LBRACKET().size();
|
||||
std::string base_type = context->type()->getText();
|
||||
new_array->expr_type_info = ArrayType{true, base_type, total_dimensions};
|
||||
size_t total_dim_count = 0;
|
||||
new_array->dim_size.resize(total_dimensions);
|
||||
for (size_t i = 3; i < context->children.size() && total_dim_count < total_dimensions; i++) {
|
||||
if (dynamic_cast<antlr4::tree::TerminalNode *>(context->children[i]) != nullptr &&
|
||||
dynamic_cast<antlr4::tree::TerminalNode *>(context->children[i])->getSymbol()->getType() ==
|
||||
MXParser::RBRACKET) {
|
||||
} else if (dynamic_cast<MXParser::ExprContext *>(context->children[i]) != nullptr) {
|
||||
new_array->dim_size[total_dim_count] = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->children[i]));
|
||||
}
|
||||
total_dim_count++;
|
||||
}
|
||||
if (context->constant() != nullptr) {
|
||||
new_array->has_initial_value = true;
|
||||
new_array->initial_value = std::dynamic_pointer_cast<ConstantExpr_ASTNode>(
|
||||
std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->constant())));
|
||||
}
|
||||
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Expr_ASTNode>(new_array);
|
||||
}
|
||||
std::any Visitor::visitBasic_expression(MXParser::Basic_expressionContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
return visit(context->basic_expr());
|
||||
}
|
||||
std::any Visitor::visitAccess_expression(MXParser::Access_expressionContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
auto access_expr = std::make_shared<AccessExpr_ASTNode>();
|
||||
access_expr->start_line = context->getStart()->getLine();
|
||||
access_expr->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
access_expr->end_line = context->getStop()->getLine();
|
||||
access_expr->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
if (context->LPAREN() == nullptr) {
|
||||
access_expr->type = ASTNodeType::MemberVariableAccessExpr;
|
||||
access_expr->is_function = false;
|
||||
} else {
|
||||
access_expr->type = ASTNodeType::MemberFunctionAccessExpr;
|
||||
access_expr->is_function = true;
|
||||
}
|
||||
nodetype_stk.push_back(access_expr->type);
|
||||
auto sub_exprs = context->expr();
|
||||
access_expr->base = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(sub_exprs[0]));
|
||||
access_expr->member = context->ID()->getText();
|
||||
for (size_t i = 1; i < sub_exprs.size(); i++) {
|
||||
access_expr->arguments.push_back(std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(sub_exprs[i])));
|
||||
}
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Expr_ASTNode>(access_expr);
|
||||
}
|
||||
std::any Visitor::visitBand_expression(MXParser::Band_expressionContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
auto band_expr = std::make_shared<BAndExpr_ASTNode>();
|
||||
band_expr->type = ASTNodeType::BAndExpr;
|
||||
band_expr->start_line = context->getStart()->getLine();
|
||||
band_expr->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
band_expr->end_line = context->getStop()->getLine();
|
||||
band_expr->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::BAndExpr);
|
||||
band_expr->op = context->children[1]->getText();
|
||||
band_expr->left = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->children[0]));
|
||||
band_expr->right = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->children[2]));
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Expr_ASTNode>(band_expr);
|
||||
}
|
||||
std::any Visitor::visitNew_construct_expression(MXParser::New_construct_expressionContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
auto new_construct_expr = std::make_shared<NewConstructExpr_ASTNode>();
|
||||
new_construct_expr->type = ASTNodeType::NewConstructExpr;
|
||||
new_construct_expr->start_line = context->getStart()->getLine();
|
||||
new_construct_expr->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
new_construct_expr->end_line = context->getStop()->getLine();
|
||||
new_construct_expr->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::NewConstructExpr);
|
||||
new_construct_expr->expr_type_info = context->type()->getText();
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Expr_ASTNode>(new_construct_expr);
|
||||
}
|
||||
std::any Visitor::visitTernary_expression(MXParser::Ternary_expressionContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
auto ternary_expr = std::make_shared<TernaryExpr_ASTNode>();
|
||||
ternary_expr->type = ASTNodeType::TernaryExpr;
|
||||
ternary_expr->start_line = context->getStart()->getLine();
|
||||
ternary_expr->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
ternary_expr->end_line = context->getStop()->getLine();
|
||||
ternary_expr->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::TernaryExpr);
|
||||
auto expr_subnodes = context->expr();
|
||||
ternary_expr->condition = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(expr_subnodes[0]));
|
||||
ternary_expr->src1 = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(expr_subnodes[1]));
|
||||
ternary_expr->src2 = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(expr_subnodes[2]));
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Expr_ASTNode>(ternary_expr);
|
||||
}
|
||||
std::any Visitor::visitBnot_expression(MXParser::Bnot_expressionContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
auto bnot_expr = std::make_shared<BNotExpr_ASTNode>();
|
||||
bnot_expr->type = ASTNodeType::BNotExpr;
|
||||
bnot_expr->start_line = context->getStart()->getLine();
|
||||
bnot_expr->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
bnot_expr->end_line = context->getStop()->getLine();
|
||||
bnot_expr->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::BNotExpr);
|
||||
bnot_expr->base = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->expr()));
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Expr_ASTNode>(bnot_expr);
|
||||
}
|
||||
std::any Visitor::visitLnot_expression(MXParser::Lnot_expressionContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
auto lnot_expr = std::make_shared<LNotExpr_ASTNode>();
|
||||
lnot_expr->type = ASTNodeType::LNotExpr;
|
||||
lnot_expr->start_line = context->getStart()->getLine();
|
||||
lnot_expr->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
lnot_expr->end_line = context->getStop()->getLine();
|
||||
lnot_expr->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::LNotExpr);
|
||||
lnot_expr->base = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->expr()));
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Expr_ASTNode>(lnot_expr);
|
||||
}
|
||||
std::any Visitor::visitPrefix_expression(MXParser::Prefix_expressionContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
auto prefix_expr = std::make_shared<PrefixExpr_ASTNode>();
|
||||
prefix_expr->type = ASTNodeType::PrefixExpr;
|
||||
prefix_expr->start_line = context->getStart()->getLine();
|
||||
prefix_expr->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
prefix_expr->end_line = context->getStop()->getLine();
|
||||
prefix_expr->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::PrefixExpr);
|
||||
prefix_expr->op = context->children[0]->getText();
|
||||
prefix_expr->base = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->expr()));
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Expr_ASTNode>(prefix_expr);
|
||||
}
|
||||
std::any Visitor::visitRl_expression(MXParser::Rl_expressionContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
auto rl_expr = std::make_shared<RLExpr_ASTNode>();
|
||||
rl_expr->type = ASTNodeType::RLExpr;
|
||||
rl_expr->start_line = context->getStart()->getLine();
|
||||
rl_expr->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
rl_expr->end_line = context->getStop()->getLine();
|
||||
rl_expr->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::RLExpr);
|
||||
rl_expr->op = context->children[1]->getText();
|
||||
rl_expr->left = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->children[0]));
|
||||
rl_expr->right = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->children[2]));
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Expr_ASTNode>(rl_expr);
|
||||
}
|
||||
std::any Visitor::visitAssign_expression(MXParser::Assign_expressionContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
auto assign_expr = std::make_shared<AssignExpr_ASTNode>();
|
||||
assign_expr->type = ASTNodeType::AssignExpr;
|
||||
assign_expr->start_line = context->getStart()->getLine();
|
||||
assign_expr->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
assign_expr->end_line = context->getStop()->getLine();
|
||||
assign_expr->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::AssignExpr);
|
||||
assign_expr->dest = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->expr(0)));
|
||||
assign_expr->src = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->expr(1)));
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Expr_ASTNode>(assign_expr);
|
||||
}
|
||||
std::any Visitor::visitMdm_expression(MXParser::Mdm_expressionContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
auto mdm_expr = std::make_shared<MDMExpr_ASTNode>();
|
||||
mdm_expr->type = ASTNodeType::MDMExpr;
|
||||
mdm_expr->start_line = context->getStart()->getLine();
|
||||
mdm_expr->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
mdm_expr->end_line = context->getStop()->getLine();
|
||||
mdm_expr->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::MDMExpr);
|
||||
mdm_expr->op = context->children[1]->getText();
|
||||
mdm_expr->left = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->children[0]));
|
||||
mdm_expr->right = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->children[2]));
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Expr_ASTNode>(mdm_expr);
|
||||
}
|
||||
std::any Visitor::visitNew_expression(MXParser::New_expressionContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
auto new_expr = std::make_shared<NewExpr_ASTNode>();
|
||||
new_expr->type = ASTNodeType::NewExpr;
|
||||
new_expr->start_line = context->getStart()->getLine();
|
||||
new_expr->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
new_expr->end_line = context->getStop()->getLine();
|
||||
new_expr->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::NewExpr);
|
||||
new_expr->expr_type_info = context->type()->getText();
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Expr_ASTNode>(new_expr);
|
||||
}
|
||||
std::any Visitor::visitNe_expression(MXParser::Ne_expressionContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
auto ne_expr = std::make_shared<NEExpr_ASTNode>();
|
||||
ne_expr->type = ASTNodeType::NEExpr;
|
||||
ne_expr->start_line = context->getStart()->getLine();
|
||||
ne_expr->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
ne_expr->end_line = context->getStop()->getLine();
|
||||
ne_expr->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::NEExpr);
|
||||
ne_expr->op = context->children[1]->getText();
|
||||
ne_expr->left = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->children[0]));
|
||||
ne_expr->right = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->children[2]));
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Expr_ASTNode>(ne_expr);
|
||||
}
|
||||
std::any Visitor::visitBor_expression(MXParser::Bor_expressionContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
auto bor_expr = std::make_shared<BOrExpr_ASTNode>();
|
||||
bor_expr->type = ASTNodeType::BOrExpr;
|
||||
bor_expr->start_line = context->getStart()->getLine();
|
||||
bor_expr->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
bor_expr->end_line = context->getStop()->getLine();
|
||||
bor_expr->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::BOrExpr);
|
||||
bor_expr->op = context->children[1]->getText();
|
||||
bor_expr->left = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->children[0]));
|
||||
bor_expr->right = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->children[2]));
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Expr_ASTNode>(bor_expr);
|
||||
}
|
||||
std::any Visitor::visitLor_expression(MXParser::Lor_expressionContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
auto lor_expr = std::make_shared<LOrExpr_ASTNode>();
|
||||
lor_expr->type = ASTNodeType::LOrExpr;
|
||||
lor_expr->start_line = context->getStart()->getLine();
|
||||
lor_expr->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
lor_expr->end_line = context->getStop()->getLine();
|
||||
lor_expr->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::LOrExpr);
|
||||
lor_expr->op = context->children[1]->getText();
|
||||
lor_expr->left = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->children[0]));
|
||||
lor_expr->right = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->children[2]));
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Expr_ASTNode>(lor_expr);
|
||||
}
|
||||
std::any Visitor::visitThis_expr(MXParser::This_exprContext *context) {
|
||||
auto this_expr = std::make_shared<ThisExpr_ASTNode>();
|
||||
this_expr->type = ASTNodeType::ThisExpr;
|
||||
this_expr->start_line = context->getStart()->getLine();
|
||||
this_expr->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
this_expr->end_line = context->getStop()->getLine();
|
||||
this_expr->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::ThisExpr);
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Expr_ASTNode>(this_expr);
|
||||
}
|
||||
std::any Visitor::visitParen_expr(MXParser::Paren_exprContext *context) {
|
||||
auto paren_expr = std::make_shared<ParenExpr_ASTNode>();
|
||||
paren_expr->type = ASTNodeType::ParenExpr;
|
||||
paren_expr->start_line = context->getStart()->getLine();
|
||||
paren_expr->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
paren_expr->end_line = context->getStop()->getLine();
|
||||
paren_expr->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::ParenExpr);
|
||||
paren_expr->expr = std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(context->expr()));
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Expr_ASTNode>(paren_expr);
|
||||
}
|
||||
std::any Visitor::visitId_expr(MXParser::Id_exprContext *context) {
|
||||
auto id_expr = std::make_shared<IDExpr_ASTNode>();
|
||||
id_expr->type = ASTNodeType::IDExpr;
|
||||
id_expr->start_line = context->getStart()->getLine();
|
||||
id_expr->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
id_expr->end_line = context->getStop()->getLine();
|
||||
id_expr->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::IDExpr);
|
||||
id_expr->id = IdentifierType{context->ID()->getText()};
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Expr_ASTNode>(id_expr);
|
||||
}
|
||||
std::any Visitor::visitThis_expr(MXParser::This_exprContext *context) { throw std::runtime_error("Not implemented"); }
|
||||
std::any Visitor::visitParen_expr(MXParser::Paren_exprContext *context) { throw std::runtime_error("Not implemented"); }
|
||||
std::any Visitor::visitId_expr(MXParser::Id_exprContext *context) { throw std::runtime_error("Not implemented"); }
|
||||
std::any Visitor::visitFunction_call_expr(MXParser::Function_call_exprContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
auto func_call_expr = std::make_shared<FunctionCallExpr_ASTNode>();
|
||||
func_call_expr->type = ASTNodeType::FunctionCallExpr;
|
||||
func_call_expr->start_line = context->getStart()->getLine();
|
||||
func_call_expr->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
func_call_expr->end_line = context->getStop()->getLine();
|
||||
func_call_expr->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::FunctionCallExpr);
|
||||
func_call_expr->func_name = IdentifierType{context->ID()->getText()};
|
||||
auto expr_subnodes = context->expr();
|
||||
for (auto expr_subnode : expr_subnodes) {
|
||||
func_call_expr->arguments.push_back(std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(expr_subnode)));
|
||||
}
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Expr_ASTNode>(func_call_expr);
|
||||
}
|
||||
std::any Visitor::visitFormatted_string_expr(MXParser::Formatted_string_exprContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
}
|
||||
std::any Visitor::visitConstant_expr(MXParser::Constant_exprContext *context) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
return visit(context->formatted_string());
|
||||
}
|
||||
std::any Visitor::visitConstant_expr(MXParser::Constant_exprContext *context) { return visit(context->constant()); }
|
||||
std::any Visitor::visitFormatted_string(MXParser::Formatted_stringContext *context) {
|
||||
auto fmt_expr = std::make_shared<FormattedStringExpr_ASTNode>();
|
||||
fmt_expr->type = ASTNodeType::FormattedStringExpr;
|
||||
fmt_expr->start_line = context->getStart()->getLine();
|
||||
fmt_expr->start_char_pos = context->getStart()->getCharPositionInLine();
|
||||
fmt_expr->end_line = context->getStop()->getLine();
|
||||
fmt_expr->end_char_pos = context->getStop()->getCharPositionInLine();
|
||||
nodetype_stk.push_back(ASTNodeType::FormattedStringExpr);
|
||||
|
||||
if (context->FORMAT_STRING_WHOLE() != nullptr) {
|
||||
fmt_expr->literals.push_back(context->FORMAT_STRING_WHOLE()->getText());
|
||||
} else {
|
||||
auto expr_subnodes = context->expr();
|
||||
auto body_subnodes = context->FORMAT_STRING_BODY();
|
||||
fmt_expr->literals.push_back(context->FORMAT_STRING_HEAD()->getText());
|
||||
for (size_t i = 0; i < expr_subnodes.size(); i++) {
|
||||
fmt_expr->literals.push_back(body_subnodes[i]->getText());
|
||||
}
|
||||
fmt_expr->literals.push_back(context->FORMAT_STRING_TAIL()->getText());
|
||||
for (auto expr_subnode : expr_subnodes) {
|
||||
fmt_expr->exprs.push_back(std::any_cast<std::shared_ptr<Expr_ASTNode>>(visit(expr_subnode)));
|
||||
}
|
||||
}
|
||||
|
||||
nodetype_stk.pop_back();
|
||||
return std::static_pointer_cast<Expr_ASTNode>(fmt_expr);
|
||||
}
|
||||
std::any Visitor::visitConstant(MXParser::ConstantContext *context) {
|
||||
// TODO
|
||||
throw std::runtime_error("Not implemented");
|
||||
}
|
||||
std::any Visitor::visitConstant(MXParser::ConstantContext *context) { throw std::runtime_error("Not implemented"); }
|
||||
std::any Visitor::visitType(MXParser::TypeContext *context) { throw std::runtime_error("Not implemented"); }
|
||||
std::any Visitor::visitType(MXParser::TypeContext *context) {
|
||||
throw std::runtime_error("Visitor::visitType should not be called");
|
||||
}
|
||||
|
Reference in New Issue
Block a user