2 # Copyright (C) 2006 Jelmer Vernooij <jelmer@samba.org>
3 # Published under the GNU GPL
17 %left NEG DEREF ADDROF INV
30 '~' exp %prec INV { "~$_[2]" }
32 exp '+' exp { "$_[1] + $_[3]" }
34 exp '-' exp { "$_[1] - $_[3]" }
36 exp '*' exp { "$_[1] * $_[3]" }
38 exp '%' exp { "$_[1] % $_[3]" }
40 exp '<' exp { "$_[1] < $_[3]" }
42 exp '>' exp { "$_[1] > $_[3]" }
44 exp '|' exp { "$_[1] | $_[3]" }
46 exp '==' exp { "$_[1] == $_[3]" }
48 exp '<=' exp { "$_[1] <= $_[3]" }
50 exp '=>' exp { "$_[1] => $_[3]" }
52 exp '<<' exp { "$_[1] << $_[3]" }
54 exp '>>' exp { "$_[1] >> $_[3]" }
56 exp '!=' exp { "$_[1] != $_[3]" }
58 exp '||' exp { "$_[1] || $_[3]" }
60 exp '&&' exp { "$_[1] && $_[3]" }
62 exp '&' exp { "$_[1] & $_[3]" }
64 exp '?' exp ':' exp { "$_[1]?$_[3]:$_[5]" }
68 '!' exp { "not $_[1]" }
70 exp '/' exp { "$_[1] / $_[3]" }
72 '-' exp %prec NEG { "-$_[2]" }
74 '&' exp %prec ADDROF { "&$_[2]" }
76 exp '^' exp { "$_[1]^$_[3]" }
78 '(' exp ')' { "($_[2])" }
82 VAR { $_[0]->_Lookup($_[1]) }
84 '*' possible_pointer %prec DEREF { $_[0]->_Dereference($_[2]); "*$_[2]" }
88 possible_pointer { $_[0]->_Use($_[1]) }
90 var '.' VAR { $_[0]->_Use("$_[1].$_[3]") }
92 '(' var ')' { "($_[2])" }
94 var '->' VAR { $_[0]->_Use("*$_[1]"); $_[1]."->".$_[3] }
99 VAR '(' opt_args ')' { "$_[1]($_[3])" }
109 exp_or_possible_pointer:
116 exp_or_possible_pointer
118 exp_or_possible_pointer ',' args { "$_[1], $_[3]" }
123 package Parse::Pidl::Expr;
128 $parser->YYData->{INPUT}=~s/^[ \t]//;
130 for ($parser->YYData->{INPUT}) {
131 if (s/^(0x[0-9A-Fa-f]+)//) {
132 $parser->YYData->{LAST_TOKEN} = $1;
135 if (s/^([0-9]+(?:\.[0-9]+)?)//) {
136 $parser->YYData->{LAST_TOKEN} = $1;
139 if (s/^([A-Za-z_][A-Za-z0-9_]*)//) {
140 $parser->YYData->{LAST_TOKEN} = $1;
143 if (s/^\"(.*?)\"//) {
144 $parser->YYData->{LAST_TOKEN} = $1;
147 if (s/^(==|!=|<=|>=|->|\|\||<<|>>|&&)//s) {
148 $parser->YYData->{LAST_TOKEN} = $1;
152 $parser->YYData->{LAST_TOKEN} = $1;
161 if (defined($self->YYData->{USE})) {
162 return $self->YYData->{USE}->($x);
170 return $self->YYData->{LOOKUP}->($x);
176 if (defined($self->YYData->{DEREFERENCE})) {
177 $self->YYData->{DEREFERENCE}->($x);
184 if (defined($self->YYData->{LAST_TOKEN})) {
185 $self->YYData->{ERROR}->("Parse error in `".$self->YYData->{FULL_INPUT}."' near `". $self->YYData->{LAST_TOKEN} . "'");
187 $self->YYData->{ERROR}->("Parse error in `".$self->YYData->{FULL_INPUT}."'");
192 my($self, $data, $error, $lookup, $deref, $use) = @_;
194 $self->YYData->{FULL_INPUT} = $data;
195 $self->YYData->{INPUT} = $data;
196 $self->YYData->{LOOKUP} = $lookup;
197 $self->YYData->{DEREFERENCE} = $deref;
198 $self->YYData->{ERROR} = $error;
199 $self->YYData->{USE} = $use;
201 return $self->YYParse( yylex => \&_Lexer, yyerror => \&_Error);