-
Notifications
You must be signed in to change notification settings - Fork 0
/
tokens.go
47 lines (41 loc) · 1.21 KB
/
tokens.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"bytes"
"fmt"
)
type TokenType uint8
type valBytes []byte
type Token struct {
tokenType TokenType
val valBytes
}
func (t Token) String() string {
return fmt.Sprintf("Type: %d, Literal: %s", t.tokenType, string(t.val))
}
func (t Token) Equals(tt Token) bool {
return t.tokenType == tt.tokenType && bytes.Equal(t.val, tt.val)
}
func NewToken(ttype TokenType, val ...byte) Token {
return Token{tokenType: ttype, val: val}
}
const (
Plus TokenType = iota + 1 // +
Minus // -
Asterisk // *
Slash // /
CommentHash // # (for comment)
Assign // =
Eq // ==
Not // !
NotEq // !=
LT // <
GT // >
LTEQ // <=
GTEQ // >=
RaisePower // **
Mod // %
Number // 1234, 12.23
SemiColon // ;
LeftBrace // (
RightBrace // )
)