in reply to Backtracking in Parse::RecDescent
After digging into the Parse::RecDescent docs, I found out that the mechanism to alter Parse::RecDescent's preference for the first match is the <score: ...> directive. The code below illustrate how it solves your case.
Now the result is "Good!" for both 'a a a' and 'a a' as desireduse strict; use warnings; use Parse::RecDescent; my $grammar = q/ startrule: choice "a" choice: "a" "a" <score: -2> | "a" <score: -1> /; my $parser = Parse::RecDescent->new($grammar); while (<DATA>) { chomp($_); print defined($parser->startrule($_)) ? "Good!\n" : "Bad!\n"; } __DATA__ a a a a a
Hope this helps, -gjb-
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Backtracking in Parse::RecDescent (solution)
by ruscoekm (Monk) on Dec 06, 2002 at 22:50 UTC | |
by Anonymous Monk on Dec 07, 2002 at 01:47 UTC | |
by ruscoekm (Monk) on Dec 09, 2002 at 08:15 UTC |