aboutsummaryrefslogblamecommitdiffstats
path: root/calc-example/calc.syntax
blob: 286019b1f4b0dd94a2179ddd14e168c1cc97ca44 (plain) (tree)
1
2
3
4
5



                                
                   





















                                                                             
_WHITESPACE = " " | "\t" | " ";
_ = {_WHITESPACE};


DIGIT = <"0", "9">;

ADD = _, ("+"),             _;
SUB = _, ("-" | "−"),       _;
MUL = _, ("*" | "⋅" | "×"), _;
DIV = _, ("/" | "∕" | "÷"), _;


sign = ADD | SUB;

unsigned = DIGIT, {DIGIT | _WHITESPACE | "_" | "'"};

_number = unsigned | "(", _expr, (")" | -);

number = _number, {_, _number}; (* optionally with implicit multiplication *)

value = [sign], number;

_expr = hyper1;


hyper1 = _, hyper2, {(ADD | SUB), (hyper2 | -)}, _;
hyper2 = _, value, {(MUL | DIV), (value | -)}, _;