Skip to content

Commit 136d6ff

Browse files
committed
1.2 Define tokens
1 parent d9674ff commit 136d6ff

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

token/token.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package token
2+
3+
// Package token defines the tokens our lexer is going to output.
4+
5+
// There is a limited number of different token types in the Monkey language.
6+
// That means we can define the possible TokenTypes as constants.
7+
const (
8+
// special type that signifies a token/character we don't know about
9+
ILLEGAL = "ILLEGAL"
10+
// special type stands for "end of file", which tells parser that it can stop
11+
EOF = "EOF"
12+
13+
// Identifiers + literals
14+
IDENT = "IDENT" // add, foobar, x, y, ...
15+
INT = "INT" // 1343456
16+
17+
// Operators
18+
ASSIGN = "="
19+
PLUS = "+"
20+
21+
// Delimiters
22+
COMMA = ","
23+
SEMICOLON = ";"
24+
25+
LPAREN = "("
26+
RPAREN = ")"
27+
LBRACE = "{"
28+
RBRACE = "}"
29+
30+
// Keywords
31+
FUNCTION = "FUNCTION"
32+
LET = "LET"
33+
)
34+
35+
// TokenType distinguishes between different types of tokens.
36+
type TokenType string
37+
38+
// Token holds a single token type and its literal value.
39+
type Token struct {
40+
Type TokenType
41+
Literal string
42+
}

0 commit comments

Comments
 (0)