monkey/token/token.go
2021-11-30 15:27:22 -05:00

47 lines
630 B
Go

package token
type TokenType string
type Token struct {
Type TokenType
Literal string
}
const (
ILLEGAL = "ILLEGAL"
EOF = "EOF"
//Identifiers and literals
IDENT = "IDENT" //add, foo, bar, a, b, c...
INT = "INT" /// 1 2 3 4 5
//OPERATORS
ASSIGN = "="
PLUS = "+"
//DELIM
COMMA = ""
SEMICOLON = ";"
LPAREN = "("
RPAREN = ")"
LBRACE = "{"
RBRACE = "}"
// KEYWORDS
FUNCTION = "FUNCTION"
LET = "LET"
)
var keywords = map[string]TokenType{
"fn": FUNCTION,
"let": LET,
}
func LookupIdent(ident string) TokenType {
if tok, ok := keywords[ident]; ok {
return tok
}
return IDENT
}