From fbe39f58fc0d757f8ffe54c6dc96bbc690862ded Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Mon, 30 Sep 2019 01:56:15 +0100 Subject: Initial commit --- parse.y | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 parse.y (limited to 'parse.y') 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 +#include +#include + +#include "basic.h" + +extern int yylineno; +int yylex(); +void yyerror(char *s, ...); + +%} + +%union { + float f; + int i; + char *s; + sexpr *u; +} + +%token NIL +%token FLOAT +%token INT +%token ID +%token BRANCH + +%type 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"); +} -- cgit v1.2.1