umx_compiler

UMX virtual machine "Monkey" interpreter / bytecode compiler
git clone git://bsandro.tech/umx_compiler
Log | Files | Refs | README | LICENSE

token.go (960B)


      1 package token
      2 
      3 type TokenType string
      4 
      5 type Token struct {
      6 	Type    TokenType
      7 	Literal string
      8 }
      9 
     10 const (
     11 	ILLEGAL   = "ILLEGAL"
     12 	EOF       = "EOF"
     13 	IDENT     = "IDENT"
     14 	INT       = "INT"
     15 	ASSIGN    = "="
     16 	PLUS      = "+"
     17 	MINUS     = "-"
     18 	ASTERISK  = "*"
     19 	SLASH     = "/"
     20 	SHRIEK    = "!"
     21 	LT        = "<"
     22 	GT        = ">"
     23 	COMMA     = ","
     24 	SEMICOLON = ";"
     25 	LPAREN    = "("
     26 	RPAREN    = ")"
     27 	LCURLY    = "{"
     28 	RCURLY    = "}"
     29 	LBRACKET  = "["
     30 	RBRACKET  = "]"
     31 	FUNCTION  = "FUNCTION"
     32 	LET       = "LET"
     33 	TRUE      = "TRUE"
     34 	FALSE     = "FALSE"
     35 	IF        = "IF"
     36 	ELSE      = "ELSE"
     37 	RETURN    = "RETURN"
     38 	EQUAL     = "=="
     39 	NOT_EQUAL = "!="
     40 	STRING    = "STRING"
     41 	COLON     = ":"
     42 )
     43 
     44 var keywords = map[string]TokenType{
     45 	"fn":     FUNCTION,
     46 	"let":    LET,
     47 	"true":   TRUE,
     48 	"false":  FALSE,
     49 	"if":     IF,
     50 	"else":   ELSE,
     51 	"return": RETURN,
     52 }
     53 
     54 func LookupIdentifier(ident string) TokenType {
     55 	if tok, ok := keywords[ident]; ok {
     56 		return tok
     57 	}
     58 	return IDENT
     59 }