Created
April 7, 2014 17:52
-
-
Save RubenCordeiro/10025295 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grammar LabeledExpr; | |
prog: stat+ ; | |
stat: expr NEWLINE # printExpr | |
| ID '=' expr NEWLINE # assign | |
| NEWLINE # blank | |
; | |
expr: expr op=('*'|'/') expr # MulDiv | |
| expr op=('+'|'-') 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment