Re: LL vs LR, strengths and weaknesses

bob@tera.com (Bob Alverson)
Tue, 19 May 1992 17:44:22 GMT

          From comp.compilers

Related articles
LL vs LR, no jihad initiation, but... parrt@ecn.purdue.edu (1992-05-11)
Re: LL vs LR, strengths and weaknesses eifrig@blaze.cs.jhu.edu (1992-05-11)
Re: LL vs LR, strengths and weaknesses reid@csgrad.cs.vt.edu (1992-05-13)
Re: LL vs LR, strengths and weaknesses mauney@adm.csc.ncsu.edu (1992-05-13)
Re: LL vs LR, strengths and weaknesses ressler@cs.cornell.edu (1992-05-14)
Re: LL vs LR, strengths and weaknesses eifrig@blaze.cs.jhu.edu (1992-05-14)
Re: LL vs LR, strengths and weaknesses henry@zoo.toronto.edu (1992-05-15)
Re: LL vs LR, strengths and weaknesses bob@tera.com (1992-05-19)
Re: LL vs LR, strengths and weaknesses jos@and.nl (1992-05-16)
| List of all articles for this month |

Newsgroups: comp.compilers
From: bob@tera.com (Bob Alverson)
Keywords: LL(1), parse
Organization: Tera Computer
References: 92-05-059 92-05-092
Date: Tue, 19 May 1992 17:44:22 GMT
Return-Path: <news@mammoth.tera.com>

ressler@cs.cornell.edu (Gene Ressler) writes:
[How C's 16 precedence levels induce massive stack growth when you
  hit expressions with lots of parentheses]
>(For starters, I believe this is why at least some RD parsers have
>embedded operator precedence parsers to do arithmetic.)


In fact, I once modified a RD parser to use operator precedence ideas
to reduce recursion in the face of parentheses. It was really bad with
cfront output, where there seem to be more paren's than white space.


It turned out that the OP version was much more concise than the pure
RD version, which had 16 versions of "expr : expr op expr" to manage
the precedence. The key thing to note is that all you get from
precedence is the resolution of a shift-reduce conflict. So, code
a RD parser that uses precedence to resolve the conflict, rather than
simple lookahead:




Expr expr(Token op0) {
        Expr e1 = primary();
        while (shift_prec[nextToken] > reduce_prec[op0]) {
Token op1 = nextToken;
match(op1);
Expr e2 = expr(op1);
e1 = GenOp(op1, e1, e2);
        }
        return e1;
}




As I recall, there were a few hacks needed. For example, ?: takes
three operands. This was a few years ago, so it is getting fuzzy.


Bob
--


Post a followup to this message

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