Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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

by samtregar (Abbot)
on Dec 14, 2004 at 20:59 UTC ( #414851=note: print w/replies, xml ) Need Help??


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

Thanks for the help! I've tried just dropping the '(' and ')' but then I get errors from PRD about the grammar being left-associative.

-sam

  • Comment on Re^2: Left-associative binary operators in Parse::RecDescent

Replies are listed 'Best First'.
Re^3: Left-associative binary operators in Parse::RecDescent
by jryan (Vicar) on Dec 14, 2004 at 23:15 UTC

    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]} ] }
Re^3: Left-associative binary operators in Parse::RecDescent
by demerphq (Chancellor) on Dec 15, 2004 at 15:03 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://414851]
help
Chatterbox?
[hippo]: That was around April 1994. Fun times.
[hippo]: They had purchased some shiny new 486 DXs the year before but crippled them by installing Win 3.1. I demo'd Linux with X on them to the department head and got the go-ahead to wipe Windows and install the new hotness.
[marto]: glory days ;)
[hippo]: Too true :)

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (11)
As of 2018-06-22 09:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (124 votes). Check out past polls.

    Notices?