[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lojban] Re: Computer grammar question: non-left recursive RPN?
As per promise, first a piece of code to illustrate how to make the tree from the new grammar.
/** SumExpression = Term
* | SumExpression SumOp Term
*/
->LL(1)
SumExpression = Term {SumOp Term}
Doing this recursively would not be good, which is why we are doing it iteratively
-------------------------------------
private Tree sumExpression() {
Tree t;
t = term();
while(token == PLUS || token == MINUS){
int operator = sumOp();
Tree right = term();
t = new Tree.Binop(start,
operator, t,
right);
}
return t;
}
-------------------------------------
> The ABNF form of this rule is:
>
> rp-expression = rp-operand rp-operand operator
>
> rp-operand = operand / rp-expression
just one thing, can an rp-expression be just an operand? I would have thought so...
Hey, wait! you need a stack to make the tree of rp-notation. You can't do it in one-token lookahead (I presume the point of this was to make it LL1)...
(take all this with a pinch of salt: I love this stuff and will gladly look into it further, but my memory is rather poor in these matters...)
Greg