do subroutineCall

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

do subroutineCall

rad4rman
The book says "we propose parsing do subroutineCall statements as if their syntax were do expression".

So I implemented compileDo as follows:

private void compileDo() {
    xmlWriter.printStartTag(JackXmlWriter.DO_STATEMENT_TAG_NAME);
    process(TokenType.KEYWORD); // 'do'
    compileExpression();
    process(TokenType.SYMBOL); // ';'
    xmlWriter.printEndTag(JackXmlWriter.DO_STATEMENT_TAG_NAME);
}

Which of course, given ExpressionLessSquare/Main.jack, outputs the following XML:

<keyword> do </keyword>
<expression>
<term>
<identifier> game </identifier>
<symbol> . </symbol>
<identifier> run </identifier>
<symbol> ( </symbol>
<expressionList>
</expressionList>
<symbol> ) </symbol>
</term>
</expression>
<symbol> ; </symbol>
</doStatement>

But the provided compare file contains:

<doStatement>
<keyword> do </keyword>
<identifier> game </identifier>
<symbol> . </symbol>
<identifier> run </identifier>
<symbol> ( </symbol>
<expressionList>
</expressionList>
<symbol> ) </symbol>
<symbol> ; </symbol>
</doStatement>

Have I misinterpreted the point in the book, or is the compare XML file out of sync with the book's advice?
Reply | Threaded
Open this post in threaded view
|

Re: do subroutineCall

rad4rman
For now, I will use a printTags flag:

private void compileExpression(final boolean printTags) {
    if (printTags) {
        xmlWriter.printStartTag(JackXmlWriter.EXPRESSION_TAG_NAME);
    }
    // ...
    if (printTags) {
        xmlWriter.printEndTag(JackXmlWriter.EXPRESSION_TAG_NAME);
    }
}

Perhaps this is the solution intended by the authors.