]> www.git.momoyon.org Git - lang.git/commitdiff
[grammar.txt] Add test grammar for Lox.
authorahmedsamyh <ahmedsamyh10@gmail.com>
Sat, 29 Mar 2025 14:26:28 +0000 (19:26 +0500)
committerahmedsamyh <ahmedsamyh10@gmail.com>
Sat, 29 Mar 2025 14:26:28 +0000 (19:26 +0500)
grammar.txt [new file with mode: 0644]

diff --git a/grammar.txt b/grammar.txt
new file mode 100644 (file)
index 0000000..056d114
--- /dev/null
@@ -0,0 +1,35 @@
+expression -> literal | unary | binary | grouping ;
+grouping   -> "(" expression ")" ;
+literal    -> NUMBER | STRING | "true" | "false" | "nil" ;
+unary      -> ( "!" | "-" ) expression ;
+binary     -> expression operator expression ;
+operator   -> "==" | "!=" | "<" | "<=" | ">" | ">=" |
+              "+" | "-" | "*" | "/" ;
+
+
+NUMBER     -> "[0-9]" "."? "[0-9]" ;
+STRING     -> \" "[a-zA-Z]"* \" ;
+
+
+So expression could be:
+1. 
+       unary =>
+       !expression =>
+       !literal =>
+       !NUMBER =>
+       !4
+
+2.
+       grouping =>
+       (expression) =>
+       (binary) =>
+       (expression operator expression) =>
+       (literal operator expression) =>
+       (NUMBER operator expression) => 
+       (5.8 operator expression) =>
+       (5.8 * expression) =>
+       (5.8 * unary) =>
+       (5.8 * -expression) =>
+       (5.8 * -literal) =>
+       (5.8 * -NUMBER) =>
+       (5.8 * -8)