diff options
author | Himbeer <himbeer@disroot.org> | 2024-10-01 13:53:13 +0200 |
---|---|---|
committer | Himbeer <himbeer@disroot.org> | 2024-10-01 18:50:39 +0200 |
commit | ce68792c848caee2f184e7a6392d9f1e958da1a1 (patch) | |
tree | b2957c12cba0e38b28090bb943206e7cd2c9422e | |
parent | b360bd096dc835d57b858f02e8ed51ffbb1f2005 (diff) |
Switch to an expression-based language design
The previous approach required both assignment and call statements to be
matched last which is impossible. An expression-based language design
simplifies the parser and provides useful syntax to programmers (such as
a ternary operator in the form of assigning the result of an if
statement). This commit does not provide an implementation.
-rw-r--r-- | doc/grammar.txt | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/doc/grammar.txt b/doc/grammar.txt index d92f1dc..4df88d7 100644 --- a/doc/grammar.txt +++ b/doc/grammar.txt @@ -16,7 +16,7 @@ constant := [ COMMENT ] block := "{" command* "}" -command := block | statement | control +command := block | statement control := if | for @@ -24,8 +24,6 @@ statement := ( return | break | continue | declaration - | assignment - | call | defer ) ";" if := "if" expression block elseif* else* @@ -42,11 +40,11 @@ continue := "continue" ":" NAME declaration := "let" [ "mut" ] NAME "=" expression ";" assignment := location "=" expression ";" -location := NAME ( index | field )* [ "*" ] +location := path ( index | field )* [ "*" ] index := "[" expression "]" field := "." NAME -call := path "(" ( expression ), ")" +call := location "(" ( expression ), ")" defer := "defer" call @@ -81,7 +79,8 @@ bitsummand := bitfactor ( "^" | bitfactor )* bitfactor := unaryprefix ( "&" unaryprefix )* unaryprefix := [ "-" | "!" | "~" ] unarypostfix unarypostfix := primary [ "*" | "?" | "!" ] -primary := grouping | literal | call | path +primary := control | grouping | literal | named +named := assignment | call | location grouping := "(" expression ")" literal := bool | string | number | arrayelems bool := "true" | "false" |