|
From the book:
"The need for this irregular lookahead operation occurs in the
CompilationEngine twice: when parsing a term, which happens only when
parsing an expression, and when parsing a subroutineCall. Now, an
inspection of the Jack grammar shows that subroutineCall appears in two
places only: either in a do subroutineCall statement or in a term.
With that in mind, we propose parsing do subroutineCall statements as if
their syntax were do expression. This pragmatic recommendation obviates
the need to write the irregular lookahead code twice. It also implies that the
parsing of subroutineCall can now be handled directly by the compileTerm
routine. In short, we’ve localized the need to write the irregular token
lookahead code to one routine only, compileTerm, and we’ve eliminated the
need for a compileSubroutineCall routine."
This can be implemented differently though.
|