grammar FeatherweightJavaScript; @header { package edu.sjsu.fwjs.parser; } // Reserved words IF : 'if' ; ELSE : 'else' ; // Literals INT : [1-9][0-9]* | '0' ; // Symbols MUL : '*' ; DIV : '/' ; SEPARATOR : ';' ; // Whitespace and comments NEWLINE : '\r'? '\n' -> skip ; LINE_COMMENT : '//' ~[\n\r]* -> skip ; WS : [ \t]+ -> skip ; // ignore whitespace // ***Parsing rules *** /** The start rule */ prog: stat+ ; stat: expr SEPARATOR # bareExpr | IF '(' expr ')' block ELSE block # ifThenElse | IF '(' expr ')' block # ifThen ; expr: expr op=( '*' | '/' | '%' ) expr # MulDivMod | INT # int | '(' expr ')' # parens ; block: '{' stat* '}' # fullBlock | stat # simpBlock ;