summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authorTom Harley2019-09-30 01:56:15 +0100
committerTom Harley2019-09-30 01:56:15 +0100
commitfbe39f58fc0d757f8ffe54c6dc96bbc690862ded (patch)
tree94d861774ded89f82363bcc2877ec2cc3f94c024 /parse.y
downloadsinter-fbe39f58fc0d757f8ffe54c6dc96bbc690862ded.tar.gz
sinter-fbe39f58fc0d757f8ffe54c6dc96bbc690862ded.zip

Initial commit

Diffstat (limited to 'parse.y')
-rw-r--r--parse.y51
1 files changed, 51 insertions, 0 deletions
diff --git a/parse.y b/parse.y
new file mode 100644
index 0000000..1810c51
--- /dev/null
+++ b/parse.y
@@ -0,0 +1,51 @@
+%{
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+
+#include "basic.h"
+
+extern int yylineno;
+int yylex();
+void yyerror(char *s, ...);
+
+%}
+
+%union {
+ float f;
+ int i;
+ char *s;
+ sexpr *u;
+}
+
+%token NIL
+%token <f> FLOAT
+%token <i> INT
+%token <s> ID
+%token BRANCH
+
+%type <u> sexpr
+
+%%
+
+cmds:
+ | cmds sexpr { print_sexpr($2); }
+
+sexpr: '(' sexpr ';' sexpr ')' { $$ = new_node($2, $4); }
+ | '(' sexpr sexpr ')' { $$ = new_node($2, $3); }
+ | INT { $$ = new_int($1); }
+ | FLOAT { $$ = new_float($1); }
+ | ID { $$ = new_id($1); }
+ | NIL { $$ = 0; }
+
+%%
+
+void yyerror(char *s, ...) {
+ va_list ap;
+ va_start(ap, s);
+
+ fprintf(stderr, "%d: error: ", yylineno);
+ vfprintf(stderr, s, ap);
+ fprintf(stderr, "\n");
+}