-
Notifications
You must be signed in to change notification settings - Fork 0
/
CplusplusStartOption.eyp
90 lines (68 loc) · 1.29 KB
/
CplusplusStartOption.eyp
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
%{
my $INT = '(int)\b';
my $ID = '([a-zA-Z_][a-zA-Z_0-9]*)';
my $NUM = '(\d+)';
my $ISDEC;
%}
%token NUM = /$NUM/
%token INT = /$INT/
%token ID = /$ID/
%right '='
%left '+'
%conflict decORexp {
if ($ISDEC) { $self->YYSetReduce(')', 'ID:DEC' ); }
else { $self->YYSetReduce(')', 'ID:EXP' ); }
}
%explorer decORexp {
#print "***********************\n";
$ISDEC = $self->YYPreParse('Decl',
#0xF # debug
);
}
%expect-rr 1 # expect 1 reduce-reduce conflict
%tree bypass
%start decl
%%
prog:
%name EMPTY
/* empty */
| %name PROG
prog %decORexp? stmt
;
stmt:
%name EXP
expr ';'
| %name DECL
decl
;
expr:
%name ID:EXP
ID %PREC decORexp
| %name NUM
NUM
| %name TYPECAST
INT '(' expr ')' /* typecast */
| %name PLUS
expr '+' expr
| %name ASSIGN
expr '=' expr
;
decl:
%name DECLARATOR
INT declarator ';'
| %name DECLARATORINIT
INT declarator '=' expr ';'
;
declarator:
%name ID:DEC
ID %PREC decORexp
| '(' declarator ')'
;
%%
####################################################
=head1 SYNOPSIS
Compile it with
eyapp -C CplusplusStartOption
This compiletion must produce warnings
eyapp -S decl -C CplusplusStartOption
=cut