Re: Re: Hand written parsers - Mailing list pgsql-hackers

From ncm@zembu.com (Nathan Myers)
Subject Re: Re: Hand written parsers
Date
Msg-id 20010412005356.A15434@store.zembu.com
Whole thread Raw
In response to Re: Re: Hand written parsers  (Ian Lance Taylor <ian@airs.com>)
Responses  ("Howard Williams" <howieshouse@home.com>)
Re: Re: Hand written parsers  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Wed, Apr 11, 2001 at 10:44:59PM -0700, Ian Lance Taylor wrote:
> Mark Butler <butlerm@middle.net> writes:
> > ...
> > The advantages of using a hand written recursive descent parser lie in
> > 1) ease of implementing grammar changes 
> > 2) ease of debugging
> > 3) ability to handle unusual cases
> > 4) ability to support context sensitive grammars
> > ...
> > Another nice capability is the ability to enable and disable grammar
> > rules at run time ...
>
> On the other hand, recursive descent parsers tend to be more ad hoc,
> they tend to be harder to maintain, and they tend to be less
> efficient.  ...  And I note that despite the
> difficulties, the g++ parser is yacc based.

Yacc and yacc-like programs are most useful when the target grammar (or 
your understanding of it) is not very stable.  With Yacc you can make 
sweeping changes much more easily; big changes can be a lot of work in 
a hand-coded parser.  Once your grammar stabilizes, though, hand coding 
can provide flexibility that is inconceivable in a parser generator, 
albeit at some cost in speed and compact description.  (I doubt parser 
speed is an issue for PG.)

G++ has flirted seriously with switching to a recursive-descent parser,
largely to be able to offer meaningful error messages and to recover
better from errors, as well as to be able to parse some problematic
but conformant (if unlikely) programs.

Note that the choice is not just between Yacc and a hand-coded parser.
Since Yacc, many more powerful parser generators have been released,
one of which might be just right for PG.

Nathan Myers
ncm@zembu.com


pgsql-hackers by date:

Previous
From: Ian Lance Taylor
Date:
Subject: Re: Re: Hand written parsers
Next
From: Zeugswetter Andreas SB
Date:
Subject: AW: AW: AW: Truncation of char, varchar types