-
Notifications
You must be signed in to change notification settings - Fork 0
/
Precedencia.eyp
82 lines (57 loc) · 1.35 KB
/
Precedencia.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
Be sure Math::Tail in examples/Calculator/lib is reachable
compile it with
eyapp -C Precedencia.eyp
execute the generated modulino with:
./Precedencia.pm -noslurp -c '2@3@4' -info --margin 2
or:
./Precedencia.pm --debug --noslurp -c '2@3@4' -info --margin 2
Try also with inputs:
4@3@5
4@3&5
4&3@5
4&3&5
The result will be the term describing the generated
Abstract Syntax Tree
=head1 See also
http://search.cpan.org/perldoc?Parse::Eyapp::debuggingtut
=cut
our $VERSION = '0.02';
%}
%token NUM = /\d+/
%left '@'
%right '&' dummy
%tree bypass
%%
list
: /* empty */
| list '\n' {}
| $list $e { print $e->str."\n";
$e->png();
$e;
}
;
e : %name NUM
NUM
| %name AMPERSAND
e '&' e
| %name AT
e '@' e %prec dummy
;
%%
# We can explicit a lexer if we want:
__PACKAGE__->lexer(
sub {
my $parser = shift;
for (${$parser->input()}) { # contextualize
m{\G(\s*)}gc;
$parser->tokenline($1 =~ tr{\n}{});
m{\G([0-9]+)}gc and return ('NUM', $1);
m{\G(.)}gc and return ($1, $1);
return('',undef); # EOF
}
}
);
# __PACKAGE__->main('Input (try st. like 2@3&4<CR><CTRL-D>): ') unless caller();
1;