diff options
author | Jakob Kaivo <jkk@ung.org> | 2022-04-17 15:12:03 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2022-04-17 15:12:03 -0400 |
commit | 152d6b74f65da60bedb6fb0d14bf65984b839796 (patch) | |
tree | 0d400744ed6b36cba31979263975cce6616b73ce /expr.y | |
parent | 028f700584306cd465ddb18231ecc41c17418082 (diff) |
it does addition
Diffstat (limited to 'expr.y')
-rw-r--r-- | expr.y | 64 |
1 files changed, 64 insertions, 0 deletions
@@ -0,0 +1,64 @@ +%{ +#include <stdio.h> + +#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"); + } + ; |