|Why context-free? email@example.com (2005-10-06)|
|Re: Why context-free? cfc@shell01.TheWorld.com (Chris F Clark) (2005-10-07)|
|Re: Why context-free? firstname.lastname@example.org (2005-10-07)|
|Re: Why context-free? email@example.com (Russ Cox) (2005-10-07)|
|Re: Why context-free? bobduff@shell01.TheWorld.com (Robert A Duff) (2005-10-07)|
|Re: Why context-free? firstname.lastname@example.org (2005-10-08)|
|Re: Why context-free? email@example.com (2005-10-08)|
|Re: Why context-free? firstname.lastname@example.org (glen herrmannsfeldt) (2005-10-09)|
|Re: Why context-free? email@example.com (2005-10-09)|
|Re: Why context-free? firstname.lastname@example.org (2005-10-09)|
|[23 later articles]|
|From:||Russ Cox <email@example.com>|
|Date:||7 Oct 2005 21:46:48 -0400|
> So WHY should I use a context-free grammar? Good reasons appreciated.
Parsers generated from explicit grammars, as opposed to hand-written
parsers, have the benefit that you can easily state precisely what language
they accept -- you've got the grammar right there. It takes a lot more
discipline to make sure you can concisely describe what a hand-written
parser accepts, beyond "run it and see". If the grammar formalism you
use happens not to be context-free grammars, I don't think that's
necessarily a big deal. But not being able to state precisely what
language you're parsing is a mistake.
Tom Duff wrote, in a paper introducing a new shell called rc:
It is remarkable that in the four most recent editions
of the UNIX system programmer's manual the Bourne
shell grammar described in the manual page does not
admit the command "who|wc". This is surely an oversight,
but it suggests something darker: nobody really knows
what the Bourne shell's grammar is. Even examination
of the source code is little help. The parser is implemented
by recursive descent, but the routines corresponding to
the syntactic categories all have a flag argument that
subtly changes their operation depending on the context.
Rc's parser is implemented using yacc, so I can say
precisely what the grammar is.
Return to the
Search the comp.compilers archives again.