-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDebug1.eyp
83 lines (56 loc) · 1.19 KB
/
Debug1.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
%{
=head1 SYNOPSIS
See http://search.cpan.org/perldoc?Parse::Eyapp::debuggingtut
This files is almost like Debug.eyp
It only changes the rules
ds:
D ';' ds
| D
for a left-recursive version.
Be sure C<DebugTail.pm> is reachable
compile it with
eyapp -b '' Debug1.eyp
Execute the generated modulino with:
./Debug1.pm -t
There is an error in the lexical analyzer.
Can you find it?
Try first with input "D;S" and then
with input "D; S"
=head1 See also
Debug1.eyp Debug2.eyp DebugLookForward.eyp DebugDynamicResolution.eyp
=cut
our $VERSION = '0.01';
use base q{DebugTail};
# This is an exercise:
# There is an error somewhere below ...
# Can you find it?
%}
%token D S
%lexer {
s{^(\s)}{} and $self->tokenline($1 =~ tr{\n}{});
return ($1, $1) if s/^(.)//;
}
%tree
%%
p:
%name P
ds ';' ss
| %name SS
ss
;
ds:
%name D2
ds ';' D
| %name D1
D
;
ss:
%name S2
S ';' ss
| %name S1
S
;
%%
my $prompt = 'Try first "D;S" and then "D; D; S" '.
'(press <CR><CTRL-D> to finish): ';
__PACKAGE__->main($prompt) unless caller();