Subroutine call

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

Subroutine call

NotRandom
I'm wondering what is possibly going on with this.

The subroutineCall is used in two different places, but a compileSubroutineCall function isn't in the recommended implementation.

Using it with the test xml files it adds an extra level of recursion. So I just don't increase the level in that function. The alternative would be duplicating the function to compileTerms and compilleDo.
Reply | Threaded
Open this post in threaded view
|

Re: Subroutine call

dolomiti7
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.
Reply | Threaded
Open this post in threaded view
|

Re: Subroutine call

NotRandom
Thanks. I really need to get the book, it would be awesome to have.