diff options
| author | Tom Harley | 2019-09-30 01:56:15 +0100 |
|---|---|---|
| committer | Tom Harley | 2019-09-30 01:56:15 +0100 |
| commit | fbe39f58fc0d757f8ffe54c6dc96bbc690862ded (patch) | |
| tree | 94d861774ded89f82363bcc2877ec2cc3f94c024 /parse.y | |
| download | sinter-fbe39f58fc0d757f8ffe54c6dc96bbc690862ded.tar.gz sinter-fbe39f58fc0d757f8ffe54c6dc96bbc690862ded.zip | |
Initial commit
Diffstat (limited to 'parse.y')
| -rw-r--r-- | parse.y | 51 |
1 files changed, 51 insertions, 0 deletions
@@ -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"); +} |
