UNPKG

@mike-lischke/antlr-tgen

Version:

A generator for antlr-ng runtime test cases

34 lines (28 loc) 678 B
[type] Parser [grammar] grammar Expr; prog: stat ; stat: expr NEWLINE # printExpr | ID '=' expr NEWLINE# assign | NEWLINE # blank ; expr: expr ('*'|'/') expr # MulDiv | expr ('+'|'-') expr # AddSub | INT # int | ID # id | '(' expr ')' # parens ; MUL : '*' ; // assigns token name to '*' used above in grammar DIV : '/' ; ADD : '+' ; SUB : '-' ; ID : [a-zA-Z]+ ; // match identifiers INT : [0-9]+ ;// match integers NEWLINE:'\r'? '\n' ; // return newlines to parser (is end-statement signal) WS : [ \t]+ -> skip ; // toss out whitespace [start] prog [input] """a = 5 """