From bb631d0e744fa91c663a7a35195125e36c1139b0 Mon Sep 17 00:00:00 2001 From: Felix Perktold Date: Sun, 21 Dec 2025 00:35:10 +0100 Subject: remove WHITESPACE token, ignore whitespace in lexer --- lisp.y | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'lisp.y') diff --git a/lisp.y b/lisp.y index dd6eddf..da1b315 100644 --- a/lisp.y +++ b/lisp.y @@ -20,7 +20,7 @@ static int is_integer(double x) { } %token NUMBER %token STRING SYMBOL -%token LPAREN RPAREN DOT WHITESPACE +%token LPAREN RPAREN DOT %token PLUS MINUS MULT DIV %type sexpr atom list list_items @@ -28,27 +28,22 @@ static int is_integer(double x) { %start sexprs %% -opt_ws: /* matches no whitespace */ - | WHITESPACE; - sexprs: sexpr { print_val($1); printf("\n"); } - | sexprs opt_ws sexpr { print_val($3); printf("\n"); }; + | sexprs sexpr { print_val($2); printf("\n"); }; sexpr: atom | list - | LPAREN opt_ws sexpr opt_ws DOT opt_ws sexpr opt_ws RPAREN + | LPAREN sexpr DOT sexpr RPAREN { - $$ = cons($3, $7); - print_val($$); - printf("\n"); + $$ = cons($2, $4); }; -list: LPAREN opt_ws list_items opt_ws RPAREN - { $$ = $3; }; +list: LPAREN list_items RPAREN + { $$ = $2; }; list_items: /* empty list */ { $$ = make_nil(); } - | sexpr opt_ws list_items { $$ = cons($1, $3); } - | sexpr WHITESPACE DOT WHITESPACE sexpr { $$ = cons($1, $5); }; + | sexpr list_items { $$ = cons($1, $2); } + | sexpr DOT sexpr { $$ = cons($1, $3); }; atom: NUMBER { -- cgit v1.2.3