fix: more errors found after further testing

This commit is contained in:
2026-04-21 18:16:18 +01:00
parent f81aa97baa
commit b8af4eda84
@@ -81,7 +81,7 @@ func compileParameterList(output *strings.Builder, tokens []tokenizer.Token, ind
*(index)++ *(index)++
if tokens[*index].Type == tokenizer.SYMBOL && tokens[*index].Value == "," { if tokens[*index].Type == tokenizer.SYMBOL && tokens[*index].Value == "," {
output.WriteString("<keyword> " + tokens[*index].Value + " </keyword>\n") output.WriteString("<symbol> " + tokens[*index].Value + " </symbol>\n")
*(index)++ *(index)++
return compileParameterList(output, tokens, index) return compileParameterList(output, tokens, index)
@@ -95,6 +95,8 @@ func compileVariableDeclaration(output *strings.Builder, tokens []tokenizer.Toke
return nil return nil
} }
output.WriteString("<varDec>\n")
output.WriteString("<keyword> " + tokens[*index].Value + " </keyword>\n") output.WriteString("<keyword> " + tokens[*index].Value + " </keyword>\n")
*(index)++ *(index)++
@@ -136,6 +138,8 @@ func compileVariableDeclaration(output *strings.Builder, tokens []tokenizer.Toke
output.WriteString("<symbol> " + tokens[*index].Value + " </symbol>\n") output.WriteString("<symbol> " + tokens[*index].Value + " </symbol>\n")
(*index)++ (*index)++
output.WriteString("</varDec>\n")
return compileVariableDeclaration(output, tokens, index) return compileVariableDeclaration(output, tokens, index)
} }
@@ -500,13 +504,9 @@ func compileStatements(output *strings.Builder, tokens []tokenizer.Token, index
func compileSubroutineBody(output *strings.Builder, tokens []tokenizer.Token, index *int) error { func compileSubroutineBody(output *strings.Builder, tokens []tokenizer.Token, index *int) error {
if tokens[*index].Type == tokenizer.KEYWORD && tokens[*index].Value == "var" { if tokens[*index].Type == tokenizer.KEYWORD && tokens[*index].Value == "var" {
output.WriteString("<varDec>\n")
if err := compileVariableDeclaration(output, tokens, index); err != nil { if err := compileVariableDeclaration(output, tokens, index); err != nil {
return err return err
} }
output.WriteString("</varDec>\n")
} }
output.WriteString("<statements>\n") output.WriteString("<statements>\n")