diff options
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | lisp.c | 2 | ||||
| -rw-r--r-- | lisp.h | 2 | ||||
| -rw-r--r-- | lisp.l | 5 | ||||
| -rw-r--r-- | lisp.y | 9 | ||||
| -rw-r--r-- | main.c | 2 |
6 files changed, 12 insertions, 10 deletions
@@ -1,6 +1,6 @@ LEX = flex YACC = bison -CC = gcc -g -Wall -Werror +CC = gcc -g CFLAGS = -DYYDEBUG=1 LIBS = -lreadline -lfl -lm OBJS = lisp.o lisp.tab.o lex.yy.o @@ -356,7 +356,7 @@ int value_eq(value *a, value *b) { return 1; } -value *builtin_eq(env *e, value *args) { +value *builtin_equal(env *e, value *args) { value *v_prev = eval(e, car(args)); args = cdr(args); @@ -76,7 +76,7 @@ value *builtin_car(env *e, value *args); value *builtin_cdr(env *e, value *args); value *builtin_reverse(env *e, value *args); value *builtin_isnull(env *e, value *args); -value *builtin_eq(env *e, value *args); +value *builtin_equal(env *e, value *args); value *builtin_add(env *e, value *args); value *builtin_sub(env *e, value *args); value *builtin_mul(env *e, value *args); @@ -7,8 +7,9 @@ int tcnt = 0; %} %% -[[:space:]]+ { /* ignore whitespace */ } -";"[^\n]* { /* ignore comment */ } +[[:space:]&&[^\n]]+ { /* ignore whitespace */ } +";"[^\n]* { /* ignore comment */ } +\n { return NLINE; } "(" { return LPAREN; } ")" { return RPAREN; } "\." { return DOT; } @@ -8,21 +8,21 @@ int yyerror(const char *s); %} %union { - int ival; double dval; const char *strval; value *val; } %token <dval> NUMBER %token <strval> STRING SYMBOL -%token <ival> LPAREN RPAREN DOT QUOTE +%token LPAREN RPAREN DOT QUOTE NLINE %type <val> expr atom list list_items %start exprs %% -exprs: expr +exprs: /* nothing */ + | expr { value *v = eval(global_env, $1); printf(";> "); @@ -38,7 +38,8 @@ exprs: expr expr: atom | list | LPAREN expr DOT expr RPAREN { $$ = cons($2, $4); } - | QUOTE expr { $$ = cons(make_symbol("quote"), cons($2, make_nil())); }; + | QUOTE expr { $$ = cons(make_symbol("quote"), cons($2, make_nil())); } + | NLINE { $$ = make_nil(); }; list: LPAREN list_items RPAREN { $$ = $2; }; @@ -80,7 +80,7 @@ int main(int argc, char **argv) { env_define(global_env, "cdr", make_builtin(builtin_cdr)); env_define(global_env, "reverse", make_builtin(builtin_reverse)); env_define(global_env, "null?", make_builtin(builtin_isnull)); - env_define(global_env, "eq?", make_builtin(builtin_eq)); + env_define(global_env, "equal?", make_builtin(builtin_equal)); env_define(global_env, "+", make_builtin(builtin_add)); env_define(global_env, "-", make_builtin(builtin_sub)); env_define(global_env, "*", make_builtin(builtin_mul)); |
