repos / gbc

GBC - Go B Compiler
git clone https://github.com/xplshn/gbc.git

gbc / pkg / token
xplshn  ·  2025-09-10

token.go

Go
  1package token
  2
  3type Type int
  4
  5const (
  6	EOF Type = iota
  7	Comment
  8	Directive
  9	Ident
 10	Number
 11	FloatNumber
 12	String
 13	Auto
 14	Extrn
 15	If
 16	Else
 17	While
 18	Return
 19	Goto
 20	Switch
 21	Case
 22	Default
 23	Break
 24	Continue
 25	Asm
 26	Nil
 27	Null
 28	TypeKeyword
 29	Struct
 30	Enum
 31	Const
 32	Void
 33	Bool
 34	Byte
 35	Int
 36	Uint
 37	Int8
 38	Uint8
 39	Int16
 40	Uint16
 41	Int32
 42	Uint32
 43	Int64
 44	Uint64
 45	Float
 46	Float32
 47	Float64
 48	StringKeyword
 49	Any
 50	TypeOf
 51	LParen
 52	RParen
 53	LBrace
 54	RBrace
 55	LBracket
 56	RBracket
 57	Semi
 58	Comma
 59	Colon
 60	Question
 61	Dots
 62	Dot
 63	Eq
 64	Define
 65	PlusEq
 66	MinusEq
 67	StarEq
 68	SlashEq
 69	RemEq
 70	AndEq
 71	OrEq
 72	XorEq
 73	ShlEq
 74	ShrEq
 75	EqPlus
 76	EqMinus
 77	EqStar
 78	EqSlash
 79	EqRem
 80	EqAnd
 81	EqOr
 82	EqXor
 83	EqShl
 84	EqShr
 85	Plus
 86	Minus
 87	Star
 88	Slash
 89	Rem
 90	And
 91	Or
 92	Xor
 93	Shl
 94	Shr
 95	EqEq
 96	Neq
 97	Lt
 98	Gt
 99	Gte
100	Lte
101	AndAnd
102	OrOr
103	Not
104	Complement
105	Inc
106	Dec
107)
108
109var KeywordMap = map[string]Type{
110	"auto":     Auto,
111	"if":       If,
112	"else":     Else,
113	"while":    While,
114	"return":   Return,
115	"goto":     Goto,
116	"switch":   Switch,
117	"case":     Case,
118	"default":  Default,
119	"extrn":    Extrn,
120	"__asm__":  Asm,
121	"break":    Break,
122	"continue": Continue,
123	"nil":      Nil,
124	"null":     Null,
125	"void":     Void,
126	"type":     TypeKeyword,
127	"struct":   Struct,
128	"enum":     Enum,
129	"const":    Const,
130	"bool":     Bool,
131	"byte":     Byte,
132	"int":      Int,
133	"uint":     Uint,
134	"int8":     Int8,
135	"uint8":    Uint8,
136	"int16":    Int16,
137	"uint16":   Uint16,
138	"int32":    Int32,
139	"uint32":   Uint32,
140	"int64":    Int64,
141	"uint64":   Uint64,
142	"float":    Float,
143	"float32":  Float32,
144	"float64":  Float64,
145	"string":   StringKeyword,
146	"any":      Any,
147	"typeof":   TypeOf,
148}
149
150// Reverse mapping from Type to the keyword string
151var TypeStrings = make(map[Type]string)
152
153func init() {
154	for str, typ := range KeywordMap {
155		TypeStrings[typ] = str
156	}
157}
158
159type Token struct {
160	Type      Type
161	Value     string
162	FileIndex int
163	Line      int
164	Column    int
165	Len       int
166}