initial monkey lexer
This commit is contained in:
46
token/token.go
Normal file
46
token/token.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package token
|
||||
|
||||
type TokenType string
|
||||
|
||||
type Token struct {
|
||||
Type TokenType
|
||||
Literal string
|
||||
}
|
||||
|
||||
const (
|
||||
ILLEGAL = "ILLEGAL"
|
||||
EOF = "EOF"
|
||||
|
||||
// Identifiers + literals
|
||||
IDENT = "IDENT" // add, foobar, x, y
|
||||
INT = "INT" // 123456
|
||||
|
||||
// Operators
|
||||
ASSIGN = "="
|
||||
PLUS = "+"
|
||||
|
||||
// Delimiters
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user