summaryrefslogtreecommitdiff
path: root/expr.y
diff options
context:
space:
mode:
Diffstat (limited to 'expr.y')
-rw-r--r--expr.y64
1 files changed, 64 insertions, 0 deletions
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 <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");
+ }
+ ;