Re: Why are LR parsers faster than using if conditions

Carl Cerecke <cdc@maxnet.co.nz>
15 Jun 2004 01:02:32 -0400

          From comp.compilers

Related articles
Why are LR parsers faster than using if conditions shripal.meghani@philips.com (2004-06-06)
Re: Why are LR parsers faster than using if conditions torbenm@diku.dk (2004-06-09)
Re: Why are LR parsers faster than using if conditions alexc@std.com (Alex Colvin) (2004-06-11)
Re: Why are LR parsers faster than using if conditions cdc@maxnet.co.nz (Carl Cerecke) (2004-06-15)
RE: Why are LR parsers faster than using if conditions quinn-j@shaw.ca (Quinn Tyler Jackson) (2004-06-21)
Re: Why are LR parsers faster than using if conditions cdc@maxnet.co.nz (Carl Cerecke) (2004-06-21)
Re: Why are LR parsers faster than using if conditions t.zielonka@zodiac.mimuw.edu.pl (Tomasz Zielonka) (2004-06-25)
Re: Why are LR parsers faster than using if conditions haberg@matematik.su.se (Hans Aberg) (2004-06-26)
Re: Why are LR parsers faster than using if conditions haberg@matematik.su.se (Hans Aberg) (2004-06-28)
Re: Why are LR parsers faster than using if conditions clint@0lsen.net (Clint Olsen) (2004-06-28)
[5 later articles]
| List of all articles for this month |
From: Carl Cerecke <cdc@maxnet.co.nz>
Newsgroups: comp.compilers
Date: 15 Jun 2004 01:02:32 -0400
Organization: Compilers Central
References: 04-06-012 04-06-034
Keywords: parse, performance
Posted-Date: 15 Jun 2004 01:02:32 EDT

Torben Ęgidius Mogensen wrote:


> LR parsers are a bit slower than well-written recursive descent
> parsers,


OK. I'll bite.


A hard-coded LR parser will be substantially faster than a table-driven
LR parser (2.5-6.5 times, according to Todd Proebsting and co. IIRC).


Basically, "hard-coded" means that the LR state machine is expanded out
into code, and shifts are coded as gotos between the code chunks. This
works well for C, but not so good for Java or python, which don't have
gotos (See! There *is* a reason for having gotos in a language!).
Another downside is that, for large grammars, this produces a *very*
large C function that some compilers can choke on.


But, if we are talking about speed, I suspect a hard-coded LR parser
will leave even a well written recursive descent parser in its dust.


Of course, parsing isn't usually a bottleneck anymore, so go with what
you understand/feel comfortable with. For most, I suspect that's
recursive descent.


Cheers,
Carl Cerecke


Post a followup to this message

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