Walter - Discrepancy between EqualExpression spec and implementation

Jarrett Billingsley kb3ctd2 at yahoo.com
Mon May 29 18:18:15 PDT 2006


"James Dunne" <james.jdunne at gmail.com> wrote in message 
news:e5g01q$1l9r$1 at digitaldaemon.com...

> The left-recursive descent rule 'OrOrExpression || AndAndExpression' means 
> to loop over the left side until a subsequent token is NOT the '||' token. 
> Thus, we can only get an OrOrExpression out of two AndAndExpressions next 
> to each other, separated by the '||' token, or just an AndAndExpression 
> alone.  So, the code does implement the spec correctly.  All the other 
> expression rules follow this pattern.

Ahhhahaha... I see.  That's kind of what my mind was working towards when I 
was thinking about it.

> Here, we see that e2 is always evaluated as an AssignExpression, thus this 
> rule is right-recursive, not left-recursive as the other pattern. Again, 
> note the while loop here.

I thought it might have something to do with left- and right-associativity, 
as it's only the assignment operators which are right-associative (and the 
postfix operators too, but you don't see that with the way the D parser is 
structured).  I used a different form of expression parsing before which 
required that you have the associativity of each operator known beforehand 
(along with the precedence, as using different associativity changed how you 
parsed the LHS and RHS of an operator, just like in the recursive descent 
method).  The other method was a bit more terse and mathematical, but had 
the advantage of smaller code.  But recursive descent is just.. cool, if a 
bit weird. 





More information about the Digitalmars-d mailing list