/* We have a list of tokens that ends with the closing paren. Skip
* the tokens, and count them. Allow optionally curly braces.
*/
- enum Token Term = GetTokListTerm (TOK_RPAREN);
+ Token Term = GetTokListTerm (TOK_RPAREN);
unsigned Count = 0;
while (Tok != Term) {
* single linked list of tokens including attributes. The list is
* either enclosed in curly braces, or terminated by a comma.
*/
- enum Token Term = GetTokListTerm (TOK_COMMA);
+ Token Term = GetTokListTerm (TOK_COMMA);
while (Tok != Term) {
/* We may not end-of-line of end-of-file here */
/* We have a list of tokens that ends with the closing paren. Skip
* the tokens, and count them. Allow optionally curly braces.
*/
- enum Token Term = GetTokListTerm (TOK_RPAREN);
+ Token Term = GetTokListTerm (TOK_RPAREN);
int Count = 0;
while (Tok != Term) {
ExprNode* Right;
/* Remember the token and skip it */
- enum Token T = Tok;
+ Token T = Tok;
NextTok ();
/* Move root to left side and read the right side */
ExprNode* Right;
/* Remember the token and skip it */
- enum Token T = Tok;
+ Token T = Tok;
NextTok ();
/* Move root to left side and read the right side */
ExprNode* Right;
/* Remember the token and skip it */
- enum Token T = Tok;
+ Token T = Tok;
NextTok ();
/* Move root to left side and read the right side */
ExprNode* Right;
/* Remember the token and skip it */
- enum Token T = Tok;
+ Token T = Tok;
NextTok ();
/* Move root to left side and read the right side */
ExprNode* Right;
/* Remember the token and skip it */
- enum Token T = Tok;
+ Token T = Tok;
NextTok ();
/* Move root to left side and read the right side */
/* */
/* */
/* */
-/* (C) 1998-2004 Ullrich von Bassewitz */
-/* Römerstraße 52 */
+/* (C) 1998-2007 Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* Start expanding the classic macro M */
{
MacExp* E;
- enum Token Term;
+ Token Term;
/* Skip the macro name */
TokNode* Last;
/* The macro may optionally be enclosed in curly braces */
- enum Token Term = GetTokListTerm (TOK_COMMA);
+ Token Term = GetTokListTerm (TOK_COMMA);
/* Check if there is really a parameter */
if (TokIsSep (Tok) || Tok == Term) {
symentry.o \
symbol.o \
symtab.o \
+ token.o \
toklist.o \
ulabel.o
symbol.obj \
symentry.obj \
symtab.obj \
+ token.obj \
toklist.obj \
ulabel.obj
/* */
/* */
/* */
-/* (C) 2000-2004 Ullrich von Bassewitz */
-/* Römerstraße 52 */
+/* (C) 2000-2007 Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
TokList* List = NewTokList ();
/* Determine if the list is enclosed in curly braces. */
- enum Token Term = GetTokListTerm (TOK_RPAREN);
+ Token Term = GetTokListTerm (TOK_RPAREN);
/* Read the token list */
unsigned Current = 0;
static void FuncIdent (void)
/* Handle the .IDENT function */
{
- char Buf[sizeof(SVal)];
- enum Token Id;
- unsigned Len;
- unsigned I;
+ char Buf[sizeof(SVal)];
+ Token Id;
+ unsigned Len;
+ unsigned I;
/* Skip it */
NextTok ();
/* Left paren expected */
ConsumeLParen ();
- /* Start argument. Since the start argument can get negative with
+ /* Start argument. Since the start argument can get negative with
* expressions like ".tcount(arg)-2", we correct it to zero silently.
*/
Start = ConstExpression ();
-void Consume (enum Token Expected, const char* ErrMsg)
+void Consume (Token Expected, const char* ErrMsg)
/* Consume Expected, print an error if we don't find it */
{
if (Tok == Expected) {
/* */
/* */
/* */
-/* (C) 2000-2004 Ullrich von Bassewitz */
-/* Römerstraße 52 */
+/* (C) 2000-2007 Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
void NextTok (void);
/* Get next token and handle token level functions */
-void Consume (enum Token Expected, const char* ErrMsg);
+void Consume (Token Expected, const char* ErrMsg);
/* Consume Token, print an error if we don't find it */
void ConsumeSep (void);
-enum Token Tok = TOK_NONE; /* Current token */
+Token Tok = TOK_NONE; /* Current token */
int WS; /* Flag: Whitespace before token */
long IVal; /* Integer token attribute */
char SVal[MAX_STR_LEN+1]; /* String token attribute */
struct InputFile {
FILE* F; /* Input file descriptor */
FilePos Pos; /* Position in file */
- enum Token Tok; /* Last token */
+ Token Tok; /* Last token */
int C; /* Last character */
char Line[256]; /* The current input line */
InputFile* Next; /* Linked list of input files */
char* Text; /* Pointer to the text data */
const char* Pos; /* Pointer to current position */
int Malloced; /* Memory was malloced */
- enum Token Tok; /* Last token */
+ Token Tok; /* Last token */
int C; /* Last character */
InputData* Next; /* Linked list of input data */
};
/* Input source: Either file or data */
struct CharSource {
CharSource* Next; /* Linked list of char sources */
- enum Token Tok; /* Last token */
+ Token Tok; /* Last token */
int C; /* Last character */
const CharSourceFunctions* Func; /* Pointer to function table */
union {
/* List of dot keywords with the corresponding tokens */
struct DotKeyword {
const char* Key; /* MUST be first field */
- enum Token Tok;
+ Token Tok;
} DotKeywords [] = {
{ ".A16", TOK_A16 },
{ ".A8", TOK_A8 },
}
}
- /* Read the number */
+ /* Read the number */
IVal = 0;
while (IsXDigit (C)) {
if (IVal & 0xF0000000) {
Error ("Binary digit expected");
}
- /* Read the number */
+ /* Read the number */
IVal = 0;
while (IsBDigit (C)) {
if (IVal & 0x80000000) {
/* This is an integer constant */
Tok = TOK_INTCON;
- return;
+ return;
}
/* Control command? */
Tok = FindDotKeyword ();
if (Tok == TOK_NONE) {
- /* Not found */
+ /* Not found */
if (!LeadingDotInIdents) {
/* Invalid pseudo instruction */
Error ("`%s' is not a recognized control command", SVal);
}
break;
- default:
+ default:
break;
}
case '^':
NextChar ();
- Tok = TOK_XOR;
+ Tok = TOK_XOR;
return;
case '&':
case ':':
NextChar ();
- switch (C) {
+ switch (C) {
case ':':
NextChar ();
case '#':
NextChar ();
- Tok = TOK_HASH;
+ Tok = TOK_HASH;
return;
case '(':
case '{':
NextChar ();
- Tok = TOK_LCURLY;
+ Tok = TOK_LCURLY;
return;
case '}':
return;
case '=':
- NextChar ();
+ NextChar ();
Tok = TOK_EQ;
return;
case '~':
NextChar ();
Tok = TOK_NOT;
- return;
+ return;
case '\'':
/* Hack: If we allow ' as terminating character for strings, read
goto Again;
}
}
- break;
+ break;
case '\n':
NextChar ();
-int TokHasSVal (enum Token Tok)
-/* Return true if the given token has an attached SVal */
-{
- return (Tok == TOK_IDENT || TOK_LOCAL_IDENT || Tok == TOK_STRCON);
-}
-
-
-
-int TokHasIVal (enum Token Tok)
-/* Return true if the given token has an attached IVal */
-{
- return (Tok == TOK_INTCON || Tok == TOK_CHARCON || Tok == TOK_REG);
-}
-
-
-
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
/* common */
#include "filepos.h"
-#include "inline.h"
/* ca65 */
#include "token.h"
/* 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 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 */
void NextRawTok (void);
/* Read the next raw token from the input stream */
-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 */
-
-#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
-
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
+
--- /dev/null
+/*****************************************************************************/
+/* */
+/* token.c */
+/* */
+/* Token list for the ca65 macro assembler */
+/* */
+/* */
+/* */
+/* (C) 2007 Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
+/* */
+/* */
+/* 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. */
+/* */
+/*****************************************************************************/
+
+
+
+/* ca65 */
+#include "token.h"
+
+
+
+/*****************************************************************************/
+/* Code */
+/*****************************************************************************/
+
+
+
+int TokHasSVal (Token Tok)
+/* Return true if the given token has an attached SVal */
+{
+ return (Tok == TOK_IDENT || TOK_LOCAL_IDENT || Tok == TOK_STRCON);
+}
+
+
+
+int TokHasIVal (Token Tok)
+/* Return true if the given token has an attached IVal */
+{
+ return (Tok == TOK_INTCON || Tok == TOK_CHARCON || Tok == TOK_REG);
+}
+
+
+
/*****************************************************************************/
/* */
-/* token.c */
+/* token.h */
/* */
/* Token list for the ca65 macro assembler */
/* */
+/* common */
+#include "inline.h"
+
+
+
/*****************************************************************************/
/* Data */
/*****************************************************************************/
/* Tokens */
-enum Token {
+typedef enum Token {
TOK_NONE, /* Start value, invalid */
TOK_EOF, /* End of input file */
TOK_SEP, /* Separator (usually newline) */
TOK_HASH, /* # */
TOK_COLON, /* : */
TOK_LPAREN, /* ( */
- TOK_RPAREN, /* ) */
+ TOK_RPAREN, /* ) */
TOK_LBRACK, /* [ */
TOK_RBRACK, /* ] */
TOK_LCURLY, /* { */
TOK_LASTPSEUDO = TOK_ZEROPAGE,
TOK_COUNT /* Count of tokens */
-};
+} Token;
+int TokHasSVal (Token Tok);
+/* Return true if the given token has an attached SVal */
+
+int TokHasIVal (Token Tok);
+/* Return true if the given token has an attached IVal */
+
+#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
+
+
+
/* End of token.h */
#endif
/* */
/* */
/* */
-/* (C) 2000-2004 Ullrich von Bassewitz */
-/* Römerstraße 52 */
+/* (C) 2000-2007 Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
typedef struct TokNode TokNode;
struct TokNode {
TokNode* Next; /* For single linked list */
- enum Token Tok; /* Token value */
+ Token Tok; /* Token value */
int WS; /* Whitespace before token? */
long IVal; /* Integer token attribute */
char SVal [1]; /* String attribute, dyn. allocated */
void FreeTokList (TokList* T);
/* Delete the token list including all token nodes */
-enum Token GetTokListTerm (enum Token Term);
+Token GetTokListTerm (Token Term);
/* Determine if the following token list is enclosed in curly braces. This is
* the case if the next token is the opening brace. If so, skip it and return
* a closing brace, otherwise return Term.