From a7a070371bcc10d0dbf94e503650856ac37ed81d Mon Sep 17 00:00:00 2001 From: Felix Perktold Date: Mon, 22 Dec 2025 00:14:15 +0100 Subject: add reading from files, add quote shorthand (') --- lisp.y | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'lisp.y') diff --git a/lisp.y b/lisp.y index ffb9bf9..5a39640 100644 --- a/lisp.y +++ b/lisp.y @@ -15,40 +15,36 @@ int yyerror(const char *s); } %token NUMBER %token STRING SYMBOL -%token LPAREN RPAREN DOT -%token PLUS MINUS MULT DIV +%token LPAREN RPAREN DOT QUOTE -%type sexpr atom list list_items +%type expr atom list list_items -%start sexprs +%start exprs %% -sexprs: sexpr +exprs: expr { value *v = eval(global_env, $1); printf(";> "); println_value(v); } - | sexprs sexpr + | exprs expr { value *v = eval(global_env, $2); printf(";> "); println_value(v); }; -sexpr: atom - | list - | LPAREN sexpr DOT sexpr RPAREN - { - $$ = cons($2, $4); - }; +expr: atom + | list + | LPAREN expr DOT expr RPAREN { $$ = cons($2, $4); } + | QUOTE expr { $$ = cons(make_symbol("quote"), cons($2, make_nil())); }; -list: LPAREN list_items RPAREN - { $$ = $2; }; +list: LPAREN list_items RPAREN { $$ = $2; }; list_items: /* empty list */ { $$ = make_nil(); } - | sexpr list_items { $$ = cons($1, $2); } - | sexpr DOT sexpr { $$ = cons($1, $3); }; + | expr list_items { $$ = cons($1, $2); } + | expr DOT expr { $$ = cons($1, $3); }; atom: NUMBER { -- cgit v1.2.3