Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!seismo!rutgers!clyde!ima!johnl
From: johnl@ima.UUCP (Compilers mailing list)
Newsgroups: mod.compilers
Subject: advice needed re: parsing C decl syntax
Message-ID: <282@ima.UUCP>
Date: Sat, 6-Dec-86 11:45:19 EST
Article-I.D.: ima.282
Posted: Sat Dec  6 11:45:19 1986
Date-Received: Mon, 8-Dec-86 22:20:56 EST
Reply-To: Paul Tarvydas 
Lines: 47
Approved: 

I've always been under the impression that YACC and friends produce
code/tables which are somewhat worse than could be done with a hand-built
parser (ie. usually recursive-descent).

Recently, I've tried to parse the C declaration syntax using recursive-descent
and have found that it's a fairly difficult task.  I find a need to delay
parsing decisions until much later in the parse.  For example, you don't know
whether you're parsing a function definition until you've seen a left
brace - up to that point, it could be anything from a declaration of a
variable (up until the left paren) to an external function definition.

I'm still reluctant to use a straight LALR table parser for reasons of
(ahem) efficiency.  Things like expressions & statements are wonderful
candidates for recursive-descent.  Lists of thingies also fall out into
simple code:

	thingie-list ::= thingie | thingie ',' thingie-list

turns into:

	thingie ();
	while (inputChoice (COMMA)) {
		thingie ();
	}

without the need for interpreting table entries.

Has anybody successfully married LR parsing with recursive-descent
techniques?  Are there any other clean tricks/techniques I could use?

thanx,
Paul Tarvydas
Tarvydas-Sanford Controls Inc.
...{utcs|utzoo|...}!utcsri!tarvydas
[Well, actually, I've never seen a compiler where the parser was the
particularly slow part.  More typically you get slowness either in character
processing in the lexer or else in slow table searches in the code gen.
If you insist, I see no reason why you couldn't define EXPR as a token in
the yacc parser and, in contexts where an expression is legal, sneak off to
an operator precedence or recursive descent parser.  But I really don't see
the point.  Yacc certainly has its problems, but excessively slow parsing has
never seemed to be one of them.  -John]
-- 
Send compilers mail to ima!compilers or, in a pinch to Levine@YALE.EDU
Plausible paths are { ihnp4 | decvax | cbosgd | harvard | yale | bbncca}!ima
Please send responses to the originator of the message -- I cannot forward
mail accidentally sent back to compilers.  Meta-mail to ima!compilers-request