aboutsummaryrefslogblamecommitdiff
path: root/users/fcuny/exp/monkey/pkg/token/token.go
blob: bc9e563c1fc0e90deb8e586d6e8ca192c00c3e60 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

















                                                                             









                             









                                                 
















                                                                                
package token

// TokenType represents the type of the token
type TokenType string

// Token represents a token, with the type and the literal value of the token
type Token struct {
	Type    TokenType
	Literal string
}

const (
	ILLEGAL = "ILLEGAL"
	EOF     = "EOF"

	IDENT = "IDENT"
	INT   = "INT"

	COMMA     = ","
	SEMICOLON = ";"

	LPAREN = "("
	RPAREN = ")"
	LBRACE = "{"
	RBRACE = "}"

	FUNCTION = "FUNCTION"
	LET      = "LET"

	// The following tokens are for operators
	ASSIGN   = "="
	PLUS     = "+"
	MINUS    = "-"
	BANG     = "!"
	ASTERISK = "*"
	SLASH    = "/"
	LT       = "<"
	GT       = ">"
)

// List of our keywords for the language
var keywords = map[string]TokenType{
	"fn":  FUNCTION,
	"let": LET,
}

// LookupIdent returns the token type for a given identifier. If the identifier
// is one of our keyword, we return the corresponding value, otherwise we return
// the given identifier.
func LookupIdent(ident string) TokenType {
	if tok, ok := keywords[ident]; ok {
		return tok
	}
	return IDENT
}