aboutsummaryrefslogtreecommitdiffstats
path: root/calc-example/calc.syntax
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2021-04-17 12:09:12 +0200
committerMattias Andrée <maandree@kth.se>2021-04-17 12:09:12 +0200
commita5218fce6b19591c9412a84a5088c260c0676f61 (patch)
tree038f8b8e1064b4f61c831907ac4f20b77711f289 /calc-example/calc.syntax
downloadlibparser-a5218fce6b19591c9412a84a5088c260c0676f61.tar.gz
libparser-a5218fce6b19591c9412a84a5088c260c0676f61.tar.bz2
libparser-a5218fce6b19591c9412a84a5088c260c0676f61.tar.xz
First commit
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--calc-example/calc.syntax27
1 files changed, 27 insertions, 0 deletions
diff --git a/calc-example/calc.syntax b/calc-example/calc.syntax
new file mode 100644
index 0000000..ef7a9f4
--- /dev/null
+++ b/calc-example/calc.syntax
@@ -0,0 +1,27 @@
+_WHITESPACE = " " | "\t" | " ";
+_ = {_WHITESPACE};
+
+
+DIGIT = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "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 | -)}, _;