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,
260 TOK_LASTPSEUDO = TOK_ZEROPAGE,
262 TOK_COUNT /* Count of tokens */
267 /* Complete token including attributes and flags */
268 typedef struct Token Token;
270 token_t Tok; /* The actual token value */
271 int WS; /* Flag for "whitespace before token" */
272 long IVal; /* Integer attribute value */
273 StrBuf SVal; /* String attribute value */
274 FilePos Pos; /* Position from which token was read */
277 /* Initializer value for a token */
278 #define STATIC_TOKEN_INITIALIZER { \
282 STATIC_STRBUF_INITIALIZER, \
283 STATIC_FILEPOS_INITIALIZER \
288 /*****************************************************************************/
290 /*****************************************************************************/
294 int TokHasSVal (token_t Tok);
295 /* Return true if the given token has an attached SVal */
297 int TokHasIVal (token_t Tok);
298 /* Return true if the given token has an attached IVal */
300 #if defined(HAVE_INLINE)
301 INLINE int TokIsSep (enum token_t T)
302 /* Return true if this is a separator token */
304 return (T == TOK_SEP || T == TOK_EOF);
307 # define TokIsSep(T) ((T) == TOK_SEP || (T) == TOK_EOF)
310 void CopyToken (Token* Dst, const Token* Src);
311 /* Copy a token. The current value of Dst.SVal is free'd, so Dst must be