Implemented numeric constants

This commit is contained in:
2024-06-14 11:48:28 +02:00
parent f04e9d7a60
commit 19489d7a9a
7 changed files with 59 additions and 9 deletions

View File

@ -2,5 +2,6 @@ package token
// Keywords defines the keywords used in the language.
var Keywords = map[string]bool{
"let": true,
"return": true,
}

View File

@ -13,7 +13,7 @@ func (list List) String() string {
var last Token
for _, t := range list {
if t.Kind == Identifier && last.Kind == Separator {
if last.Kind == Keyword || last.Kind == Separator {
builder.WriteByte(' ')
}

View File

@ -70,6 +70,9 @@ func Tokenize(buffer []byte) List {
case ']':
tokens = append(tokens, Token{ArrayEnd, i, arrayEndBytes})
case '=', ':', '+', '-', '*', '/', '<', '>', '!':
tokens = append(tokens, Token{Operator, i, buffer[i : i+1]})
// Separator
case ',':
tokens = append(tokens, Token{Separator, i, separatorBytes})
@ -147,3 +150,7 @@ func isNumber(c byte) bool {
func isNumberStart(c byte) bool {
return isNumber(c) || c == '-'
}
func isOperator(c byte) bool {
return c == '=' || c == ':' || c == '+' || c == '-' || c == '*' || c == '/' || c == '<' || c == '>' || c == '!'
}