eva icon indicating copy to clipboard operation
eva copied to clipboard

[Suggestion] Add let ... in ... expr syntax

Open Flexilis-anatis opened this issue 6 years ago • 2 comments

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.

Flexilis-anatis avatar Jul 02 '19 19:07 Flexilis-anatis

i am planning on rewriting the parsing logic using nom or lalrpop. variable support and assignments are top priorities!

oppiliappan avatar Jul 08 '19 04:07 oppiliappan

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 ^^

minijackson avatar Oct 30 '19 19:10 minijackson