1 /*****************************************************************************/
5 /* The scanner for the ca65 macroassembler */
9 /* (C) 1998-2004 Ullrich von Bassewitz */
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 /*****************************************************************************/
47 /*****************************************************************************/
49 /*****************************************************************************/
55 TOK_NONE, /* Start value, invalid */
56 TOK_EOF, /* End of input file */
57 TOK_SEP, /* Separator (usually newline) */
58 TOK_IDENT, /* An identifier */
59 TOK_LOCAL_IDENT, /* A cheap local identifier */
61 TOK_INTCON, /* Integer constant */
62 TOK_CHARCON, /* Character constant */
63 TOK_STRCON, /* String constant */
66 TOK_X, /* X register */
67 TOK_Y, /* Y register */
68 TOK_S, /* S register */
71 TOK_ULABEL, /* :++ or :-- */
80 TOK_BOOLAND, /* .and */
82 TOK_BOOLXOR, /* .xor */
83 TOK_BOOLNOT, /* .not */
88 TOK_STAR = TOK_MUL, /* Alias */
93 TOK_BANK = TOK_XOR, /* Alias */
99 TOK_PC, /* $ if enabled */
100 TOK_NAMESPACE, /* :: */
112 TOK_OVERRIDE_ZP, /* z: */
113 TOK_OVERRIDE_ABS, /* a: */
114 TOK_OVERRIDE_FAR, /* f: */
116 TOK_MACPARAM, /* Macro parameter, not generated by scanner */
117 TOK_REPCOUNTER, /* Repeat counter, not generated by scanner */
119 /* The next ones are tokens for the pseudo instructions. Keep together! */
121 TOK_A16 = TOK_FIRSTPSEUDO,
241 TOK_LASTPSEUDO = TOK_ZEROPAGE,
243 TOK_COUNT /* Count of tokens */
248 /* Scanner variables */
249 #define MAX_INPUT_FILES 254 /* No more than this files total */
250 #define MAX_STR_LEN 255 /* Maximum length of any string */
251 extern enum Token Tok; /* Current token */
252 extern int WS; /* Flag: Whitespace before token */
253 extern long IVal; /* Integer token attribute */
254 extern char SVal [MAX_STR_LEN+1]; /* String token attribute */
256 extern FilePos CurPos; /* Name and position in file */
257 extern int ForcedEnd; /* Force end of assembly */
261 /*****************************************************************************/
263 /*****************************************************************************/
267 void NewInputFile (const char* Name);
268 /* Open a new input file */
270 void DoneInputFile (void);
271 /* Close the current input file */
273 void NewInputData (char* Data, int Malloced);
274 /* Add a chunk of input data to the input stream */
276 void LocaseSVal (void);
277 /* Make SVal lower case */
279 void UpcaseSVal (void);
280 /* Make SVal upper case */
282 void NextRawTok (void);
283 /* Read the next raw token from the input stream */
285 int TokHasSVal (enum Token Tok);
286 /* Return true if the given token has an attached SVal */
288 int TokHasIVal (enum Token Tok);
289 /* Return true if the given token has an attached IVal */
291 #if defined(HAVE_INLINE)
292 INLINE int TokIsSep (enum Token T)
293 /* Return true if this is a separator token */
295 return (T == TOK_SEP || T == TOK_EOF);
298 # define TokIsSep(T) (T == TOK_SEP || T == TOK_EOF)
301 int GetSubKey (const char** Keys, unsigned Count);
302 /* Search for a subkey in a table of keywords. The current token must be an
303 * identifier and all keys must be in upper case. The identifier will be
304 * uppercased in the process. The function returns the index of the keyword,
305 * or -1 if the keyword was not found.
308 unsigned char ParseAddrSize (void);
309 /* Check if the next token is a keyword that denotes an address size specifier.
310 * If so, return the corresponding address size constant, otherwise output an
311 * error message and return ADDR_SIZE_DEFAULT.
314 void InitScanner (const char* InFile);
315 /* Initialize the scanner, open the given input file */
317 void DoneScanner (void);
318 /* Release scanner resources */
322 /* End of scanner.h */