Added support for binary literals

This commit is contained in:
Sasha Koshka 2022-08-11 00:17:22 -05:00
parent 77f3c590c6
commit 8f38203684

View File

@ -58,6 +58,7 @@ func (lexer *LexingOperation) tokenize () (err error) {
return
}
// tokenizeSymbolBeginning lexes a token that starts with a number.
func (lexer *LexingOperation) tokenizeNumberBeginning (negative bool) (err error) {
if lexer.char == '0' {
lexer.nextRune()
@ -88,7 +89,7 @@ func (lexer *LexingOperation) tokenizeNumberBeginning (negative bool) (err error
return
}
// tokenizeDecimalNumber Reads and tokenizes a hexidecimal number.
// tokenizeHexidecimalNumber Reads and tokenizes a hexidecimal number.
func (lexer *LexingOperation) tokenizeHexidecimalNumber (negative bool) (err error) {
var number uint64
@ -124,6 +125,38 @@ func (lexer *LexingOperation) tokenizeHexidecimalNumber (negative bool) (err err
return
}
// tokenizeBinaryNumber Reads and tokenizes a binary number.
func (lexer *LexingOperation) tokenizeBinaryNumber (negative bool) (err error) {
var number uint64
for {
if lexer.char == '0' {
number *= 2
} else if lexer.char == '1' {
number *= 2
number += 1
} else {
break
}
err = lexer.nextRune()
if err != nil { return }
}
token := Token { }
if negative {
token.kind = TokenKindInt
token.value = int64(number) * -1
} else {
token.kind = TokenKindUInt
token.value = uint64(number)
}
lexer.addToken(token)
return
}
func (lexer *LexingOperation) tokenizeAlphaBeginning () (err error) {
got := ""