Install pidl by default if ExtUtils::MakeMaker is available. This should make the...
[samba.git] / source4 / pidl / expr.yp
index 5b248ea5d6bf19cd261084cf01bb7a3816895679..a8074875ff90fad7c04c127e5c9227504b90be14 100644 (file)
@@ -21,9 +21,7 @@
 exp:        NUM
                |       TEXT                            { "\"$_[1]\"" }
                |       func
-               |       exp '.' VAR                     { "$_[1].$_[3]" }
-        |   VAR                 { $_[0]->Lookup($_[1]) }
-        |   '*' exp %prec DEREF { $_[0]->Dereference($_[2]); "*$_[2]" }
+               |   var
         |   '~' exp %prec INV   { "~$_[2]" }
         |   exp '+' exp         { "$_[1] + $_[3]" }
         |   exp '-' exp         { "$_[1] - $_[3]" }
@@ -41,7 +39,6 @@ exp:        NUM
         |   exp '||' exp        { "$_[1] || $_[3]" }
         |   exp '&&' exp        { "$_[1] && $_[3]" }
         |   exp '&' exp         { "$_[1] & $_[3]" }
-               |       exp '->' VAR            { $_[1]."->".$_[3] }
                |       exp '?' exp ':' exp { "$_[1]?$_[3]:$_[5]" }
                |       '~' exp                         { "~$_[1]" }
                |       '!' exp                         { "not $_[1]" }
@@ -52,9 +49,24 @@ exp:        NUM
         |   '(' exp ')'         { "($_[2])" }
 ;
 
+possible_pointer: 
+            VAR                 { $_[0]->_Lookup($_[1]) }
+        |   '*' possible_pointer %prec DEREF { $_[0]->_Dereference($_[2]); "*$_[2]" }
+               ;
+
+var:   possible_pointer        { $_[0]->_Use($_[1]) }
+               |       var '.' VAR                     { $_[0]->_Use("$_[1].$_[3]") }
+               |   '(' var ')'         { "($_[2])" }
+               |       var '->' VAR            { $_[0]->_Use("*$_[1]"); $_[1]."->".$_[3] }
+;
+
+
 func: VAR '(' opt_args ')' { "$_[1]($_[3])" };
 opt_args: { "" } | args;
-args: exp | exp ',' args { "$_[1], $_[3]" };
+exp_or_possible_pointer: exp | possible_pointer;
+args: exp_or_possible_pointer 
+    | exp_or_possible_pointer ',' args { "$_[1], $_[3]" }
+;
 
 %%
 
@@ -93,13 +105,22 @@ sub _Lexer {
     }
 }
 
-sub Lookup($$) 
+sub _Use($$)
+{
+       my ($self, $x) = @_;
+       if (defined($self->YYData->{USE})) {
+               return $self->YYData->{USE}->($x);
+       }
+       return $x;
+}
+
+sub _Lookup($$) 
 {
        my ($self, $x) = @_;
        return $self->YYData->{LOOKUP}->($x);
 }
 
-sub Dereference($$)
+sub _Dereference($$)
 {
        my ($self, $x) = @_;
        if (defined($self->YYData->{DEREFERENCE})) {
@@ -107,10 +128,23 @@ sub Dereference($$)
        }
 }
 
+sub _Error($)
+{
+       my ($self) = @_;
+       if (defined($self->YYData->{LAST_TOKEN})) {
+               $self->YYData->{ERROR}->("Parse error in `".$self->YYData->{FULL_INPUT}."' near `". $self->YYData->{LAST_TOKEN} . "'");
+       } else {
+               $self->YYData->{ERROR}->("Parse error in `".$self->YYData->{FULL_INPUT}."'");
+       }
+}
+
 sub Run {
-    my($self, $data, $error, $lookup, $deref) = @_;
+    my($self, $data, $error, $lookup, $deref, $use) = @_;
+    $self->YYData->{FULL_INPUT} = $data;
     $self->YYData->{INPUT} = $data;
     $self->YYData->{LOOKUP} = $lookup;
     $self->YYData->{DEREFERENCE} = $deref;
-    return $self->YYParse( yylex => \&_Lexer, yyerror => $error );
+    $self->YYData->{ERROR} = $error;
+    $self->YYData->{USE} = $use;
+    return $self->YYParse( yylex => \&_Lexer, yyerror => \&_Error);
 }