summaryrefslogtreecommitdiff
path: root/lisp.y
diff options
context:
space:
mode:
authorFelix Perktold <Felix.Perktold@student.uibk.ac.at>2025-12-22 00:14:15 +0100
committerFelix Perktold <Felix.Perktold@student.uibk.ac.at>2025-12-22 00:14:15 +0100
commita7a070371bcc10d0dbf94e503650856ac37ed81d (patch)
tree7b2e5968b623d15947bc0537a4ff64a385119f68 /lisp.y
parent33b3d80c2dcd12dbf692984e0d736bfa9906a8b5 (diff)
add reading from files, add quote shorthand (')
Diffstat (limited to 'lisp.y')
-rw-r--r--lisp.y28
1 files changed, 12 insertions, 16 deletions
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 <dval> NUMBER
%token <strval> STRING SYMBOL
-%token <ival> LPAREN RPAREN DOT
-%token <ival> PLUS MINUS MULT DIV
+%token <ival> LPAREN RPAREN DOT QUOTE
-%type <val> sexpr atom list list_items
+%type <val> 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
{