parsing expression

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

parsing expression

invin
I have a few questions about the parsing of expressions:

1) In RETURN rule how to figure out whether to call compileExpression() since the expression is optional?

2) Similarly, EXPRESSION-LIST  rule, how is compileExpressionList() method going to figure out whether the expression is there or not since it is optional?
Reply | Threaded
Open this post in threaded view
|

Re: parsing expression

ivant
As described on pages 206-207, Jack grammar is almost LL(0). The 0 part means that the current token (the thing you're "looking" at at the moment) is enough to know how to choose between the alternatives.

The only exception is the parsing of expressions, where you'll need to do a single look ahead. What does that mean? It means that you need to peek at next token to see what it is so you can dispatch correctly.