summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lisp.l4
-rw-r--r--lisp.y21
2 files changed, 10 insertions, 15 deletions
diff --git a/lisp.l b/lisp.l
index bbeb02d..7a9eece 100644
--- a/lisp.l
+++ b/lisp.l
@@ -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;
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 <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
{