Skip to content

Commit

Permalink
compileExpressionList
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaiah Becker-Mayer committed Mar 13, 2021
1 parent 16d0444 commit cf5f23c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
32 changes: 28 additions & 4 deletions Compiler/pkg/compiler/compilationengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,6 @@ func (ce *CompilationEngine) compileSubroutineCall() error {
if err := ce.compileExpressionList(); err != nil {
return SyntaxError(err)
}
if err := ce.advance(); err != nil {
return SyntaxError(err)
}
if err := ce.compileSymbol(")"); err != nil {
return SyntaxError(err)
}
Expand Down Expand Up @@ -944,9 +941,36 @@ func (ce *CompilationEngine) compileTerm() error {
return nil
}

// (expression (',' expression)* )?
// caller should expect to be at the next token when this fucntion returns
func (ce *CompilationEngine) compileExpressionList() error {
ce.openXMLTag("expressionList")
defer ce.closeXMLTag("expressionList")
// TODO finish the rest of this

// Advance and check if we are at a closing parenthesis
if err := ce.advance(); err != nil {
return SyntaxError(err)
}
sym, _ := ce.jt.Symbol()
if ce.jt.TokenType() == symbol && sym == ")" {
// The next token was a closing parenthesis; simply return, and the caller is expected
// to compile the closing paren
return nil
}

// compile expression
if err := ce.compileExpression(); err != nil {
return SyntaxError(err)
}
for sym, _ := ce.jt.Symbol(); sym == ","; sym, _ = ce.jt.Symbol() {
ce.compileSymbol(sym) // compile ","
if err := ce.advance(); err != nil {
return SyntaxError(err)
}
if err := ce.compileExpression(); err != nil {
return SyntaxError(err)
}
}

return nil
}
2 changes: 1 addition & 1 deletion Compiler/test/ExpressionLessSquare/Square.xml
Original file line number Diff line number Diff line change
Expand Up @@ -950,4 +950,4 @@
</subroutineBody>
</subroutineDec>
<symbol> } </symbol>
</class>
</class>

0 comments on commit cf5f23c

Please sign in to comment.