java - getType() method not found in antlr4 -
The rule below is a quote from the larger rule, note the optional part at the end of the grammar tail. After the input is parsed, we go on the tree with generating paras to evaluate the expression. The listener code for the first rule is also given below.
Arithmetic: Arithmetic Factor (op = (Multicellular) Arithmetic Factor) *; Arithmetic Factor: INTEGER / * For now, Become a Simple Terminal * /
Listener
import java.util.ArrayList; Import org.antlr.v4.runtime.misc.NotNull; Import org.antlr.v4.runtime.tree.ParseTree; Import org.antlr.v4.runtime.tree.ParseTreeProperty; The public class pedicalkt evelator extended the Gradient Barrister Listener to {Personal PertyProperty & lt; Float & gt; FloatValues = New Parspty Property & lt; Float & gt; (); Private Archieist & Lt; Float & gt; Arithmetic factorial = faucet; Private zero setflat value (Parsity node, float value) {floatValues.put (node, value); } Private Float Flat Value (Pursi Node) {Return Float Values (Node); } Enter the public zeroEarthmaticTerm (@NoteNalPredicGrammarPr.ArthmeticTimcontexTTx) {ArithmeticTermFactor List = New Array List & Lt; Float & gt; (); }
Currently, I am evaluating the arithmetic term like this. I have to find type ops and either divi or factors must be given abundance. But, my compiler can not find getType () method. I saw the code generated by the ATLR 4 but it was not there, I am following the book by the creator of the entry 4 and he uses the getType () method in the same situation, but the same work does not work here Your support will really be appreciated.
Exit Public Zero ArithmeticTerm (@notless pedicagramar parser. ArithicTermContx CTX) {Float Assessed Value = 0.0F; If (ctx.op == empty) {Assessed value = match flight value (ctx.arithmeticFactor (.) Get (0)); } For other {Float value: ArithmeticTermFactor List} {if (ctx.op.getType () == Predicted Grammer Laaxer MLL) {Valued value * = Value; } Other {evaluation / value / = value; }}} Arithmetic ExprTermList.add (rated value); } Extraction of the public outreach arithmetic factor (@notless pedicure grammar parser. Arithic Factor Contax CTX) {float rated value = negative * integer.valouf (CTX.INTGER (.) GetText ()); ArithmeticTermFactorList.add (evaluatedValue); }
}
Instead:
< Ex> arithmetic: Number: arithmetic factor (op = (multiple) differentiated arithmetic) *;
Do something like this:
Expression: MINUS expression #unaryMinusExpression | Expression MULT Expression # MultiXpress | Expression expression #divideExpression | Add expression expression #addExpression | Expression MINUS expression #minusExpression | INTEGER #integerExpression | '(' Expression ')' # parent's expression;
And then in your audience, you only have to override the # expression ...
methods:
@Override public Enter zero multi expression (@ note null pédéric grammar parser.multi expression ctx) {...}
Note that MULT
and divide < / Code> Expressions have a high priority defined by more than
ADD
and MINUS
.
Comments
Post a Comment