summaryrefslogtreecommitdiff
path: root/lisp.yacc
diff options
context:
space:
mode:
Diffstat (limited to 'lisp.yacc')
-rw-r--r--lisp.yacc64
1 files changed, 64 insertions, 0 deletions
diff --git a/lisp.yacc b/lisp.yacc
new file mode 100644
index 0000000..16461d9
--- /dev/null
+++ b/lisp.yacc
@@ -0,0 +1,64 @@
+%{
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "types.h"
+
+
+int yylex();
+void yyerror(const char *msg);
+
+extern char *yytext;
+
+ast *ass[MAXASS] = {0};
+int asscount = 0;
+
+void append(ast *a) {
+ ass[asscount] = a;
+ asscount++;
+}
+
+%}
+
+%union {
+ char *intlit;
+ char *name;
+ ast *as;
+ values *vs;
+}
+
+%token <intlit> INTLIT
+%token <name> NAME
+
+%type <as> EXPR
+%type <vs> ARGS ARG
+
+%%
+PROG : EXPRS {}
+ ;
+
+EXPRS : EXPR {append($1);}
+ | EXPRS EXPR {append($2);}
+ ;
+
+EXPR : '(' NAME ')' {$$ = newast($2);}
+ | '(' NAME ARGS ')' {
+ ast *a= newast($2);
+ a->vals = $3;
+ $$ = a;
+ }
+ ;
+
+ARGS : ARG
+ | ARGS ARG {$$ = addval($1, $2);}
+ ;
+
+ARG : EXPR {$$ = newastval($1);}
+ | INTLIT {$$ = newintval(atoi($1));}
+ ;
+
+%%
+
+void yyerror(const char *msg) {
+ fprintf(stderr, "%s\n", msg);
+}