/*****************************************************************************/
/* */
-/* token.c */
+/* token.h */
/* */
/* Token list for the ca65 macro assembler */
/* */
/* */
/* */
-/* (C) 2007 Ullrich von Bassewitz */
-/* Roemerstrasse 52 */
-/* D-70794 Filderstadt */
-/* EMail: uz@cc65.org */
+/* (C) 2007-2011, Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
+/* common */
+#include "filepos.h"
+#include "inline.h"
+#include "strbuf.h"
+
+
+
/*****************************************************************************/
/* Data */
/*****************************************************************************/
/* Tokens */
-enum Token {
+typedef enum token_t {
TOK_NONE, /* Start value, invalid */
TOK_EOF, /* End of input file */
TOK_SEP, /* Separator (usually newline) */
TOK_ULABEL, /* :++ or :-- */
TOK_EQ, /* = */
- TOK_NE, /* <> */
+ TOK_NE, /* <> */
TOK_LT, /* < */
TOK_GT, /* > */
TOK_LE, /* <= */
TOK_BOOLNOT, /* .not */
TOK_PLUS, /* + */
- TOK_MINUS, /* - */
+ TOK_MINUS, /* - */
TOK_MUL, /* * */
TOK_STAR = TOK_MUL, /* Alias */
TOK_DIV, /* / */
TOK_MOD, /* ! */
- TOK_OR, /* | */
+ TOK_OR, /* | */
TOK_XOR, /* ^ */
TOK_BANK = TOK_XOR, /* Alias */
TOK_AND, /* & */
TOK_HASH, /* # */
TOK_COLON, /* : */
TOK_LPAREN, /* ( */
- TOK_RPAREN, /* ) */
+ TOK_RPAREN, /* ) */
TOK_LBRACK, /* [ */
TOK_RBRACK, /* ] */
TOK_LCURLY, /* { */
TOK_ASSERT,
TOK_AUTOIMPORT,
TOK_BANKBYTE,
+ TOK_BANKBYTES,
TOK_BLANK,
TOK_BSS,
TOK_BYTE,
TOK_DEBUGINFO,
TOK_DEFINE,
TOK_DEFINED,
+ TOK_DELMAC,
TOK_DESTRUCTOR,
TOK_DWORD,
TOK_ELSE,
TOK_EXPORT,
TOK_EXPORTZP,
TOK_FARADDR,
+ TOK_FATAL,
TOK_FEATURE,
TOK_FILEOPT,
TOK_FORCEIMPORT,
TOK_GLOBAL,
TOK_GLOBALZP,
TOK_HIBYTE,
+ TOK_HIBYTES,
TOK_HIWORD,
TOK_I16,
TOK_I8,
TOK_LIST,
TOK_LISTBYTES,
TOK_LOBYTE,
+ TOK_LOBYTES,
TOK_LOCAL,
TOK_LOCALCHAR,
TOK_LOWORD,
TOK_MACPACK,
TOK_MACRO,
TOK_MATCH,
+ TOK_MAX,
TOK_MID,
+ TOK_MIN,
TOK_NULL,
TOK_ORG,
TOK_OUT,
TOK_PAGELENGTH,
TOK_PARAMCOUNT,
TOK_PC02,
+ TOK_POPCPU,
TOK_POPSEG,
TOK_PROC,
TOK_PSC02,
+ TOK_PUSHCPU,
TOK_PUSHSEG,
TOK_REFERENCED,
TOK_RELOC,
TOK_TAG,
TOK_TCOUNT,
TOK_TIME,
+ TOK_UNDEF,
TOK_UNION,
TOK_VERSION,
TOK_WARNING,
TOK_LASTPSEUDO = TOK_ZEROPAGE,
TOK_COUNT /* Count of tokens */
+} token_t;
+
+
+
+/* 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 \
+}
+
/*****************************************************************************/
+int TokHasSVal (token_t Tok);
+/* Return true if the given token has an attached SVal */
+
+int TokHasIVal (token_t Tok);
+/* Return true if the given token has an attached IVal */
+
+#if defined(HAVE_INLINE)
+INLINE int TokIsSep (enum token_t 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
+
+void CopyToken (Token* Dst, const Token* Src);
+/* Copy a token. The current value of Dst.SVal is free'd, so Dst must be
+ * initialized.
+ */
+
+
+
/* End of token.h */
#endif