Show quoted text> Using the simple calculator example in the docs on this: 2*6/4^2*4/3
> gave the incorrect answer, 0.5625 instead of 1. Test is attached.
The problem is that it's treating exponentiation as a left-associative operator.
The fix is to replace the rule with:
<rule: Pow>
<[Term]> ** \^
<MATCH= (?{
my $exp = pop @{$MATCH{Term}};
$exp = $_ ** $exp for @{$MATCH{Term}};
$exp;
})>
|
<MATCH=Term>
Show quoted text> (Its also really slow)
Welcome to the limitations of recursive descent. :-(
Hint: try adding a <debug:run> directive at the start of grammar,
to see how much trial and error the grammar requires on nested
constructs.
Damian