Re: Advice on Writing a Parser Generator

Joachim Durchholz <joachim.durchholz@web.de>
20 Aug 2003 01:21:56 -0400

          From comp.compilers

Related articles
Advice on Writing a Parser Generator scherzin@fmi.uni-passau.de (Stefanie Scherzinger) (2003-08-10)
Re: Advice on Writing a Parser Generator thant@acm.org (Thant Tessman) (2003-08-10)
Re: Advice on Writing a Parser Generator freitag@alancoxonachip.com (Andi Kleen) (2003-08-10)
Re: Advice on Writing a Parser Generator kers@hplb.hpl.hp.com (Chris Dollin) (2003-08-15)
Re: Advice on Writing a Parser Generator chief@ockhamstyle.com (Mykola Rabchevskiy) (2003-08-15)
Re: Advice on Writing a Parser Generator rda@lemma-one.com (Rob Arthan) (2003-08-15)
Re: Advice on Writing a Parser Generator scherzin@fmi.uni-passau.de (2003-08-15)
Re: Advice on Writing a Parser Generator joachim.durchholz@web.de (Joachim Durchholz) (2003-08-20)
Re: Advice on Writing a Parser Generator cfc@shell01.TheWorld.com (Chris F Clark) (2003-08-23)
Re: Advice on Writing a Parser Generator lex@cc.gatech.edu (Lex Spoon) (2003-08-23)
Re: Advice on Writing a Parser Generator jhayes2@oswego.edu (2003-08-23)
Re: Advice on Writing a Parser Generator usenet0@skora.net (Thomas Skora) (2003-09-04)
Re: Advice on Writing a Parser Generator robert.thorpe@antenova.com (Rob Thorpe) (2003-09-04)
| List of all articles for this month |

From: Joachim Durchholz <joachim.durchholz@web.de>
Newsgroups: comp.compilers
Date: 20 Aug 2003 01:21:56 -0400
Organization: Compilers Central
References: 03-08-027 03-08-040 03-08-048
Keywords: yacc
Posted-Date: 20 Aug 2003 01:21:56 EDT

John wrote:
> Yacc produces parse tables, too. What looks like a mix of code and data
> is the canned parser code + parse tables + a big switch in which it embeds
> the action code to run on reductions. This is a good thing; otherwise
> matching up the rule numbers with the action code is an error-prone
> pain in the neck.


Wouldn't it be better if the tables simply contained the addresses of
action functions? I see a whole lot of advantages in such an approach:


1. We'd get just large tables. The huge switch statements tend to drive
compilers nuts, either during parsing or during optimization.
2. It would improve separation between the yacc-generated code and the
action code. The action code can modify all parts of the parser state,
it must be written to avoid accidentally clobbering parser state, etc.
In other words, it's extremely unmodular - and if anybody exploits the
advantages of non-modularity, his code will almost certainly break with
the next change in yacc. (IIRC yacc had more than its share of
compatibility issues.)
3. Oh, and finally, we'd not have to manually match up rule numbers and
action code :-)


Regards,
Jo
[If you want to make all your yacc rules function calls, you can certainly
do so. I find that a lot of them are trivial and not worth putting out
of line, e.g.:


  expr: '(' expr ')' { $$ = $2; }


-John]



Post a followup to this message

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