eva
eva copied to clipboard
[Suggestion] Add let ... in ... expr syntax
Add a basic let syntax for simple mathematical functions. Proposed EBNF:
expr ::= NUMBER
| NAME
| NAME '(' args? ')'
| 'let' NAME+ '=' expr 'in' expr
args = expr (',' expr)*
Where an expression in the form let name = 5 in expr binds name to 5 in expr, and an expression in the form let name a b = a + b in expr binds name to the function f(a, b) = a + b in expr.
i am planning on rewriting the parsing logic using nom or lalrpop. variable support and assignments are top priorities!
If this helps, a while ago I implemented a variant on the language in the Modern Compiler Implementation with lalrpop. The language is very ML-inspired, expression based, and contains exactly this let ... in ... syntax. Here is the lalrpop file with the let expression (and a lot of other things which you may or may not find useful):
https://github.com/minijackson/INF-4301A/blob/master/src/parser/parser.lalrpop#L206-L222
I'm happy to answer questions about this project and my experience with lalrpop ^^