blob: 1060e27869ef80c321d02c0d39b16b2b274912fb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
%{
#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 {
}
| INTEGER {
}
| '(' expr ')' {
printf("a parenthesized expression\n");
}
| expr MATCH expr {
printf("match two\n");
}
| expr MULTIPLICATION expr {
printf("multiplicationish\n");
}
| expr '+' expr {
$$.u.i = $1.u.i + $3.u.i;
printf("%d\n", $$.u.i);
}
| expr '-' expr {
$$.u.i = $1.u.i - $3.u.i;
printf("%d\n", $$.u.i);
}
| expr COMPARISON expr {
printf("compare\n");
}
| expr AND expr {
printf("and\n");
}
| expr OR expr {
printf("or\n");
}
;
|