Fixed bug where comments were not properly ignored

This commit is contained in:
Sasha Koshka
2022-10-27 22:51:04 -04:00
parent d648660889
commit 2a53da6f95
5 changed files with 55 additions and 57 deletions

View File

@@ -72,6 +72,10 @@ func main () {
for lineNumber := 0; inputScanner.Scan(); lineNumber ++ {
tokens := strings.Fields(inputScanner.Text())
if len(tokens) == 0 { continue }
if tokens[0][0] == '/' {
// skip line if it is a comment
continue
}
statement, err := parseStatement(tokens)
statement.lineNumber = lineNumber
@@ -128,7 +132,7 @@ func main () {
// for _, statement := range statements {
// fmt.Println(statement)
// }
//
// for symbol, address := range symbolTable {
// fmt.Println(symbol, address)
// }
@@ -195,11 +199,6 @@ func main () {
}
func parseStatement (tokens []string) (statement Statement, err error) {
if tokens[0][0] == '/' {
// skip line if it is a comment
return
}
// get label if it exists
possibleLabel := tokens[0]
if possibleLabel[len(possibleLabel) - 1] == ',' {