Source

example-vm / minijs / grammar.txt

Full commit
IGNORE: "[ \t\n]";

ADD_OPER: "[+-]";
MULT_OPER: "[*/]";
COMP_OPER: "(==)|(>=)|(<=)|>|<|(!=)";

FLOAT: "[0-9]+";
NAME: "[a-zA-Z_][a-zA-Z0-9_]*";

main: statement* [EOF];

statement: expr ";" |
           "if" "(" expr ")" "{" statement* "}" |
           "while" "(" expr ")" "{" statement* "}";

expr: assignment | comparison;

comparison: additive COMP_OPER comparison | additive;
additive: multitive ADD_OPER additive | multitive;
multitive: primary MULT_OPER multitive | primary;
primary: "(" additive ")" | atom;
atom: FLOAT | NAME;

assignment: NAME "=" expr;