changeset 27:f6cb12bf2d09

gen: Fix grammar for program level.
author Lewin Bormann <lbo@spheniscida.de>
date Mon, 19 Aug 2019 22:16:07 +0200
parents cf95c6716512
children bcc2670db1a6
files gen/y.yy
diffstat 1 files changed, 8 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/gen/y.yy	Mon Aug 19 21:56:36 2019 +0200
+++ b/gen/y.yy	Mon Aug 19 22:16:07 2019 +0200
@@ -30,6 +30,8 @@
 %define lr.type ielr
 
 %union yvalue {
+// More yexprs.
+yvec_t exprs;
 // One yexpr.
 yexpr_t expr;
 // A number literal (todo: floats)
@@ -46,31 +48,33 @@
 %token TOK_LEFTP
 %token TOK_RIGHTP
 
+%type <exprs> prog
 %type <expr> sexpr
 %type <expr> inner_sexpr
 
 %%
 
-prog: sexpr prog { yexpr_debug(&$1); } | %empty;
+prog: prog sexpr { YVEC_PUSH(&$1, &$2); yexpr_debug(&$2); }
+    | %empty { yvec_t v; YVEC_INIT(&v, 0, yexpr_t); $$ = v; };
 
 sexpr: TOK_LEFTP inner_sexpr TOK_RIGHTP { printf("found sexpr\n"); $$ = $2; };
 
 inner_sexpr: inner_sexpr TOK_ATOM {
-                printf("found atom with sexpr %s\n", $2);
+                printf("found atom %s\n", $2);
                 yexpr_t atom;
                 yexpr_set_atom(&atom, strdup($2));
                 yexpr_init_or_extend(&$1, atom);
                 $$ = $1;
            }
            | inner_sexpr TOK_NUMBER_LITERAL {
-                printf("found number %d, sexpr\n", $2);
+                printf("found number %d\n", $2);
                 yexpr_t num;
                 yexpr_set_number(&num, $2);
                 yexpr_init_or_extend(&$1, num);
                 $$ = $1;
            }
            | inner_sexpr TOK_STRING_LITERAL {
-                printf("found string %s, sexpr\n", $2);
+                printf("found string %s\n", $2);
                 yexpr_t strexpr;
                 ystr_t str;
                 ystr_init(&str, $2);