From: ahmedsamyh Date: Sat, 29 Mar 2025 14:26:28 +0000 (+0500) Subject: [grammar.txt] Add test grammar for Lox. X-Git-Url: https://www.git.momoyon.org/?a=commitdiff_plain;h=c813b8317bfb34d8f5f0805c8885f37697af1de8;p=lang.git [grammar.txt] Add test grammar for Lox. --- diff --git a/grammar.txt b/grammar.txt new file mode 100644 index 0000000..056d114 --- /dev/null +++ b/grammar.txt @@ -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)