Pol  Revision:cb584c9
tokens.h
Go to the documentation of this file.
1 
7 #ifndef __TOKENS_H
8 #define __TOKENS_H
9 
10 #include <iosfwd>
11 
12 #include "../clib/rawtypes.h"
13 #include "../clib/stlutil.h"
14 
15 namespace Pol
16 {
17 namespace Bscript
18 {
31 enum BTokenType : u8
32 {
34  TYP_OPERAND = 0x01,
35  TYP_OPERATOR = 0x02, // BINARY implied
37  TYP_LEFTPAREN = 0x04,
41 
43 
44  TYP_RESERVED = 0x08,
45 
46  TYP_LABEL = 0x09, // a GOTO/GOSUB label
47 
48  TYP_FUNC = 0x10, // func returning something
49  TYP_METHOD = 0x1a, // object method
50 
51  TYP_USERFUNC = 0x1b,
52 
53  TYP_SEPARATOR = 0x1c,
54  TYP_DELIMITER = 0x1d,
55 
56  TYP_CONTROL = 0x1e,
57 
58  TYP_LEFTBRACE = 0x1f,
60 
61  TYP_NUMTYPES = 0x21,
62  TYP_FUNCREF = 0x22,
63 };
64 
65 inline std::ostream& operator<<( std::ostream& out, const BTokenType& tok )
66 {
67  return out << static_cast<int>( tok );
68 }
69 
82 enum BTokenId : u16
83 {
84  // --- LOWER SPACE 0x00-0xFF: TOKENS OUTPUTTED TO THE BYTECODE ---
85  TOK_LONG = 0x00,
86  TOK_DOUBLE = 0x01,
87  TOK_STRING = 0x02, // "string literal"
88 
89  TOK_IDENT = 0x03, // variable identifier, i.e. A, AB, A$ */
90 
91  TOK_ADD = 0x04,
92  TOK_SUBTRACT = 0x05,
93  TOK_MULT = 0x06,
94  TOK_DIV = 0x07,
95 
96  TOK_ASSIGN = 0x08,
98 
99  TOK_PLUSEQUAL = 0x0a,
105 
106  // comparison operators
107  TOK_LESSTHAN = 0x10,
108  TOK_LESSEQ = 0x11,
109  TOK_GRTHAN = 0x12,
110  TOK_GREQ = 0x13,
111 
112  TOK_AND = 0x14,
113  TOK_OR = 0x15,
114 
115  // equalite/inequality operators */
116  TOK_EQUAL = 0x16,
117  TOK_NEQ = 0x17,
118 
119  // unary operators
120  TOK_UNPLUS = 0x18,
121  TOK_UNMINUS = 0x19,
122  TOK_LOG_NOT = 0x1a,
124 
125  TOK_CONSUMER = 0x1c,
126 
128 
132 
134  CTRL_PROGEND = 0x22,
138  CTRL_LEAVE_BLOCK = 0x26, // offset is number of variables to remove
139 
142 
143  RSV_GOTO = 0x29,
144  RSV_RETURN = 0x2a,
145  RSV_EXIT = 0x2b,
146 
147  RSV_LOCAL = 0x2c,
148  RSV_GLOBAL = 0x2d,
149  RSV_VAR = 0x2e,
150 
151  RSV_FUNCTION = 0x2f,
152 
154 
155  TOK_FUNC = 0x31,
156  TOK_USERFUNC = 0x32,
157  TOK_ERROR = 0x33,
158  TOK_IN = 0x34,
159  TOK_LOCALVAR = 0x35,
163  INS_CASEJMP = 0x39,
164  INS_GET_ARG = 0x3a,
165  TOK_ARRAY = 0x3b,
166 
168 
170  TOK_STACK = 0x3e,
171  INS_INITFOR = 0x3f,
172  INS_NEXTFOR = 0x40,
173  TOK_REFTO = 0x41,
175  TOK_MODULUS = 0x43,
176 
177  TOK_BSLEFT = 0x44,
178  TOK_BSRIGHT = 0x45,
179  TOK_BITAND = 0x46,
180  TOK_BITOR = 0x47,
181  TOK_BITXOR = 0x48,
182 
183  TOK_STRUCT = 0x49,
190 
194 
197  INS_UNINIT = 0x55,
199 
204 
205  TOK_EQUAL1 = 0x5b,
206 
212 
213  TOK_FUNCREF = 0x61,
214 
215  // --- UPPER SPACE 0x0100-0xFFFF: TOKENS THAT AREN'T PART OF EMITTED CODE ---
216  //
217  // these can be safely renumbered any time, but must start from 0x100
218 
219  TOK_SEMICOLON = 0x100,
223  TOK_TERM, // terminator, ';', etc.
228 
230  RSV_ENDFOREACH, // RSV_IN: use TOK_IN
231 
238 
254 
255  CTRL_LABEL, // LABEL:
263 
268 
278 
280 };
281 
282 inline std::ostream& operator<<( std::ostream& out, const BTokenId& tok )
283 {
284  return out << static_cast<int>( tok );
285 }
286 
288 {
292 };
293 }
294 
295 namespace Clib
296 {
297 template <>
298 std::string tostring( const Bscript::BTokenType& v );
299 template <>
300 std::string tostring( const Bscript::BTokenId& v );
301 }
302 }
303 #endif
unsigned char u8
Definition: rawtypes.h:25
std::ostream & operator<<(std::ostream &os, const CompilerContext &ctx)
Definition: compctx.h:54
unsigned short u16
Definition: rawtypes.h:26
std::string tostring(const Bscript::BTokenType &v)
Definition: tokens.cpp:19
ESCRIPT_CASE_TYPES
Definition: tokens.h:287
Definition: berror.cpp:12