Er, that doesn't seem to match A or A*A or A*A*A...
grammar f;
rule atom   { A }
rule binary { <atom> \* <expr> }
rule expr { <atom> | <binary> } looks better. Now.. how to make this preferentially match the /whole/ string... Ah:
grammar f;
rule atom   { A }
rule binary { <atom> \* <any> }
rule any    { [<atom> | <binary> ]}
rule expr { ^^ <any> $$ } Thanks, Luke! (The original ticket about PGE exploding still stands, but I don't need anything else at the moment.) Luke Palmer via RT writes:
Attempting to come up with a simplistic math grammar that has one possible
operand (A) and one possible operator (*) - so that things like A, A*A, and
A*A*A*A*A are all parsed. This simplistic example (thanks to spinclad on
#perl6) cause PGE to explode.
$ cat ta.p6r
grammar f;
rule atom  { A }
rule binary { <expr> \* <atom> }
rule expr { <binary> }

That probably shouldn't die so horribly, but it should die.  We don't
support left-recursive grammars, and this is one.  A
non-left-recursive grammar that matches the same language is:
    grammar f;
    rule atom { A }
rule binary { <atom> \* <binary> } Luke



Reply via email to