@mike-lischke/antlr-tgen
Version:
A generator for antlr-ng runtime test cases
73 lines (67 loc) • 1.27 kB
Plain Text
[type]
Parser
[grammar]
grammar T;
s @after {<ToStringTree("$ctx"):writeln()>} : e EOF ; // must indicate EOF can follow
expressionList
: e (',' e)*
;
e : '(' e ')'
| 'this'
| 'super'
| INT
| ID
| typespec '.' 'class'
| e '.' ID
| e '.' 'this'
| e '.' 'super' '(' expressionList? ')'
| e '.' 'new' ID '(' expressionList? ')'
| 'new' typespec ( '(' expressionList? ')' | ('[' e ']')+)
| e '[' e ']'
| '(' typespec ')' e
| e ('++' | '--')
| e '(' expressionList? ')'
| ('+'|'-'|'++'|'--') e
| ('~'|'!') e
| e ('*'|'/'|'%') e
| e ('+'|'-') e
| e ('\<\<' | '>>>' | '>>') e
| e ('\<=' | '>=' | '>' | '\<') e
| e 'instanceof' e
| e ('==' | '!=') e
| e '&' e
|\<assoc=right> e '^' e
| e '|' e
| e '&&' e
| e '||' e
| e '?' e ':' e
|\<assoc=right>
e ('='
|'+='
|'-='
|'*='
|'/='
|'&='
|'|='
|'^='
|'>>='
|'>>>='
|'\<\<='
|'%=') e
;
typespec
: ID
| ID '[' ']'
| 'int'
| 'int' '[' ']'
;
ID : ('a'..'z'|'A'..'Z'|'_'|'$')+;
INT : '0'..'9'+ ;
WS : (' '|'\n') -> skip ;
[start]
s
[input]
(T)x
[output]
"""(s (e ( (typespec T) ) (e x)) <EOF>)
"""