67 lines
938 B
Go
67 lines
938 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 = "+"
|
|
MINUS = "-"
|
|
BANG = "!"
|
|
ASTERISK = "*"
|
|
SLASH = "/"
|
|
|
|
LT = "<"
|
|
GT = ">"
|
|
|
|
EQ = "=="
|
|
NOT_EQ = "!="
|
|
|
|
//DELIM
|
|
COMMA = ""
|
|
SEMICOLON = ";"
|
|
|
|
LPAREN = "("
|
|
RPAREN = ")"
|
|
LBRACE = "{"
|
|
RBRACE = "}"
|
|
|
|
// KEYWORDS
|
|
FUNCTION = "FUNCTION"
|
|
LET = "LET"
|
|
TRUE = "TRUE"
|
|
FALSE = "FALSE"
|
|
IF = "IF"
|
|
ELSE = "ELSE"
|
|
RETURN = "RETURN"
|
|
)
|
|
|
|
var keywords = map[string]TokenType{
|
|
"fn": FUNCTION,
|
|
"let": LET,
|
|
"true": TRUE,
|
|
"false": FALSE,
|
|
"if": IF,
|
|
"else": ELSE,
|
|
"return": RETURN,
|
|
}
|
|
|
|
func LookupIdent(ident string) TokenType {
|
|
if tok, ok := keywords[ident]; ok {
|
|
return tok
|
|
}
|
|
return IDENT
|
|
}
|