2 # Copyright (C) 2006 Jelmer Vernooij <jelmer@samba.org>
3 # Published under the GNU GPL
17 %left NEG DEREF ADDROF INV
22 | TEXT { "\"$_[1]\"" }
25 | '~' exp %prec INV { "~$_[2]" }
26 | exp '+' exp { "$_[1] + $_[3]" }
27 | exp '-' exp { "$_[1] - $_[3]" }
28 | exp '*' exp { "$_[1] * $_[3]" }
29 | exp '%' exp { "$_[1] % $_[3]" }
30 | exp '<' exp { "$_[1] < $_[3]" }
31 | exp '>' exp { "$_[1] > $_[3]" }
32 | exp '|' exp { "$_[1] | $_[3]" }
33 | exp '==' exp { "$_[1] == $_[3]" }
34 | exp '<=' exp { "$_[1] <= $_[3]" }
35 | exp '=>' exp { "$_[1] => $_[3]" }
36 | exp '<<' exp { "$_[1] << $_[3]" }
37 | exp '>>' exp { "$_[1] >> $_[3]" }
38 | exp '!=' exp { "$_[1] != $_[3]" }
39 | exp '||' exp { "$_[1] || $_[3]" }
40 | exp '&&' exp { "$_[1] && $_[3]" }
41 | exp '&' exp { "$_[1] & $_[3]" }
42 | exp '?' exp ':' exp { "$_[1]?$_[3]:$_[5]" }
43 | '~' exp { "~$_[1]" }
44 | '!' exp { "not $_[1]" }
45 | exp '/' exp { "$_[1] / $_[3]" }
46 | '-' exp %prec NEG { "-$_[2]" }
47 | '&' exp %prec ADDROF { "&$_[2]" }
48 | exp '^' exp { "$_[1]^$_[3]" }
49 | '(' exp ')' { "($_[2])" }
53 VAR { $_[0]->_Lookup($_[1]) }
54 | '*' possible_pointer %prec DEREF { $_[0]->_Dereference($_[2]); "*$_[2]" }
57 var: possible_pointer { $_[0]->_Use($_[1]) }
58 | var '.' VAR { $_[0]->_Use("$_[1].$_[3]") }
59 | '(' var ')' { "($_[2])" }
60 | var '->' VAR { $_[0]->_Use("*$_[1]"); $_[1]."->".$_[3] }
64 func: VAR '(' opt_args ')' { "$_[1]($_[3])" };
65 opt_args: { "" } | args;
66 exp_or_possible_pointer: exp | possible_pointer;
67 args: exp_or_possible_pointer
68 | exp_or_possible_pointer ',' args { "$_[1], $_[3]" }
73 package Parse::Pidl::Expr;
78 $parser->YYData->{INPUT}=~s/^[ \t]//;
80 for ($parser->YYData->{INPUT}) {
81 if (s/^(0x[0-9A-Fa-f]+)//) {
82 $parser->YYData->{LAST_TOKEN} = $1;
85 if (s/^([0-9]+(?:\.[0-9]+)?)//) {
86 $parser->YYData->{LAST_TOKEN} = $1;
89 if (s/^([A-Za-z_][A-Za-z0-9_]*)//) {
90 $parser->YYData->{LAST_TOKEN} = $1;
94 $parser->YYData->{LAST_TOKEN} = $1;
97 if (s/^(==|!=|<=|>=|->|\|\||<<|>>|&&)//s) {
98 $parser->YYData->{LAST_TOKEN} = $1;
102 $parser->YYData->{LAST_TOKEN} = $1;
111 if (defined($self->YYData->{USE})) {
112 return $self->YYData->{USE}->($x);
120 return $self->YYData->{LOOKUP}->($x);
126 if (defined($self->YYData->{DEREFERENCE})) {
127 $self->YYData->{DEREFERENCE}->($x);
134 if (defined($self->YYData->{LAST_TOKEN})) {
135 $self->YYData->{ERROR}->("Parse error in `".$self->YYData->{FULL_INPUT}."' near `". $self->YYData->{LAST_TOKEN} . "'");
137 $self->YYData->{ERROR}->("Parse error in `".$self->YYData->{FULL_INPUT}."'");
142 my($self, $data, $error, $lookup, $deref, $use) = @_;
143 $self->YYData->{FULL_INPUT} = $data;
144 $self->YYData->{INPUT} = $data;
145 $self->YYData->{LOOKUP} = $lookup;
146 $self->YYData->{DEREFERENCE} = $deref;
147 $self->YYData->{ERROR} = $error;
148 $self->YYData->{USE} = $use;
149 return $self->YYParse( yylex => \&_Lexer, yyerror => \&_Error);