aboutsummaryrefslogtreecommitdiffstats
path: root/calc-example/calc.syntax
blob: f7392334d6810b20e6f1d5e3421ae3b2653d446f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
_WHITESPACE = " " | "\t" | " ";
_COMMENT    = "(*", {!"*)", <0, 0xFF>}, ("*)" | -);

_           = {_WHITESPACE | _COMMENT};


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 | -)}, _;