Re: Advice on Writing a Parser Generator

Rob Arthan <rda@lemma-one.com>
15 Aug 2003 23:43:14 -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)
[1 later articles]
| List of all articles for this month |

From: Rob Arthan <rda@lemma-one.com>
Newsgroups: comp.compilers
Date: 15 Aug 2003 23:43:14 -0400
Organization: Lemma 1 Ltd.
References: 03-08-027 03-08-040
Keywords: parse, LALR, bibliography, comment
Posted-Date: 15 Aug 2003 23:43:14 EDT

Thant Tessman wrote:


> Stefanie Scherzinger wrote:
>
>
>> I plan to write a parser generator, very similar to YACC, for Java.
>>
>> I was hoping to find some literature and advice on how to best
>> approach this.
>
> People will usually recommend the Dragon book, but that was always a
> tough read for me.


The Dragon book also makes the theory and practice of LALR(1) parser
generators seem much harder than it is, because it was written before
some valuable later research that produced better and more
understandable algorithms. The simplest and best approach to LALR(1)
parser generation, in my view, is that of Bermudez and Logothetis,
see:


@article{bermudez89,
                author="Manuel E. Bermudez and George Logothetis",
                title="Simple Computation of LALR(1) Lookahead Sets",
                journal="Information Processing Letters",
                volume="31",
                publisher=NH,
                year="1989",
                pages="233--238"}


- they cleverly reuse the SLR(1) algorithm on a variant grammar to carry out
the LALR(1) look-ahead calculations.


> However, I was able to follow "Modern Compiler
> Implementation in ML" well enough to build an SLR parser generator (in
> C++ oddly enough). I haven't read it, but there's a version for Java:
>
> http://www.cs.princeton.edu/~appel/modern/java/
>
> -thant


Discovering the Bermudez-Logothetis paper last year made me realise
that the LALR(1) approach is worth the extra effort. The parser
generator called SLRP that comes as part of the OpenProofPower
development tools is an example implementation (see
http://www.lemma-one.com/ProofPower). It is written in Standard ML and
generates Standard ML code.


The output of SLRP is essentially just the parsing tables, so it would
be easy to adapt to other languages. I don't think that the
performance considerations of the 1970s and 1980s that caused parser
generators like yacc to produce a mixture of code and data rather than
just tables to feed into a a generic parsing function apply these days
(or do they?).


Regards,


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


You can pull out the parse tables if you want, but there's usually no point.
-John]


Post a followup to this message

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