Do I need <subroutineBody> tag?

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

Do I need <subroutineBody> tag?

BigBang
In the Coursera course (Unit 4.7: The Jack Analyzer), a subroutineBody xml tag appears around the { } brackets of a subroutine declaration.

Screen Coursera soubroutineBody

Is this just for reference or does it actually need to be implemented in the parser?

So far I've simply set the keyword to trigger the compileXXX and the ending symbol (the ";" symbol or the "}" symbol).

I don't understand how I should ask for the opening { brackets, because the parser doesn't recognize which compileXXX is the parent.
Reply | Threaded
Open this post in threaded view
|

Re: Do I need <subroutineBody> tag?

WBahn
Administrator
The XML output should be as you see it in the example.

The grammar is carefully constructed so that a recursive-decent parser only needs to look at the next token to decide which function to call next (there is one exception where the parse needs to look ahead at the next token, too).

So imagine that you have called compileClass(). The first three things have to be there -- 'class', and identifier, and '{'. After that, the next thing must be one of three things -- a classVarDec, a subroutineDec, or a '}'.

Consider what the next token can and can't be in each case.