From 1783097ba99c2b55dfdf483535ad221e06999f1f Mon Sep 17 00:00:00 2001 From: Araozu Date: Sat, 2 Nov 2024 21:45:38 -0500 Subject: [PATCH] feat: improve expression grammar --- src/pages/spec/ast/expression.md | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/pages/spec/ast/expression.md b/src/pages/spec/ast/expression.md index 6204c2d..c153753 100644 --- a/src/pages/spec/ast/expression.md +++ b/src/pages/spec/ast/expression.md @@ -9,9 +9,10 @@ The expression parser effectively implements a precedence table. | Operator | Precedence | |------------|------------| -| == != | 4 | -| > >= < <= | 3 | -| - + ++ | 2 | +| == != | 5 | +| > >= < <= | 4 | +| - + ++ | 3 | +| . ?. !. | 2 | | / * % | 1 | @@ -22,9 +23,23 @@ Expression = Equality Equality = Comparison, (("==" | "!="), Comparison)* Comparison = Term, ((">" | ">=" | "<" | "<="), Term)* Term = Factor, (("-" | "+" | "++"), Factor)* -Factor = Unary, (("/" | "*" | "%"), Unary)* +Factor = DotAccess, (("/" | "*" | "%"), DotAccess)* +DotAccess = Unary, (("."), Unary)* Unary = ("!" | "-"), Expression - | FunctionCallExpression + | CallExpression ``` +## CallExpression + +It's so hard to properly name these constructions. +This one groups a function call or an array access. + +```ebnf +CallExpression = primary, "(", (arguments list)?, ")" + | primary, "[", (expression, (comma, expression)*, comma?)? "]" + | primary +``` + + +