From 378683d25bdae89fa446b2b82f8dda5d6b34ea33 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Thu, 14 Mar 2024 14:37:32 +0100 Subject: feat: initial support of closures Also detection and automatic execution of main function. Make sure that all debug is output to stderr. --- parser/expr.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'parser/expr.go') diff --git a/parser/expr.go b/parser/expr.go index 91c093f..e952f7c 100644 --- a/parser/expr.go +++ b/parser/expr.go @@ -17,6 +17,17 @@ func (p *Parser) ParseExpr(in Tokens) (out Tokens, err error) { // Process tokens from last to first, the goal is to reorder the tokens in // a stack machine processing order, so it can be directly interpreted. // + if len(in) > 1 && in[0].Id == lang.Func { + // Function as value (i.e closure). + if out, err = p.ParseFunc(in); err != nil { + return out, err + } + // Get function label and use it as a symbol ident. + fid := out[1] + fid.Id = lang.Ident + out = append(out, fid) + return out, err + } for i := len(in) - 1; i >= 0; i-- { t := in[i] // temporary assumptions: binary operators, returning 1 value -- cgit v1.2.3