1 /*****************************************************************************/
5 /* The scanner for the ca65 macroassembler */
9 /* (C) 1998-2000 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@musoftware.de */
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 /*****************************************************************************/
41 #include "../common/filepos.h"
45 /*****************************************************************************/
47 /*****************************************************************************/
53 TOK_NONE, /* Start value, invalid */
54 TOK_EOF, /* End of input file */
55 TOK_SEP, /* Separator (usually newline) */
56 TOK_IDENT, /* An identifier */
57 TOK_MNEMO, /* A mnemonic */
59 TOK_INTCON, /* Integer constant */
60 TOK_CHARCON, /* Character constant */
61 TOK_STRCON, /* String constant */
64 TOK_X, /* X register */
65 TOK_Y, /* Y register */
66 TOK_S, /* S register */
68 TOK_ULABEL, /* :++ or :-- */
85 TOK_STAR = TOK_MUL, /* Alias */
95 TOK_PC, /* $ if enabled */
96 TOK_NAMESPACE, /* :: */
106 TOK_MACPARAM, /* Macro parameter, not generated by scanner */
108 /* The next ones are tokens for the pseudo instructions. Keep together! */
110 TOK_A16 = TOK_FIRSTPSEUDO,
192 TOK_LASTPSEUDO = TOK_ZEROPAGE,
194 TOK_COUNT /* Count of tokens */
199 /* Scanner variables */
200 #define MAX_INPUT_FILES 254 /* No more than this files total */
201 #define MAX_STR_LEN 255 /* Maximum length of any string */
202 extern enum Token Tok; /* Current token */
203 extern int WS; /* Flag: Whitespace before token */
204 extern long IVal; /* Integer token attribute */
205 extern char SVal [MAX_STR_LEN+1]; /* String token attribute */
207 extern FilePos CurPos; /* Name and position in file */
208 extern int ForcedEnd; /* Force end of assembly */
212 /*****************************************************************************/
214 /*****************************************************************************/
218 const char* GetFileName (unsigned char Name);
219 /* Get the name of a file where the name index is known */
221 void NewInputFile (const char* Name);
222 /* Open a new input file */
224 void DoneInputFile (void);
225 /* Close the current input file */
227 void NewInputData (const char* Data, int Malloced);
228 /* Add a chunk of input data to the input stream */
230 void UpcaseSVal (void);
231 /* Make SVal upper case */
234 /* Read the next token from the input stream */
236 void Consume (enum Token Expected, unsigned ErrMsg);
237 /* Consume Token, print an error if we don't find it */
239 void ConsumeSep (void);
240 /* Consume a separator token */
242 void ConsumeLParen (void);
243 /* Consume a left paren */
245 void ConsumeRParen (void);
246 /* Consume a right paren */
248 void ConsumeComma (void);
249 /* Consume a comma */
251 void SkipUntilSep (void);
252 /* Skip tokens until we reach a line separator */
254 int TokHasSVal (enum Token Tok);
255 /* Return true if the given token has an attached SVal */
257 int TokHasIVal (enum Token Tok);
258 /* Return true if the given token has an attached IVal */
260 int GetSubKey (const char** Keys, unsigned Count);
261 /* Search for a subkey in a table of keywords. The current token must be an
262 * identifier and all keys must be in upper case. The identifier will be
263 * uppercased in the process. The function returns the index of the keyword,
264 * or -1 if the keyword was not found.
267 void WriteFiles (void);
268 /* Write the list of input files to the object file */
270 void InitScanner (const char* InFile);
271 /* Initialize the scanner, open the given input file */
273 void DoneScanner (void);
274 /* Release scanner resources */
278 /* End of scanner.h */