Re: advice needed re: parsing C decl syntax

SKY <harvard!rutgers!seismo!rochester!ken>
Mon, 08 Dec 86 23:08:04 -0500

          From comp.compilers

Related articles
advice needed re: parsing C decl syntax toronto.edu!tarvydas@csri (Paul Tarvydas) (1986-12-06)
Re: advice needed re: parsing C decl syntax harvard!rutgers!seismo!rochester!ken (SKY) (1986-12-08)
Re: advice needed re: parsing C decl syntax ihnp4!tektronix!tekchips.TEK.COM!stevev (Steve Vegdahl) (1986-12-09)
Re: advice needed re: parsing C decl syntax ihnp4!bobkat!pedz (Pedz Thing) (1986-12-10)
Re: advice needed re: parsing C decl syntax steve@basser.oz (1986-12-10)
Re: advice needed re: parsing C decl syntax ihnp4!utzoo!henry (1986-12-16)
| List of all articles for this month |

Newsgroups: mod.compilers
In-Reply-To: <282@ima.UUCP>
Organization: U of Rochester, CS Dept, Rochester, NY
Uucp: ..!{allegra,decvax,seismo}!rochester!ken ARPA: ken@rochester.arpa
Snail: CS Dept., U. of Roch., NY 14627. Voice: Ken!
Date: Mon, 08 Dec 86 23:08:04 -0500
From: SKY <harvard!rutgers!seismo!rochester!ken>

LR parsing implies bottom up parsing.


The standard trick in LL (recursive descent) parsing is to delay doing
something about a token if it could be one of several things.
Basically you are rewriting your grammar so that it is LL(1) instead of
LL(k), k > 1, by left factoring. For example:


statement -> identifier := expression
-> identifier ( paramlist )


is not LL(1). But when you factor it out thus:


statement -> identifier stmttail
stmttail -> := expression
-> ( paramlist )


Now one token of lookahead suffices.


Ken
[This is true, but in real recursive descent compilers that I have seen, it's
as likely that you parse these things by kludgery as by adding productions.
Most recursive descent compilers are written by hand, so you'd parse the first
syntax by eating the identifier, remembering it, eating the next token, and then
going ahead with the appropriate construction. But I'd rather let yacc do the
work for me. Yacc can parse anything with enough help -- I have written a yacc
parser with a moderate number of kludges that correctly parses Fortran 77, a
language in which a statement can't be tokenized until you know what kind of
statement it is. -John]





Post a followup to this message

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