2000-05-28 13:40:48 +00:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* */
|
|
|
|
|
/* scanner.h */
|
|
|
|
|
/* */
|
|
|
|
|
/* The scanner for the ca65 macroassembler */
|
|
|
|
|
/* */
|
|
|
|
|
/* */
|
|
|
|
|
/* */
|
2005-05-09 18:57:03 +00:00
|
|
|
|
/* (C) 1998-2005 Ullrich von Bassewitz */
|
2003-11-13 00:21:31 +00:00
|
|
|
|
/* R<>merstra<72>e 52 */
|
2003-03-07 11:33:14 +00:00
|
|
|
|
/* D-70794 Filderstadt */
|
|
|
|
|
/* EMail: uz@cc65.org */
|
2000-05-28 13:40:48 +00:00
|
|
|
|
/* */
|
|
|
|
|
/* */
|
|
|
|
|
/* This software is provided 'as-is', without any expressed or implied */
|
|
|
|
|
/* warranty. In no event will the authors be held liable for any damages */
|
|
|
|
|
/* arising from the use of this software. */
|
|
|
|
|
/* */
|
|
|
|
|
/* Permission is granted to anyone to use this software for any purpose, */
|
|
|
|
|
/* including commercial applications, and to alter it and redistribute it */
|
|
|
|
|
/* freely, subject to the following restrictions: */
|
|
|
|
|
/* */
|
|
|
|
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
|
|
|
|
/* claim that you wrote the original software. If you use this software */
|
|
|
|
|
/* in a product, an acknowledgment in the product documentation would be */
|
|
|
|
|
/* appreciated but is not required. */
|
|
|
|
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
|
|
|
|
/* be misrepresented as being the original software. */
|
|
|
|
|
/* 3. This notice may not be removed or altered from any source */
|
|
|
|
|
/* distribution. */
|
|
|
|
|
/* */
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef SCANNER_H
|
|
|
|
|
#define SCANNER_H
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-07-28 12:15:40 +00:00
|
|
|
|
/* common */
|
|
|
|
|
#include "filepos.h"
|
2003-01-19 12:04:33 +00:00
|
|
|
|
#include "inline.h"
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Data */
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Tokens */
|
|
|
|
|
enum Token {
|
|
|
|
|
TOK_NONE, /* Start value, invalid */
|
|
|
|
|
TOK_EOF, /* End of input file */
|
|
|
|
|
TOK_SEP, /* Separator (usually newline) */
|
|
|
|
|
TOK_IDENT, /* An identifier */
|
2003-11-29 07:53:26 +00:00
|
|
|
|
TOK_LOCAL_IDENT, /* A cheap local identifier */
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
TOK_INTCON, /* Integer constant */
|
2003-10-17 00:38:21 +00:00
|
|
|
|
TOK_CHARCON, /* Character constant */
|
|
|
|
|
TOK_STRCON, /* String constant */
|
|
|
|
|
|
2004-10-03 21:26:00 +00:00
|
|
|
|
TOK_A, /* A)ccumulator */
|
2003-10-17 00:38:21 +00:00
|
|
|
|
TOK_X, /* X register */
|
|
|
|
|
TOK_Y, /* Y register */
|
|
|
|
|
TOK_S, /* S register */
|
2004-10-03 21:26:00 +00:00
|
|
|
|
TOK_REG, /* Sweet16 R.. register (in sweet16 mode) */
|
2003-10-17 00:38:21 +00:00
|
|
|
|
|
|
|
|
|
TOK_ASSIGN, /* := */
|
|
|
|
|
TOK_ULABEL, /* :++ or :-- */
|
|
|
|
|
|
|
|
|
|
TOK_EQ, /* = */
|
|
|
|
|
TOK_NE, /* <> */
|
|
|
|
|
TOK_LT, /* < */
|
|
|
|
|
TOK_GT, /* > */
|
|
|
|
|
TOK_LE, /* <= */
|
|
|
|
|
TOK_GE, /* >= */
|
|
|
|
|
|
2003-11-11 13:57:30 +00:00
|
|
|
|
TOK_BOOLAND, /* .and */
|
|
|
|
|
TOK_BOOLOR, /* .or */
|
|
|
|
|
TOK_BOOLXOR, /* .xor */
|
|
|
|
|
TOK_BOOLNOT, /* .not */
|
2003-10-17 00:38:21 +00:00
|
|
|
|
|
|
|
|
|
TOK_PLUS, /* + */
|
|
|
|
|
TOK_MINUS, /* - */
|
2003-01-19 12:04:33 +00:00
|
|
|
|
TOK_MUL, /* * */
|
2000-05-28 13:40:48 +00:00
|
|
|
|
TOK_STAR = TOK_MUL, /* Alias */
|
2003-10-17 00:38:21 +00:00
|
|
|
|
TOK_DIV, /* / */
|
|
|
|
|
TOK_MOD, /* ! */
|
|
|
|
|
TOK_OR, /* | */
|
|
|
|
|
TOK_XOR, /* ^ */
|
2003-11-11 13:57:30 +00:00
|
|
|
|
TOK_BANK = TOK_XOR, /* Alias */
|
2003-10-17 00:38:21 +00:00
|
|
|
|
TOK_AND, /* & */
|
|
|
|
|
TOK_SHL, /* << */
|
|
|
|
|
TOK_SHR, /* >> */
|
|
|
|
|
TOK_NOT, /* ~ */
|
|
|
|
|
|
|
|
|
|
TOK_PC, /* $ if enabled */
|
2000-05-28 13:40:48 +00:00
|
|
|
|
TOK_NAMESPACE, /* :: */
|
2003-10-17 00:38:21 +00:00
|
|
|
|
TOK_DOT, /* . */
|
|
|
|
|
TOK_COMMA, /* , */
|
|
|
|
|
TOK_HASH, /* # */
|
|
|
|
|
TOK_COLON, /* : */
|
|
|
|
|
TOK_LPAREN, /* ( */
|
|
|
|
|
TOK_RPAREN, /* ) */
|
|
|
|
|
TOK_LBRACK, /* [ */
|
|
|
|
|
TOK_RBRACK, /* ] */
|
2004-05-09 19:45:07 +00:00
|
|
|
|
TOK_LCURLY, /* { */
|
|
|
|
|
TOK_RCURLY, /* } */
|
2004-10-03 21:26:00 +00:00
|
|
|
|
TOK_AT, /* @ - in Sweet16 mode */
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
2003-06-17 20:22:14 +00:00
|
|
|
|
TOK_OVERRIDE_ZP, /* z: */
|
|
|
|
|
TOK_OVERRIDE_ABS, /* a: */
|
|
|
|
|
TOK_OVERRIDE_FAR, /* f: */
|
|
|
|
|
|
2003-10-17 00:38:21 +00:00
|
|
|
|
TOK_MACPARAM, /* Macro parameter, not generated by scanner */
|
2003-03-07 11:33:14 +00:00
|
|
|
|
TOK_REPCOUNTER, /* Repeat counter, not generated by scanner */
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
/* The next ones are tokens for the pseudo instructions. Keep together! */
|
|
|
|
|
TOK_FIRSTPSEUDO,
|
|
|
|
|
TOK_A16 = TOK_FIRSTPSEUDO,
|
|
|
|
|
TOK_A8,
|
|
|
|
|
TOK_ADDR,
|
|
|
|
|
TOK_ALIGN,
|
|
|
|
|
TOK_ASCIIZ,
|
2003-06-06 12:45:19 +00:00
|
|
|
|
TOK_ASSERT,
|
2000-05-28 13:40:48 +00:00
|
|
|
|
TOK_AUTOIMPORT,
|
2003-12-12 15:59:44 +00:00
|
|
|
|
TOK_BANKBYTE,
|
2000-05-28 13:40:48 +00:00
|
|
|
|
TOK_BLANK,
|
|
|
|
|
TOK_BSS,
|
|
|
|
|
TOK_BYTE,
|
2002-11-22 01:45:00 +00:00
|
|
|
|
TOK_CASE,
|
2002-02-18 09:11:57 +00:00
|
|
|
|
TOK_CHARMAP,
|
2000-05-28 13:40:48 +00:00
|
|
|
|
TOK_CODE,
|
2002-02-18 09:11:57 +00:00
|
|
|
|
TOK_CONCAT,
|
2000-11-20 15:22:57 +00:00
|
|
|
|
TOK_CONDES,
|
2000-05-28 13:40:48 +00:00
|
|
|
|
TOK_CONST,
|
2000-11-20 15:22:57 +00:00
|
|
|
|
TOK_CONSTRUCTOR,
|
2000-05-28 13:40:48 +00:00
|
|
|
|
TOK_CPU,
|
|
|
|
|
TOK_DATA,
|
2000-08-01 21:36:45 +00:00
|
|
|
|
TOK_DBG,
|
2000-05-28 13:40:48 +00:00
|
|
|
|
TOK_DBYT,
|
|
|
|
|
TOK_DEBUGINFO,
|
|
|
|
|
TOK_DEFINE,
|
|
|
|
|
TOK_DEFINED,
|
2000-11-20 15:22:57 +00:00
|
|
|
|
TOK_DESTRUCTOR,
|
2000-05-28 13:40:48 +00:00
|
|
|
|
TOK_DWORD,
|
|
|
|
|
TOK_ELSE,
|
|
|
|
|
TOK_ELSEIF,
|
2003-11-17 17:59:30 +00:00
|
|
|
|
TOK_END,
|
2003-11-14 09:03:32 +00:00
|
|
|
|
TOK_ENDENUM,
|
2000-05-28 13:40:48 +00:00
|
|
|
|
TOK_ENDIF,
|
|
|
|
|
TOK_ENDMACRO,
|
|
|
|
|
TOK_ENDPROC,
|
|
|
|
|
TOK_ENDREP,
|
2003-11-08 23:27:30 +00:00
|
|
|
|
TOK_ENDSCOPE,
|
2003-10-17 00:38:21 +00:00
|
|
|
|
TOK_ENDSTRUCT,
|
2003-11-13 22:03:24 +00:00
|
|
|
|
TOK_ENDUNION,
|
2003-11-14 09:03:32 +00:00
|
|
|
|
TOK_ENUM,
|
2000-05-28 13:40:48 +00:00
|
|
|
|
TOK_ERROR,
|
|
|
|
|
TOK_EXITMACRO,
|
|
|
|
|
TOK_EXPORT,
|
|
|
|
|
TOK_EXPORTZP,
|
|
|
|
|
TOK_FARADDR,
|
|
|
|
|
TOK_FEATURE,
|
|
|
|
|
TOK_FILEOPT,
|
2003-03-07 11:33:14 +00:00
|
|
|
|
TOK_FORCEIMPORT,
|
2000-07-29 15:53:33 +00:00
|
|
|
|
TOK_FORCEWORD,
|
2000-05-28 13:40:48 +00:00
|
|
|
|
TOK_GLOBAL,
|
|
|
|
|
TOK_GLOBALZP,
|
2003-12-12 15:59:44 +00:00
|
|
|
|
TOK_HIBYTE,
|
|
|
|
|
TOK_HIWORD,
|
2000-05-28 13:40:48 +00:00
|
|
|
|
TOK_I16,
|
|
|
|
|
TOK_I8,
|
2005-05-09 18:57:03 +00:00
|
|
|
|
TOK_MAKEIDENT,
|
2000-05-28 13:40:48 +00:00
|
|
|
|
TOK_IF,
|
|
|
|
|
TOK_IFBLANK,
|
|
|
|
|
TOK_IFCONST,
|
|
|
|
|
TOK_IFDEF,
|
|
|
|
|
TOK_IFNBLANK,
|
|
|
|
|
TOK_IFNCONST,
|
|
|
|
|
TOK_IFNDEF,
|
|
|
|
|
TOK_IFNREF,
|
|
|
|
|
TOK_IFP02,
|
|
|
|
|
TOK_IFP816,
|
|
|
|
|
TOK_IFPC02,
|
2003-08-07 08:13:46 +00:00
|
|
|
|
TOK_IFPSC02,
|
2000-05-28 13:40:48 +00:00
|
|
|
|
TOK_IFREF,
|
|
|
|
|
TOK_IMPORT,
|
|
|
|
|
TOK_IMPORTZP,
|
|
|
|
|
TOK_INCBIN,
|
|
|
|
|
TOK_INCLUDE,
|
2004-09-20 10:15:01 +00:00
|
|
|
|
TOK_INTERRUPTOR,
|
2000-07-08 14:01:43 +00:00
|
|
|
|
TOK_LEFT,
|
2000-05-28 13:40:48 +00:00
|
|
|
|
TOK_LINECONT,
|
|
|
|
|
TOK_LIST,
|
|
|
|
|
TOK_LISTBYTES,
|
2004-10-03 21:26:00 +00:00
|
|
|
|
TOK_LOBYTE,
|
2000-05-28 13:40:48 +00:00
|
|
|
|
TOK_LOCAL,
|
|
|
|
|
TOK_LOCALCHAR,
|
2003-12-12 15:59:44 +00:00
|
|
|
|
TOK_LOWORD,
|
2000-05-28 13:40:48 +00:00
|
|
|
|
TOK_MACPACK,
|
|
|
|
|
TOK_MACRO,
|
|
|
|
|
TOK_MATCH,
|
2000-06-03 11:15:11 +00:00
|
|
|
|
TOK_MID,
|
2000-05-28 13:40:48 +00:00
|
|
|
|
TOK_NULL,
|
|
|
|
|
TOK_ORG,
|
2003-11-11 13:57:30 +00:00
|
|
|
|
TOK_OUT,
|
2000-05-28 13:40:48 +00:00
|
|
|
|
TOK_P02,
|
|
|
|
|
TOK_P816,
|
|
|
|
|
TOK_PAGELENGTH,
|
|
|
|
|
TOK_PARAMCOUNT,
|
2003-01-04 16:59:51 +00:00
|
|
|
|
TOK_PC02,
|
2002-11-28 17:42:16 +00:00
|
|
|
|
TOK_POPSEG,
|
2000-05-28 13:40:48 +00:00
|
|
|
|
TOK_PROC,
|
2003-08-07 08:13:46 +00:00
|
|
|
|
TOK_PSC02,
|
2002-11-28 17:42:16 +00:00
|
|
|
|
TOK_PUSHSEG,
|
2000-05-28 13:40:48 +00:00
|
|
|
|
TOK_REFERENCED,
|
|
|
|
|
TOK_RELOC,
|
|
|
|
|
TOK_REPEAT,
|
2000-07-15 10:33:32 +00:00
|
|
|
|
TOK_RES,
|
2000-07-08 14:01:43 +00:00
|
|
|
|
TOK_RIGHT,
|
2000-05-28 13:40:48 +00:00
|
|
|
|
TOK_RODATA,
|
2003-11-08 23:27:30 +00:00
|
|
|
|
TOK_SCOPE,
|
2000-05-28 13:40:48 +00:00
|
|
|
|
TOK_SEGMENT,
|
2005-05-11 08:31:42 +00:00
|
|
|
|
TOK_SET,
|
2003-11-29 07:53:26 +00:00
|
|
|
|
TOK_SETCPU,
|
2003-11-17 17:59:30 +00:00
|
|
|
|
TOK_SIZEOF,
|
2000-05-28 13:40:48 +00:00
|
|
|
|
TOK_SMART,
|
2005-05-10 15:42:32 +00:00
|
|
|
|
TOK_SPRINTF,
|
2000-07-25 21:32:11 +00:00
|
|
|
|
TOK_STRAT,
|
2000-05-28 13:40:48 +00:00
|
|
|
|
TOK_STRING,
|
2000-07-25 21:32:11 +00:00
|
|
|
|
TOK_STRLEN,
|
2003-10-17 00:38:21 +00:00
|
|
|
|
TOK_STRUCT,
|
2000-05-28 13:40:48 +00:00
|
|
|
|
TOK_SUNPLUS,
|
2003-10-17 00:38:21 +00:00
|
|
|
|
TOK_TAG,
|
2000-07-15 10:33:32 +00:00
|
|
|
|
TOK_TCOUNT,
|
2002-11-26 13:44:35 +00:00
|
|
|
|
TOK_TIME,
|
2003-10-17 00:38:21 +00:00
|
|
|
|
TOK_UNION,
|
2003-08-12 15:11:55 +00:00
|
|
|
|
TOK_VERSION,
|
2000-07-27 18:47:57 +00:00
|
|
|
|
TOK_WARNING,
|
2000-05-28 13:40:48 +00:00
|
|
|
|
TOK_WORD,
|
|
|
|
|
TOK_XMATCH,
|
|
|
|
|
TOK_ZEROPAGE,
|
|
|
|
|
TOK_LASTPSEUDO = TOK_ZEROPAGE,
|
|
|
|
|
|
2003-10-17 00:38:21 +00:00
|
|
|
|
TOK_COUNT /* Count of tokens */
|
2000-05-28 13:40:48 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Scanner variables */
|
|
|
|
|
#define MAX_INPUT_FILES 254 /* No more than this files total */
|
|
|
|
|
#define MAX_STR_LEN 255 /* Maximum length of any string */
|
|
|
|
|
extern enum Token Tok; /* Current token */
|
|
|
|
|
extern int WS; /* Flag: Whitespace before token */
|
|
|
|
|
extern long IVal; /* Integer token attribute */
|
|
|
|
|
extern char SVal [MAX_STR_LEN+1]; /* String token attribute */
|
|
|
|
|
|
|
|
|
|
extern FilePos CurPos; /* Name and position in file */
|
|
|
|
|
extern int ForcedEnd; /* Force end of assembly */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Code */
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
2003-06-06 12:45:19 +00:00
|
|
|
|
|
2005-05-09 18:57:03 +00:00
|
|
|
|
int IsIdChar (int C);
|
|
|
|
|
/* Return true if the character is a valid character for an identifier */
|
|
|
|
|
|
|
|
|
|
int IsIdStart (int C);
|
|
|
|
|
/* Return true if the character may start an identifier */
|
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
|
void NewInputFile (const char* Name);
|
|
|
|
|
/* Open a new input file */
|
|
|
|
|
|
|
|
|
|
void DoneInputFile (void);
|
|
|
|
|
/* Close the current input file */
|
|
|
|
|
|
2003-01-04 16:59:51 +00:00
|
|
|
|
void NewInputData (char* Data, int Malloced);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
/* Add a chunk of input data to the input stream */
|
|
|
|
|
|
2000-09-02 11:35:22 +00:00
|
|
|
|
void LocaseSVal (void);
|
|
|
|
|
/* Make SVal lower case */
|
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
|
void UpcaseSVal (void);
|
|
|
|
|
/* Make SVal upper case */
|
|
|
|
|
|
2000-06-03 11:15:11 +00:00
|
|
|
|
void NextRawTok (void);
|
|
|
|
|
/* Read the next raw token from the input stream */
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
int TokHasSVal (enum Token Tok);
|
|
|
|
|
/* Return true if the given token has an attached SVal */
|
|
|
|
|
|
|
|
|
|
int TokHasIVal (enum Token Tok);
|
|
|
|
|
/* Return true if the given token has an attached IVal */
|
|
|
|
|
|
2003-01-19 12:04:33 +00:00
|
|
|
|
#if defined(HAVE_INLINE)
|
|
|
|
|
INLINE int TokIsSep (enum Token T)
|
|
|
|
|
/* Return true if this is a separator token */
|
|
|
|
|
{
|
|
|
|
|
return (T == TOK_SEP || T == TOK_EOF);
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
# define TokIsSep(T) (T == TOK_SEP || T == TOK_EOF)
|
|
|
|
|
#endif
|
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
|
int GetSubKey (const char** Keys, unsigned Count);
|
|
|
|
|
/* Search for a subkey in a table of keywords. The current token must be an
|
|
|
|
|
* identifier and all keys must be in upper case. The identifier will be
|
|
|
|
|
* uppercased in the process. The function returns the index of the keyword,
|
|
|
|
|
* or -1 if the keyword was not found.
|
|
|
|
|
*/
|
|
|
|
|
|
2003-11-13 00:21:31 +00:00
|
|
|
|
unsigned char ParseAddrSize (void);
|
2003-11-07 19:28:37 +00:00
|
|
|
|
/* Check if the next token is a keyword that denotes an address size specifier.
|
|
|
|
|
* If so, return the corresponding address size constant, otherwise output an
|
|
|
|
|
* error message and return ADDR_SIZE_DEFAULT.
|
|
|
|
|
*/
|
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
|
void InitScanner (const char* InFile);
|
|
|
|
|
/* Initialize the scanner, open the given input file */
|
|
|
|
|
|
|
|
|
|
void DoneScanner (void);
|
|
|
|
|
/* Release scanner resources */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* End of scanner.h */
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|