2020import liquidjava .rj_language .ast .UnaryExpression ;
2121import liquidjava .rj_language .ast .Var ;
2222import liquidjava .utils .Utils ;
23- import liquidjava .utils .constants .Formats ;
2423import liquidjava .utils .constants .Keys ;
2524
2625import org .antlr .v4 .runtime .tree .ParseTree ;
3029import rj .grammar .RJParser .DotCallContext ;
3130import rj .grammar .RJParser .EnumContext ;
3231import rj .grammar .RJParser .ExpBoolContext ;
33- import rj .grammar .RJParser .ExpContext ;
34- import rj .grammar .RJParser .ExpGroupContext ;
35- import rj .grammar .RJParser .ExpOperandContext ;
3632import rj .grammar .RJParser .FunctionCallContext ;
3733import rj .grammar .RJParser .GhostCallContext ;
3834import rj .grammar .RJParser .InvocationContext ;
3935import rj .grammar .RJParser .IteContext ;
4036import rj .grammar .RJParser .LitContext ;
41- import rj .grammar .RJParser .LitGroupContext ;
4237import rj .grammar .RJParser .LiteralContext ;
4338import rj .grammar .RJParser .LiteralExpressionContext ;
4439import rj .grammar .RJParser .OpArithContext ;
45- import rj .grammar .RJParser .OpGroupContext ;
4640import rj .grammar .RJParser .OpLiteralContext ;
4741import rj .grammar .RJParser .OpMinusContext ;
4842import rj .grammar .RJParser .OpNotContext ;
49- import rj .grammar .RJParser .OpSubContext ;
50- import rj .grammar .RJParser .OperandContext ;
5143import rj .grammar .RJParser .PredContext ;
52- import rj .grammar .RJParser .PredExpContext ;
5344import rj .grammar .RJParser .PredGroupContext ;
5445import rj .grammar .RJParser .PredLogicContext ;
55- import rj .grammar .RJParser .PredNegateContext ;
5646import rj .grammar .RJParser .ProgContext ;
5747import rj .grammar .RJParser .StartContext ;
5848import rj .grammar .RJParser .StartPredContext ;
@@ -79,10 +69,6 @@ else if (rc instanceof StartContext)
7969 return startCreate (rc );
8070 else if (rc instanceof PredContext )
8171 return predCreate (rc );
82- else if (rc instanceof ExpContext )
83- return expCreate (rc );
84- else if (rc instanceof OperandContext )
85- return operandCreate (rc );
8672 else if (rc instanceof LiteralExpressionContext )
8773 return literalExpressionCreate (rc );
8874 else if (rc instanceof DotCallContext )
@@ -111,53 +97,31 @@ private Expression startCreate(ParseTree rc) throws LJError {
11197 private Expression predCreate (ParseTree rc ) throws LJError {
11298 if (rc instanceof PredGroupContext )
11399 return new GroupExpression (create (((PredGroupContext ) rc ).pred ()));
114- else if (rc instanceof PredNegateContext )
115- return new UnaryExpression ("!" , create (((PredNegateContext ) rc ).pred ()));
100+ else if (rc instanceof OpLiteralContext )
101+ return create (((OpLiteralContext ) rc ).literalExpression ());
102+ else if (rc instanceof OpMinusContext )
103+ return new UnaryExpression ("-" , create (((OpMinusContext ) rc ).pred ()));
104+ else if (rc instanceof OpNotContext )
105+ return new UnaryExpression ("!" , create (((OpNotContext ) rc ).pred ()));
106+ else if (rc instanceof OpArithContext )
107+ return new BinaryExpression (create (((OpArithContext ) rc ).pred (0 )),
108+ ((OpArithContext ) rc ).getChild (1 ).getText (), create (((OpArithContext ) rc ).pred (1 )));
109+ else if (rc instanceof ExpBoolContext )
110+ return new BinaryExpression (create (((ExpBoolContext ) rc ).pred (0 )), ((ExpBoolContext ) rc ).BOOLOP ().getText (),
111+ create (((ExpBoolContext ) rc ).pred (1 )));
116112 else if (rc instanceof PredLogicContext )
117113 return new BinaryExpression (create (((PredLogicContext ) rc ).pred (0 )),
118- ((PredLogicContext ) rc ).LOGOP ( ).getText (), create (((PredLogicContext ) rc ).pred (1 )));
119- else if (rc instanceof IteContext )
114+ ((PredLogicContext ) rc ).getChild ( 1 ).getText (), create (((PredLogicContext ) rc ).pred (1 )));
115+ if (rc instanceof IteContext )
120116 return new Ite (create (((IteContext ) rc ).pred (0 )), create (((IteContext ) rc ).pred (1 )),
121117 create (((IteContext ) rc ).pred (2 )));
122- else
123- return create (((PredExpContext ) rc ).exp ());
124- }
125118
126- private Expression expCreate (ParseTree rc ) throws LJError {
127- if (rc instanceof ExpGroupContext )
128- return new GroupExpression (create (((ExpGroupContext ) rc ).exp ()));
129- else if (rc instanceof ExpBoolContext ) {
130- return new BinaryExpression (create (((ExpBoolContext ) rc ).exp (0 )), ((ExpBoolContext ) rc ).BOOLOP ().getText (),
131- create (((ExpBoolContext ) rc ).exp (1 )));
132- } else {
133- ExpOperandContext eoc = (ExpOperandContext ) rc ;
134- return create (eoc .operand ());
135- }
136- }
137-
138- private Expression operandCreate (ParseTree rc ) throws LJError {
139- if (rc instanceof OpLiteralContext )
140- return create (((OpLiteralContext ) rc ).literalExpression ());
141- else if (rc instanceof OpArithContext )
142- return new BinaryExpression (create (((OpArithContext ) rc ).operand (0 )),
143- ((OpArithContext ) rc ).ARITHOP ().getText (), create (((OpArithContext ) rc ).operand (1 )));
144- else if (rc instanceof OpSubContext )
145- return new BinaryExpression (create (((OpSubContext ) rc ).operand (0 )), "-" ,
146- create (((OpSubContext ) rc ).operand (1 )));
147- else if (rc instanceof OpMinusContext )
148- return new UnaryExpression ("-" , create (((OpMinusContext ) rc ).operand ()));
149- else if (rc instanceof OpNotContext )
150- return new UnaryExpression ("!" , create (((OpNotContext ) rc ).operand ()));
151- else if (rc instanceof OpGroupContext )
152- return new GroupExpression (create (((OpGroupContext ) rc ).operand ()));
153119 assert false ;
154120 return null ;
155121 }
156122
157123 private Expression literalExpressionCreate (ParseTree rc ) throws LJError {
158- if (rc instanceof LitGroupContext )
159- return new GroupExpression (create (((LitGroupContext ) rc ).literalExpression ()));
160- else if (rc instanceof LitContext )
124+ if (rc instanceof LitContext )
161125 return create (((LitContext ) rc ).literal ());
162126 else if (rc instanceof VarContext )
163127 return new Var (((VarContext ) rc ).ID ().getText ());
0 commit comments