in reply to Parse::RecDescent Puzzlement

It is hard to say without seeing your implementation, but it seems as to me that '(' and ')' should be checked in the higher levels.
lv1expr : lv2expr ADD lv1expr | '(' lv2expr ADD lv1expr ')'

It's not as pretty as what you have, but it doesn’t recurse as far for things that are technically level one exprs parens shouldn’t change the rule your matching, they are just there for precedence right? You still need to match the sub expr, which is just a lv1expr or lv2expr. Consider how deep you would have to go in the current grammar to parse ((((A + B)*A+C)*D)+X). This seems unnecessary. Again, I don’t know the whole situation, perhaps i am missing something.
hope this helps, good luck.

Replies are listed 'Best First'.
Re: Re: Parse::RecDescent Puzzlement
by Android 18 (Novice) on May 14, 2002 at 14:48 UTC
    I organized it in order of operator precedence, from loosest (+/-) to tightest (^) to the num itself.. ()'s group expression so they should be considered a number, but inside you just call the parser again to evaluate the inside. (yes there are probably better ways to do this but optimization comes later..) I just want do know why it's looping forever on input as simple as "1+(2+3)".

    It perplexes me.. ^_^

    Once bread becomes toast, it can never be bread again.