2007-08-27 20:39:02 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* */
|
2007-08-28 21:14:21 +00:00
|
|
|
/* token.h */
|
2007-08-27 20:39:02 +00:00
|
|
|
/* */
|
|
|
|
/* Token list for the ca65 macro assembler */
|
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* */
|
2012-01-03 21:41:34 +00:00
|
|
|
/* (C) 2007-2012, Ullrich von Bassewitz */
|
2010-04-18 18:47:16 +00:00
|
|
|
/* Roemerstrasse 52 */
|
|
|
|
/* D-70794 Filderstadt */
|
|
|
|
/* EMail: uz@cc65.org */
|
2007-08-27 20:39:02 +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 TOKEN_H
|
|
|
|
#define TOKEN_H
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-08-28 21:14:21 +00:00
|
|
|
/* common */
|
2011-01-16 16:05:43 +00:00
|
|
|
#include "filepos.h"
|
2007-08-28 21:14:21 +00:00
|
|
|
#include "inline.h"
|
2011-01-16 16:05:43 +00:00
|
|
|
#include "strbuf.h"
|
2007-08-28 21:14:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2007-08-27 20:39:02 +00:00
|
|
|
/*****************************************************************************/
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Data */
|
2007-08-27 20:39:02 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-01-16 16:05:43 +00:00
|
|
|
/* Tokens */
|
2011-01-16 14:51:13 +00:00
|
|
|
typedef enum token_t {
|
2013-05-09 11:56:54 +00:00
|
|
|
TOK_NONE, /* Start value, invalid */
|
|
|
|
TOK_EOF, /* End of input file */
|
|
|
|
TOK_SEP, /* Separator (usually newline) */
|
|
|
|
TOK_IDENT, /* An identifier */
|
2007-08-27 20:39:02 +00:00
|
|
|
TOK_LOCAL_IDENT, /* A cheap local identifier */
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
TOK_INTCON, /* Integer constant */
|
|
|
|
TOK_CHARCON, /* Character constant */
|
|
|
|
TOK_STRCON, /* String constant */
|
2007-08-27 20:39:02 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
TOK_A, /* A)ccumulator */
|
|
|
|
TOK_X, /* X register */
|
|
|
|
TOK_Y, /* Y register */
|
|
|
|
TOK_S, /* S register */
|
2007-08-27 20:39:02 +00:00
|
|
|
TOK_REG, /* Sweet16 R.. register (in sweet16 mode) */
|
|
|
|
|
|
|
|
TOK_ASSIGN, /* := */
|
2013-05-09 11:56:54 +00:00
|
|
|
TOK_ULABEL, /* :++ or :-- */
|
|
|
|
|
|
|
|
TOK_EQ, /* = */
|
|
|
|
TOK_NE, /* <> */
|
|
|
|
TOK_LT, /* < */
|
|
|
|
TOK_GT, /* > */
|
|
|
|
TOK_LE, /* <= */
|
|
|
|
TOK_GE, /* >= */
|
|
|
|
|
|
|
|
TOK_BOOLAND, /* .and */
|
|
|
|
TOK_BOOLOR, /* .or */
|
|
|
|
TOK_BOOLXOR, /* .xor */
|
|
|
|
TOK_BOOLNOT, /* .not */
|
|
|
|
|
|
|
|
TOK_PLUS, /* + */
|
|
|
|
TOK_MINUS, /* - */
|
|
|
|
TOK_MUL, /* * */
|
|
|
|
TOK_STAR = TOK_MUL, /* Alias */
|
|
|
|
TOK_DIV, /* / */
|
|
|
|
TOK_MOD, /* ! */
|
|
|
|
TOK_OR, /* | */
|
|
|
|
TOK_XOR, /* ^ */
|
|
|
|
TOK_AND, /* & */
|
|
|
|
TOK_SHL, /* << */
|
|
|
|
TOK_SHR, /* >> */
|
|
|
|
TOK_NOT, /* ~ */
|
|
|
|
|
|
|
|
TOK_PC, /* $ if enabled */
|
|
|
|
TOK_NAMESPACE, /* :: */
|
|
|
|
TOK_DOT, /* . */
|
|
|
|
TOK_COMMA, /* , */
|
|
|
|
TOK_HASH, /* # */
|
|
|
|
TOK_COLON, /* : */
|
|
|
|
TOK_LPAREN, /* ( */
|
|
|
|
TOK_RPAREN, /* ) */
|
|
|
|
TOK_LBRACK, /* [ */
|
|
|
|
TOK_RBRACK, /* ] */
|
2007-08-27 20:39:02 +00:00
|
|
|
TOK_LCURLY, /* { */
|
|
|
|
TOK_RCURLY, /* } */
|
|
|
|
TOK_AT, /* @ - in Sweet16 mode */
|
|
|
|
|
|
|
|
TOK_OVERRIDE_ZP, /* z: */
|
|
|
|
TOK_OVERRIDE_ABS, /* a: */
|
|
|
|
TOK_OVERRIDE_FAR, /* f: */
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
TOK_MACPARAM, /* Macro parameter, not generated by scanner */
|
|
|
|
TOK_REPCOUNTER, /* Repeat counter, not generated by scanner */
|
2007-08-27 20:39:02 +00:00
|
|
|
|
|
|
|
/* The next ones are tokens for the pseudo instructions. Keep together! */
|
|
|
|
TOK_FIRSTPSEUDO,
|
2013-05-09 11:56:54 +00:00
|
|
|
TOK_A16 = TOK_FIRSTPSEUDO,
|
2007-08-27 20:39:02 +00:00
|
|
|
TOK_A8,
|
|
|
|
TOK_ADDR,
|
2015-04-20 03:21:56 +00:00
|
|
|
TOK_ADDRSIZE,
|
2007-08-27 20:39:02 +00:00
|
|
|
TOK_ALIGN,
|
|
|
|
TOK_ASCIIZ,
|
2015-10-19 23:30:25 +00:00
|
|
|
TOK_ASIZE,
|
2007-08-27 20:39:02 +00:00
|
|
|
TOK_ASSERT,
|
|
|
|
TOK_AUTOIMPORT,
|
2012-01-03 21:41:34 +00:00
|
|
|
TOK_BANK,
|
2007-08-27 20:39:02 +00:00
|
|
|
TOK_BANKBYTE,
|
2009-05-18 16:11:34 +00:00
|
|
|
TOK_BANKBYTES,
|
2007-08-27 20:39:02 +00:00
|
|
|
TOK_BLANK,
|
|
|
|
TOK_BSS,
|
|
|
|
TOK_BYTE,
|
|
|
|
TOK_CASE,
|
|
|
|
TOK_CHARMAP,
|
|
|
|
TOK_CODE,
|
|
|
|
TOK_CONCAT,
|
|
|
|
TOK_CONDES,
|
|
|
|
TOK_CONST,
|
|
|
|
TOK_CONSTRUCTOR,
|
|
|
|
TOK_CPU,
|
|
|
|
TOK_DATA,
|
|
|
|
TOK_DBG,
|
|
|
|
TOK_DBYT,
|
|
|
|
TOK_DEBUGINFO,
|
|
|
|
TOK_DEFINE,
|
|
|
|
TOK_DEFINED,
|
2015-05-11 00:25:40 +00:00
|
|
|
TOK_DEFINEDMACRO,
|
2011-06-12 21:29:07 +00:00
|
|
|
TOK_DELMAC,
|
2007-08-27 20:39:02 +00:00
|
|
|
TOK_DESTRUCTOR,
|
|
|
|
TOK_DWORD,
|
|
|
|
TOK_ELSE,
|
|
|
|
TOK_ELSEIF,
|
|
|
|
TOK_END,
|
|
|
|
TOK_ENDENUM,
|
|
|
|
TOK_ENDIF,
|
|
|
|
TOK_ENDMACRO,
|
|
|
|
TOK_ENDPROC,
|
|
|
|
TOK_ENDREP,
|
|
|
|
TOK_ENDSCOPE,
|
|
|
|
TOK_ENDSTRUCT,
|
|
|
|
TOK_ENDUNION,
|
|
|
|
TOK_ENUM,
|
|
|
|
TOK_ERROR,
|
|
|
|
TOK_EXITMACRO,
|
|
|
|
TOK_EXPORT,
|
|
|
|
TOK_EXPORTZP,
|
|
|
|
TOK_FARADDR,
|
2011-01-09 11:00:22 +00:00
|
|
|
TOK_FATAL,
|
2007-08-27 20:39:02 +00:00
|
|
|
TOK_FEATURE,
|
|
|
|
TOK_FILEOPT,
|
|
|
|
TOK_FORCEIMPORT,
|
|
|
|
TOK_FORCEWORD,
|
|
|
|
TOK_GLOBAL,
|
|
|
|
TOK_GLOBALZP,
|
|
|
|
TOK_HIBYTE,
|
2009-05-18 16:11:34 +00:00
|
|
|
TOK_HIBYTES,
|
2007-08-27 20:39:02 +00:00
|
|
|
TOK_HIWORD,
|
|
|
|
TOK_I16,
|
|
|
|
TOK_I8,
|
|
|
|
TOK_MAKEIDENT,
|
|
|
|
TOK_IF,
|
|
|
|
TOK_IFBLANK,
|
|
|
|
TOK_IFCONST,
|
|
|
|
TOK_IFDEF,
|
|
|
|
TOK_IFNBLANK,
|
|
|
|
TOK_IFNCONST,
|
|
|
|
TOK_IFNDEF,
|
|
|
|
TOK_IFNREF,
|
|
|
|
TOK_IFP02,
|
|
|
|
TOK_IFP816,
|
|
|
|
TOK_IFPC02,
|
|
|
|
TOK_IFPSC02,
|
|
|
|
TOK_IFREF,
|
|
|
|
TOK_IMPORT,
|
|
|
|
TOK_IMPORTZP,
|
|
|
|
TOK_INCBIN,
|
|
|
|
TOK_INCLUDE,
|
|
|
|
TOK_INTERRUPTOR,
|
2015-10-19 23:30:25 +00:00
|
|
|
TOK_ISIZE,
|
2015-05-19 23:50:51 +00:00
|
|
|
TOK_ISMNEMONIC,
|
2007-08-27 20:39:02 +00:00
|
|
|
TOK_LEFT,
|
|
|
|
TOK_LINECONT,
|
|
|
|
TOK_LIST,
|
|
|
|
TOK_LISTBYTES,
|
|
|
|
TOK_LOBYTE,
|
2009-05-18 16:11:34 +00:00
|
|
|
TOK_LOBYTES,
|
2007-08-27 20:39:02 +00:00
|
|
|
TOK_LOCAL,
|
|
|
|
TOK_LOCALCHAR,
|
|
|
|
TOK_LOWORD,
|
|
|
|
TOK_MACPACK,
|
|
|
|
TOK_MACRO,
|
|
|
|
TOK_MATCH,
|
2010-02-11 18:54:08 +00:00
|
|
|
TOK_MAX,
|
2007-08-27 20:39:02 +00:00
|
|
|
TOK_MID,
|
2010-02-11 18:54:08 +00:00
|
|
|
TOK_MIN,
|
2007-08-27 20:39:02 +00:00
|
|
|
TOK_NULL,
|
|
|
|
TOK_ORG,
|
|
|
|
TOK_OUT,
|
|
|
|
TOK_P02,
|
|
|
|
TOK_P816,
|
|
|
|
TOK_PAGELENGTH,
|
|
|
|
TOK_PARAMCOUNT,
|
|
|
|
TOK_PC02,
|
2010-04-18 18:47:16 +00:00
|
|
|
TOK_POPCPU,
|
2007-08-27 20:39:02 +00:00
|
|
|
TOK_POPSEG,
|
|
|
|
TOK_PROC,
|
2011-01-09 11:00:22 +00:00
|
|
|
TOK_PSC02,
|
2010-04-18 18:47:16 +00:00
|
|
|
TOK_PUSHCPU,
|
2007-08-27 20:39:02 +00:00
|
|
|
TOK_PUSHSEG,
|
|
|
|
TOK_REFERENCED,
|
|
|
|
TOK_RELOC,
|
|
|
|
TOK_REPEAT,
|
|
|
|
TOK_RES,
|
|
|
|
TOK_RIGHT,
|
|
|
|
TOK_RODATA,
|
|
|
|
TOK_SCOPE,
|
|
|
|
TOK_SEGMENT,
|
|
|
|
TOK_SET,
|
|
|
|
TOK_SETCPU,
|
|
|
|
TOK_SIZEOF,
|
|
|
|
TOK_SMART,
|
|
|
|
TOK_SPRINTF,
|
|
|
|
TOK_STRAT,
|
|
|
|
TOK_STRING,
|
|
|
|
TOK_STRLEN,
|
|
|
|
TOK_STRUCT,
|
|
|
|
TOK_TAG,
|
|
|
|
TOK_TCOUNT,
|
|
|
|
TOK_TIME,
|
2011-06-11 22:18:48 +00:00
|
|
|
TOK_UNDEF,
|
2007-08-27 20:39:02 +00:00
|
|
|
TOK_UNION,
|
|
|
|
TOK_VERSION,
|
|
|
|
TOK_WARNING,
|
|
|
|
TOK_WORD,
|
|
|
|
TOK_XMATCH,
|
|
|
|
TOK_ZEROPAGE,
|
2013-05-09 11:56:54 +00:00
|
|
|
TOK_LASTPSEUDO = TOK_ZEROPAGE,
|
2007-08-27 20:39:02 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
TOK_COUNT /* Count of tokens */
|
2011-01-16 14:51:13 +00:00
|
|
|
} token_t;
|
2007-08-27 20:39:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2011-01-16 16:05:43 +00:00
|
|
|
/* Complete token including attributes and flags */
|
|
|
|
typedef struct Token Token;
|
|
|
|
struct Token {
|
|
|
|
token_t Tok; /* The actual token value */
|
|
|
|
int WS; /* Flag for "whitespace before token" */
|
|
|
|
long IVal; /* Integer attribute value */
|
|
|
|
StrBuf SVal; /* String attribute value */
|
|
|
|
FilePos Pos; /* Position from which token was read */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Initializer value for a token */
|
|
|
|
#define STATIC_TOKEN_INITIALIZER { \
|
|
|
|
TOK_NONE, \
|
|
|
|
0, \
|
|
|
|
0, \
|
|
|
|
STATIC_STRBUF_INITIALIZER, \
|
|
|
|
STATIC_FILEPOS_INITIALIZER \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-08-27 20:39:02 +00:00
|
|
|
/*****************************************************************************/
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Code */
|
2007-08-27 20:39:02 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-01-16 14:51:13 +00:00
|
|
|
int TokHasSVal (token_t Tok);
|
2007-08-28 21:14:21 +00:00
|
|
|
/* Return true if the given token has an attached SVal */
|
|
|
|
|
2011-01-16 14:51:13 +00:00
|
|
|
int TokHasIVal (token_t Tok);
|
2007-08-28 21:14:21 +00:00
|
|
|
/* Return true if the given token has an attached IVal */
|
|
|
|
|
|
|
|
#if defined(HAVE_INLINE)
|
2011-01-16 14:51:13 +00:00
|
|
|
INLINE int TokIsSep (enum token_t T)
|
2007-08-28 21:14:21 +00:00
|
|
|
/* Return true if this is a separator token */
|
|
|
|
{
|
|
|
|
return (T == TOK_SEP || T == TOK_EOF);
|
|
|
|
}
|
|
|
|
#else
|
2011-01-16 14:19:58 +00:00
|
|
|
# define TokIsSep(T) ((T) == TOK_SEP || (T) == TOK_EOF)
|
2007-08-28 21:14:21 +00:00
|
|
|
#endif
|
|
|
|
|
2011-01-20 20:54:30 +00:00
|
|
|
void CopyToken (Token* Dst, const Token* Src);
|
|
|
|
/* Copy a token. The current value of Dst.SVal is free'd, so Dst must be
|
2014-06-30 09:10:35 +00:00
|
|
|
** initialized.
|
|
|
|
*/
|
2011-01-20 20:54:30 +00:00
|
|
|
|
2007-08-28 21:14:21 +00:00
|
|
|
|
|
|
|
|
2007-08-27 20:39:02 +00:00
|
|
|
/* End of token.h */
|
|
|
|
|
|
|
|
#endif
|