optimizations
Some checks failed
Build / build (push) Successful in 9m47s
Publish Image / publish (push) Failing after 49s
Test / build (push) Failing after 6m19s

This commit is contained in:
Chuck Smith
2024-04-02 14:32:03 -04:00
parent 07fd82b261
commit 88e3330856
18 changed files with 510 additions and 31 deletions

View File

@@ -182,9 +182,7 @@ func (l *Lexer) NextToken() token.Token {
tok.Type = token.LookupIdent(tok.Literal)
return tok
} else if isDigit(l.ch) {
tok.Type = token.INT
tok.Literal = l.readNumber()
return tok
return l.readNumber()
} else {
tok = newToken(token.ILLEGAL, l.ch)
}
@@ -209,12 +207,22 @@ func (l *Lexer) readIdentifier() string {
return l.input[position:l.position]
}
func (l *Lexer) readNumber() string {
func (l *Lexer) readNumber() token.Token {
position := l.position
for isDigit(l.ch) {
l.readChar()
}
return l.input[position:l.position]
intPart := l.input[position:l.position]
if l.ch == '.' {
l.readChar()
position := l.position
for isDigit(l.ch) {
l.readChar()
}
fracPart := l.input[position:l.position]
return token.Token{Type: token.FLOAT, Literal: intPart + "." + fracPart}
}
return token.Token{Type: token.INT, Literal: intPart}
}
func isLetter(ch byte) bool {