Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Order of Precedence in Parse::RecDescent grammar

by ikegami (Patriarch)
on Jun 01, 2005 at 18:07 UTC ( [id://462581]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
       expr     : bin_op_2 { $item[1] }
    
    ...
    
       bin_op_1 : bin_op_1 /[*\\\/%]/ term  { [ @item[2, 1, 3] ] }
                | term                      { $item[1] }
    
  2. or download this
       bin_op_2  : bin_op_1 bin_op_2_(s?)
                   { treeify($item[1], map { @$_ } @{$item[2]}); }
    ...
    
       bin_op_2_ : /[+-]/     bin_op_1 { [ $item[1], $item[2] ] }
       bin_op_1_ : /[*\\\/%]/ term     { [ $item[1], $item[2] ] }
    
  3. or download this
          sub treeify {
             my $t = shift;
    ...
                while @_;
             return $t;
          }
    
  4. or download this
       # Lowest precedence.
       bin_op_2 : <leftop: bin_op_1 SUM bin_op_1 >
    ...
    
       SUM      : '+' | '-'
       PROD     : '*' | '/' | '\\' | '%'
    
  5. or download this
    use strict;
    use warnings;
    ...
                                [ $_                 ]));
       print("\n");
    }
    
  6. or download this
          sub treeify_r {
             my $t = pop;
    ...
                  { treeify_r(@{$item[1]}); }
    
       ASSIGN   : '='
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://462581]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-26 04:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found