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_Z, /* Z register */
70 TOK_S, /* S register */
71 TOK_REG, /* Sweet16 R.. register (in sweet16 mode) */
74 TOK_ULABEL, /* :++ or :-- */
83 TOK_BOOLAND, /* .and */
85 TOK_BOOLXOR, /* .xor */
86 TOK_BOOLNOT, /* .not */
91 TOK_STAR = TOK_MUL, /* Alias */
101 TOK_PC, /* $ if enabled */
102 TOK_NAMESPACE, /* :: */
113 TOK_AT, /* @ - in Sweet16 mode */
115 TOK_OVERRIDE_ZP, /* z: */
116 TOK_OVERRIDE_ABS, /* a: */
117 TOK_OVERRIDE_FAR, /* f: */
119 TOK_MACPARAM, /* Macro parameter, not generated by scanner */
120 TOK_REPCOUNTER, /* Repeat counter, not generated by scanner */
122 /* The next ones are tokens for the pseudo instructions. Keep together! */
124 TOK_A16 = TOK_FIRSTPSEUDO,
265 TOK_LASTPSEUDO = TOK_ZEROPAGE,
267 TOK_COUNT /* Count of tokens */
272 /* Complete token including attributes and flags */
273 typedef struct Token Token;
275 token_t Tok; /* The actual token value */
276 int WS; /* Flag for "whitespace before token" */
277 long IVal; /* Integer attribute value */
278 StrBuf SVal; /* String attribute value */
279 FilePos Pos; /* Position from which token was read */
282 /* Initializer value for a token */
283 #define STATIC_TOKEN_INITIALIZER { \
287 STATIC_STRBUF_INITIALIZER, \
288 STATIC_FILEPOS_INITIALIZER \
293 /*****************************************************************************/
295 /*****************************************************************************/
299 int TokHasSVal (token_t Tok);
300 /* Return true if the given token has an attached SVal */
302 int TokHasIVal (token_t Tok);
303 /* Return true if the given token has an attached IVal */
305 #if defined(HAVE_INLINE)
306 INLINE int TokIsSep (enum token_t T)
307 /* Return true if this is a separator token */
309 return (T == TOK_SEP || T == TOK_EOF);
312 # define TokIsSep(T) ((T) == TOK_SEP || (T) == TOK_EOF)
315 void CopyToken (Token* Dst, const Token* Src);
316 /* Copy a token. The current value of Dst.SVal is free'd, so Dst must be