feat: document grammar of expressions

This commit is contained in:
Araozu 2024-10-19 21:21:49 -05:00
parent a6335d4cbe
commit 71de3bd598
2 changed files with 52 additions and 2 deletions

View File

@ -20,11 +20,20 @@ Module = (Statement | Expression)*
## Statement ## Statement
(At the moment) a statement is either a variable binding or a function declaration A statement is either a variable binding, a function declaration,
a conditional (for now, until those becom expressions),
for loop, while loop, or an assignment.
Assignment includes the operators `= += -= *= /=`, etc. Those operators
cannot be used elsewhere, only as part of an Assignment.
```ebnf ```ebnf
Statement = VariableBinding Statement = VariableBinding
| FunctionDeclaration | FunctionDeclaration
| Conditional
| ForLoop
| WhileLoop
| Assignment
``` ```
## Expression ## Expression
@ -61,3 +70,22 @@ BlockMember = Statement
``` ```
## Assignment
The target of an assignment can only be an identifier for now.
In the future this will include other things like maps, arrays,
pattern matching, destructuring, etc.
```ebnf
Assignment = AssignmentTarget, AssignmentOperator, Expression
AssignmentTarget = Identifier
AssignmentOperator = "="
| "+="
| "-="
| "*/"
| "/="
| "%="
```

View File

@ -5,4 +5,26 @@ title: Expression
# Expression # Expression
Expression The expression parser effectively implements a precedence table.
| Operator | Precedence |
|------------|------------|
| == != | 4 |
| > >= < <= | 3 |
| - + ++ | 2 |
| / * % | 1 |
```ebnf
Expression = Equality
Equality = Comparison, (("==" | "!="), Comparison)*
Comparison = Term, ((">" | ">=" | "<" | "<="), Term)*
Term = Factor, (("-" | "+" | "++"), Factor)*
Factor = Unary, (("/" | "*" | "%"), Unary)*
Unary = ("!" | "-"), Expression
| FunctionCallExpression
```