The following grammar, in Java, does not produce a visitor with "visitExpr" and I have no idea why... I added valueExpression and it DOES produce visitValueExpression, but this doesn't make it easy to get an expr out of all the math expressions.
grammar Txml; program: statement (NEWLINE statement)* NEWLINE? EOF; statement: require # Condition | entry # CreateEntry | assignment # Assign ; require: REQUIRE valueExpression; valueExpression: expr; expr: lhs=expr ('*' | '/') rhs=expr # MulDiv | lhs=expr ('+' | '-') rhs=expr # AddSub | lhs=expr '%' rhs=expr # Mod | lhs=expr '^' rhs=expr # Pow | '(' expr ')' # Parens | NUMBER # NumberLiteral | IDENT '(' args ')' # FunctionCall | IDENT # Identifier | STRING_LITERAL # StringLiteral ; functionArgument: expr; args: (functionArgument (',' functionArgument)*)?; // Reserved words REQUIRE: 'require'; // Whitespace and line break NEWLINE : [\r\n]; WS: [ \t] + -> skip; // Entities NUMBER: ('0' .. '9') + ('.' ('0' .. '9') +)?; IDENT: [a-zA-Z]+[0-9a-zA-Z]*; STRING_LITERAL : '"' (~('"' | '\\' | '\r' | '\n') | '\\' ('"' | '\\'))* '"';
Also, I don't quite see how to visit a "generic" node in the base visitor - how do I get a RuleNode out of a specific context?
https://stackoverflow.com/questions/66792486/antlr-not-producing-a-visit-method-for-some-reason March 25, 2021 at 11:07AM
没有评论:
发表评论