diff options
| author | Felix Perktold <Felix.Perktold@student.uibk.ac.at> | 2025-12-21 00:35:10 +0100 |
|---|---|---|
| committer | Felix Perktold <Felix.Perktold@student.uibk.ac.at> | 2025-12-21 00:35:10 +0100 |
| commit | bb631d0e744fa91c663a7a35195125e36c1139b0 (patch) | |
| tree | 6bee67244cbbbbe5251dcb5aae64e12ee2b190c4 | |
| parent | 41d98bd3fde6fdc4d1550108f8528f8dfcc97206 (diff) | |
remove WHITESPACE token, ignore whitespace in lexer
| -rw-r--r-- | lisp.l | 4 | ||||
| -rw-r--r-- | lisp.y | 21 |
2 files changed, 10 insertions, 15 deletions
@@ -7,7 +7,7 @@ int tcnt = 0; %} %% -[[:space:]]+ { printf("%d: WHITESPACE\n", ++tcnt); return WHITESPACE; } +[[:space:]]+ { printf("%d: WHITESPACE\n", tcnt); /*ignore whitespace*/} "(" { printf("%d: LPAREN\n", ++tcnt); return LPAREN; } ")" { printf("%d: RPAREN\n", ++tcnt); return RPAREN; } "\." { printf("%d: DOT\n", ++tcnt); return DOT; } @@ -31,7 +31,7 @@ int tcnt = 0; return STRING; } -[^[:space:]\"()]+ { +[^[:space:]\"().]+ { yylval.strval = strdup(yytext); printf("%d: SYMBOL: %s\n", ++tcnt, yylval.strval); return SYMBOL; @@ -20,7 +20,7 @@ static int is_integer(double x) { } %token <dval> NUMBER %token <strval> STRING SYMBOL -%token <ival> LPAREN RPAREN DOT WHITESPACE +%token <ival> LPAREN RPAREN DOT %token <ival> PLUS MINUS MULT DIV %type <val> 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 { |
