1 /*****************************************************************************/
5 /* Token list for the ca65 macro assembler */
9 /* (C) 2007-2012, Ullrich von Bassewitz */
10 /* Roemerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
48 /*****************************************************************************/
50 /*****************************************************************************/
55 typedef enum token_t {
56 TOK_NONE, /* Start value, invalid */
57 TOK_EOF, /* End of input file */
58 TOK_SEP, /* Separator (usually newline) */
59 TOK_IDENT, /* An identifier */
60 TOK_LOCAL_IDENT, /* A cheap local identifier */
62 TOK_INTCON, /* Integer constant */
63 TOK_CHARCON, /* Character constant */
64 TOK_STRCON, /* String constant */
66 TOK_A, /* A)ccumulator */
67 TOK_X, /* X register */
68 TOK_Y, /* Y register */
69 TOK_S, /* S register */
70 TOK_REG, /* Sweet16 R.. register (in sweet16 mode) */
73 TOK_ULABEL, /* :++ or :-- */
82 TOK_BOOLAND, /* .and */
84 TOK_BOOLXOR, /* .xor */
85 TOK_BOOLNOT, /* .not */
90 TOK_STAR = TOK_MUL, /* Alias */
100 TOK_PC, /* $ if enabled */
101 TOK_NAMESPACE, /* :: */
112 TOK_AT, /* @ - in Sweet16 mode */
114 TOK_OVERRIDE_ZP, /* z: */
115 TOK_OVERRIDE_ABS, /* a: */
116 TOK_OVERRIDE_FAR, /* f: */
118 TOK_MACPARAM, /* Macro parameter, not generated by scanner */
119 TOK_REPCOUNTER, /* Repeat counter, not generated by scanner */
121 /* The next ones are tokens for the pseudo instructions. Keep together! */
123 TOK_A16 = TOK_FIRSTPSEUDO,
258 TOK_LASTPSEUDO = TOK_ZEROPAGE,
260 TOK_COUNT /* Count of tokens */
265 /* Complete token including attributes and flags */
266 typedef struct Token Token;
268 token_t Tok; /* The actual token value */
269 int WS; /* Flag for "whitespace before token" */
270 long IVal; /* Integer attribute value */
271 StrBuf SVal; /* String attribute value */
272 FilePos Pos; /* Position from which token was read */
275 /* Initializer value for a token */
276 #define STATIC_TOKEN_INITIALIZER { \
280 STATIC_STRBUF_INITIALIZER, \
281 STATIC_FILEPOS_INITIALIZER \
286 /*****************************************************************************/
288 /*****************************************************************************/
292 int TokHasSVal (token_t Tok);
293 /* Return true if the given token has an attached SVal */
295 int TokHasIVal (token_t Tok);
296 /* Return true if the given token has an attached IVal */
298 #if defined(HAVE_INLINE)
299 INLINE int TokIsSep (enum token_t T)
300 /* Return true if this is a separator token */
302 return (T == TOK_SEP || T == TOK_EOF);
305 # define TokIsSep(T) ((T) == TOK_SEP || (T) == TOK_EOF)
308 void CopyToken (Token* Dst, const Token* Src);
309 /* Copy a token. The current value of Dst.SVal is free'd, so Dst must be