From 152d6b74f65da60bedb6fb0d14bf65984b839796 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Sun, 17 Apr 2022 15:12:03 -0400 Subject: it does addition --- expr.y | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 expr.y (limited to 'expr.y') diff --git a/expr.y b/expr.y new file mode 100644 index 0000000..950a772 --- /dev/null +++ b/expr.y @@ -0,0 +1,64 @@ +%{ +#include + +#include "expr.h" + +extern int yylex(void); +extern int yyerror(const char *s); + +static void breakpoint(void) { } +%} + +%token INTEGER +%token STRING +%token '(' ')' +%left MATCH MULTIPLICATION +%left '+' '-' +%left COMPARISON AND OR + +%start expr + +%% + +expr : STRING { + printf("string\n"); + } + + | INTEGER { + printf("integer %d\n", $1.u.i); + } + + | '(' expr ')' { + printf("a parenthesized expression\n"); + } + + | expr MATCH expr { + printf("match two\n"); + } + + | expr MULTIPLICATION expr { + printf("multiplicationish\n"); + } + + | expr '+' expr { + printf("plus\n"); + $$.u.i = $1.u.i + $3.u.i; + printf("%d\n", $$.u.i); + } + + | expr '-' expr { + printf("minus\n"); + } + + | expr COMPARISON expr { + printf("compare\n"); + } + + | expr AND expr { + printf("and\n"); + } + + | expr OR expr { + printf("or\n"); + } + ; -- cgit v1.2.1