Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^3: Left-associative binary operators in Parse::RecDescent

by jryan (Vicar)
on Dec 14, 2004 at 23:15 UTC ( #414890=note: print w/replies, xml ) Need Help??


in reply to Re^2: Left-associative binary operators in Parse::RecDescent
in thread Left-associative binary operators in Parse::RecDescent

Yeah, that's a good point. You'll need to get rid of the left-recursion. To do that, you'd need to get rid of binary_op and subexpression in your subexpression rule. Next, you'll need to factor out all of the paren stuff into a single rule, and then use that rule within the binary_op rule instead of subexpression. Here's an example:

paren: '(' binary_op ')' { \$item [2] } # parens belong here, and o +nly here! | subexpression subexpression: function_call | var | literal | <error> binary_op : paren (op paren { [ \@item[1..2] ] })(s?) # any +parenned expression will sink down here { [ \$item[1], map { \@\$_ } \@{\$item[2]} ] }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://414890]
help
Chatterbox?
[Discipulus]: marioroy this page linked by haukex is interesting. If I get it i'll try to rewrite the algorithm in another way. The inner for loop seems a pity and a possible canditate fot Memoize.pm or a self made cache
[marioroy]: Discipulus Cool. Also cool is seeing "use integer" run 1.36x faster.

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2017-10-24 07:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (286 votes). Check out past polls.

    Notices?