Re: Why context-free?

Russ Cox <rsc@swtch.com>
7 Oct 2005 21:46:48 -0400

          From comp.compilers

Related articles
Why context-free? nmm1@cus.cam.ac.uk (2005-10-06)
Re: Why context-free? cfc@shell01.TheWorld.com (Chris F Clark) (2005-10-07)
Re: Why context-free? torbenm@app-4.diku.dk (2005-10-07)
Re: Why context-free? rsc@swtch.com (Russ Cox) (2005-10-07)
Re: Why context-free? bobduff@shell01.TheWorld.com (Robert A Duff) (2005-10-07)
Re: Why context-free? nmm1@cus.cam.ac.uk (2005-10-08)
Re: Why context-free? vidyut.vidyut@gmail.com (2005-10-08)
Re: Why context-free? gah@ugcs.caltech.edu (glen herrmannsfeldt) (2005-10-09)
Re: Why context-free? mpah@thegreen.co.uk (2005-10-09)
Re: Why context-free? nmm1@cus.cam.ac.uk (2005-10-09)
[23 later articles]
| List of all articles for this month |
From: Russ Cox <rsc@swtch.com>
Newsgroups: comp.compilers
Date: 7 Oct 2005 21:46:48 -0400
Organization: Compilers Central
References: 05-10-053
Keywords: parse, design
Posted-Date: 07 Oct 2005 21:46:47 EDT

> 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.


Russ


[1] http://plan9.bell-labs.com/sys/doc/rc.pdf


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.