From 65f17aba82aefb4f24cbf9de683cda0e72a9c891 Mon Sep 17 00:00:00 2001 From: MadMaurice Date: Fri, 2 Apr 2021 02:45:49 +0200 Subject: [PATCH] Implement progn style base level --- lib/Minilisp.pm | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/Minilisp.pm b/lib/Minilisp.pm index 57bbe83..7ac8b65 100644 --- a/lib/Minilisp.pm +++ b/lib/Minilisp.pm @@ -121,7 +121,7 @@ my %stdctx = ( sub parser { my @tokens = @_; - my $expr = parser_expr(\@tokens); + my $expr = parser_prog(\@tokens); return sub { my $ctx = shift; @@ -131,6 +131,24 @@ sub parser { } } +sub parser_prog { + my $ts = shift; + + my @steps; + + while (scalar @$ts) + { + push @steps, parser_expr($ts); + } + + return sub { + my $ctx = shift; + my $result; + $result = $_->($ctx) foreach (@steps); + return $result; + } +} + sub parser_expr { my $ts = shift; my $tok = shift @$ts;