Top down LR parsing? Am I reading it correctly?
This is exemplified in the two definitions of `parse_add_addexpr_cont` in the article.
It's much harder to teach the inner working / implementation of such parsers. Table generation adds an extra layer of indirection. I skip this in my class, because I doubt it will be very valuable to students to be able to implement an LR parser compared to other things we cover in the class.
Doing the OP's approach, you can get some intuition for how a LR parser behaves / is implemented without going to the full complexity.
Expr parse_addexpr() {
Expr result = parse_mulexpr();
while (peek_token() == TokenType.PLUS) {
expect_token(TokenType.PLUS);
Expr rhs = parse_mulexpr();
result = new AddExpr(result, rhs);
}
return result;
}
which corresponds to "addexpr: <mulexpr> (+ <mulexpr>)*" but with left-associative tree-composing.