Re: Parsing ambiguities
- From: "Arthur J. O'Dwyer" <ajonospam@xxxxxxxxxxxxxx>
- Date: Fri, 2 Jun 2006 20:13:39 -0400 (EDT)
On Thu, 1 Jun 2006, Robbert Haarman wrote:
On Thu, Jun 01, 2006 at 12:45:32AM -0400, Arthur J. O'Dwyer wrote:
Is there any (free and/or published) parser generator that can deal
with ambiguous grammars like this one by generating multiple parse trees?
There's a paper on parser combinators in Haskell that describes a very
elegant way to generate parsers that can deal with ambiguity. Indeed, it
generates (lazily, because it's Haskell) all possible parsings of the
input, discarding any that fail at higher levels. It would be
conceptually simple to build your interpreter on top of that.
Googling "Haskell parser combinator" turns up only Parsec, a parser
combinator library for Haskell that I hope wasn't what you were referring
to.
(Parsec has a <|> symbol that means the same as | in Yacc, but with
the added constraint that it won't ever do backtracking if it fails to
get an exact match. You need to add the keyword "try" in order to get
normal behavior. The documentation spends a long time explaining how
to match the C keyword "return" without barfing on "read" or "returns".
IMNSHO, this is extremely silly.)
This blog entry
http://chneukirchen.org/blog/archive/2005/10/the-rightyear-parsing-library.html
claims flatly that "you need to ensure you don't have left-recursion in
your grammar, because that borks parser combinators in general." Is
that true?
A little more searching got things like
D. S. Swierstra & P. Azero Alcocer,
"Fast, Error Correcting Parser Combinators: A Short Tutorial"
http://www.cs.uu.nl/groups/ST/Software/UU_Parsing/Sofsem99.pdf
which looks more relevant, if less prepackaged. Is this the sort of
thing you're talking about?
I've made an implementation of the same parser combinators in Scheme. I
can send it to you if you're interested.
(1) I'm currently working in C. (2) If I wanted to switch languages,
apparently Ruby and Haskell, among others, include Parsec-like things
in their standard distros. (3) If yours is "the same" as Parsec (no way
to do backtracking automatically), I don't see how I could use it
effectively, as explained above.
However, objection (3) cancels out objection (2): if Haskell and Ruby
only contain Parsec-like parsers, then switching to one of them wouldn't
help me any more than switching to Scheme!
So you could upload the code somewhere, or e-mail it to me, and I
might take a look. (Examples of usage is a must! :) More info on these
parser combinators and how they're applicable to ambiguity would be
really nice, though.
My current code is here:
http://www.contrib.andrew.cmu.edu/~ajo/disseminate/shrdlu/
It's definitely nothing special to look at, but hopefully it'll
give you some idea of the particular things I'm having trouble with.
(For example, prepositional phrases just plain aren't in the grammar
right now, because I don't know how to handle the "ON THE BLOCK IN THE
BOX" ambiguity.)
-Arthur
.
- References:
- Parsing ambiguities
- From: Arthur J. O'Dwyer
- Re: Parsing ambiguities
- From: Robbert Haarman
- Parsing ambiguities
- Prev by Date: Re: Parsing ambiguities
- Next by Date: Re: Parsing ambiguities
- Previous by thread: Re: Parsing ambiguities
- Next by thread: Re: Parsing ambiguities
- Index(es):
Relevant Pages
|