
org.antlr.v4.test.runtime.templates.LeftRecursion.MultipleAlternativesWithCommonLabel.stg Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of runtime-testsuite Show documentation
Show all versions of runtime-testsuite Show documentation
A collection of tests for ANTLR 4 Runtime libraries.
/*
* This is a regression test for antlr/antlr4#433 "Not all context accessor
* methods are generated when an alternative rule label is used for multiple
* alternatives".
* https://github.com/antlr/antlr4/issues/433
*/
TestType() ::= "Parser"
Options ::= [
"Debug": false
]
Grammar ::= [
"T": {}
]
Rule() ::= "s"
grammar(grammarName) ::= <<
grammar ;
s : e {};
e returns [int v]
: e '*' e {$v = .e(0).v * .e(1).v;} # binary
| e '+' e {$v = .e(0).v + .e(1).v;} # binary
| INT {$v = $INT.int;} # anInt
| '(' e ')' {$v = $e.v;} # parens
| left=e INC {$v = $left.v + 1;} # unary
| left=e DEC {$v = $left.v - 1;} # unary
| ID {} # anID
;
ID : 'a'..'z'+ ;
INT : '0'..'9'+ ;
INC : '++' ;
DEC : '--' ;
WS : (' '|'\n') -> skip ;
>>
© 2015 - 2025 Weber Informatics LLC | Privacy Policy