mirror of
https://github.com/cc65/cc65.git
synced 2024-12-28 06:30:16 +00:00
Move more stuff from scanner.c into the new module token.c.
git-svn-id: svn://svn.cc65.org/cc65/trunk@3801 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
aa4df9f98b
commit
3894b074a6
@ -333,7 +333,7 @@ static ExprNode* FuncBlank (void)
|
||||
/* 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) {
|
||||
|
||||
@ -437,7 +437,7 @@ static ExprNode* DoMatch (enum TC EqualityLevel)
|
||||
* 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 */
|
||||
@ -717,7 +717,7 @@ static ExprNode* FuncTCount (void)
|
||||
/* 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) {
|
||||
|
||||
@ -978,7 +978,7 @@ static ExprNode* Term (void)
|
||||
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 */
|
||||
@ -1079,7 +1079,7 @@ static ExprNode* SimpleExpr (void)
|
||||
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 */
|
||||
@ -1141,7 +1141,7 @@ static ExprNode* BoolExpr (void)
|
||||
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 */
|
||||
@ -1208,7 +1208,7 @@ static ExprNode* Expr2 (void)
|
||||
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 */
|
||||
@ -1267,7 +1267,7 @@ static ExprNode* Expr1 (void)
|
||||
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 */
|
||||
|
@ -6,8 +6,8 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (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 */
|
||||
/* */
|
||||
@ -662,7 +662,7 @@ static void StartExpClassic (Macro* M)
|
||||
/* Start expanding the classic macro M */
|
||||
{
|
||||
MacExp* E;
|
||||
enum Token Term;
|
||||
Token Term;
|
||||
|
||||
|
||||
/* Skip the macro name */
|
||||
@ -764,7 +764,7 @@ static void StartExpDefine (Macro* M)
|
||||
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) {
|
||||
|
@ -53,6 +53,7 @@ OBJS = anonname.o \
|
||||
symentry.o \
|
||||
symbol.o \
|
||||
symtab.o \
|
||||
token.o \
|
||||
toklist.o \
|
||||
ulabel.o
|
||||
|
||||
|
@ -97,6 +97,7 @@ OBJS = anonname.obj \
|
||||
symbol.obj \
|
||||
symentry.obj \
|
||||
symtab.obj \
|
||||
token.obj \
|
||||
toklist.obj \
|
||||
ulabel.obj
|
||||
|
||||
|
@ -6,8 +6,8 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (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 */
|
||||
/* */
|
||||
@ -102,7 +102,7 @@ static TokList* CollectTokens (unsigned Start, unsigned Count)
|
||||
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;
|
||||
@ -218,10 +218,10 @@ static void NoIdent (void)
|
||||
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 ();
|
||||
@ -337,7 +337,7 @@ static void FuncMid (void)
|
||||
/* 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 ();
|
||||
@ -726,7 +726,7 @@ void NextTok (void)
|
||||
|
||||
|
||||
|
||||
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) {
|
||||
|
@ -6,8 +6,8 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (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 */
|
||||
/* */
|
||||
@ -51,7 +51,7 @@
|
||||
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);
|
||||
|
@ -70,7 +70,7 @@
|
||||
|
||||
|
||||
|
||||
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 */
|
||||
@ -84,7 +84,7 @@ typedef struct InputFile InputFile;
|
||||
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 */
|
||||
@ -96,7 +96,7 @@ struct InputData {
|
||||
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 */
|
||||
};
|
||||
@ -115,7 +115,7 @@ struct CharSourceFunctions {
|
||||
/* 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 {
|
||||
@ -135,7 +135,7 @@ int ForcedEnd = 0;
|
||||
/* 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 },
|
||||
@ -810,7 +810,7 @@ Again:
|
||||
}
|
||||
}
|
||||
|
||||
/* Read the number */
|
||||
/* Read the number */
|
||||
IVal = 0;
|
||||
while (IsXDigit (C)) {
|
||||
if (IVal & 0xF0000000) {
|
||||
@ -835,7 +835,7 @@ Again:
|
||||
Error ("Binary digit expected");
|
||||
}
|
||||
|
||||
/* Read the number */
|
||||
/* Read the number */
|
||||
IVal = 0;
|
||||
while (IsBDigit (C)) {
|
||||
if (IVal & 0x80000000) {
|
||||
@ -910,7 +910,7 @@ Again:
|
||||
|
||||
/* This is an integer constant */
|
||||
Tok = TOK_INTCON;
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Control command? */
|
||||
@ -935,7 +935,7 @@ Again:
|
||||
Tok = FindDotKeyword ();
|
||||
if (Tok == TOK_NONE) {
|
||||
|
||||
/* Not found */
|
||||
/* Not found */
|
||||
if (!LeadingDotInIdents) {
|
||||
/* Invalid pseudo instruction */
|
||||
Error ("`%s' is not a recognized control command", SVal);
|
||||
@ -1035,7 +1035,7 @@ Again:
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1085,7 +1085,7 @@ CharAgain:
|
||||
|
||||
case '^':
|
||||
NextChar ();
|
||||
Tok = TOK_XOR;
|
||||
Tok = TOK_XOR;
|
||||
return;
|
||||
|
||||
case '&':
|
||||
@ -1110,7 +1110,7 @@ CharAgain:
|
||||
|
||||
case ':':
|
||||
NextChar ();
|
||||
switch (C) {
|
||||
switch (C) {
|
||||
|
||||
case ':':
|
||||
NextChar ();
|
||||
@ -1160,7 +1160,7 @@ CharAgain:
|
||||
|
||||
case '#':
|
||||
NextChar ();
|
||||
Tok = TOK_HASH;
|
||||
Tok = TOK_HASH;
|
||||
return;
|
||||
|
||||
case '(':
|
||||
@ -1185,7 +1185,7 @@ CharAgain:
|
||||
|
||||
case '{':
|
||||
NextChar ();
|
||||
Tok = TOK_LCURLY;
|
||||
Tok = TOK_LCURLY;
|
||||
return;
|
||||
|
||||
case '}':
|
||||
@ -1210,7 +1210,7 @@ CharAgain:
|
||||
return;
|
||||
|
||||
case '=':
|
||||
NextChar ();
|
||||
NextChar ();
|
||||
Tok = TOK_EQ;
|
||||
return;
|
||||
|
||||
@ -1235,7 +1235,7 @@ CharAgain:
|
||||
case '~':
|
||||
NextChar ();
|
||||
Tok = TOK_NOT;
|
||||
return;
|
||||
return;
|
||||
|
||||
case '\'':
|
||||
/* Hack: If we allow ' as terminating character for strings, read
|
||||
@ -1285,7 +1285,7 @@ CharAgain:
|
||||
goto Again;
|
||||
}
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
case '\n':
|
||||
NextChar ();
|
||||
@ -1314,22 +1314,6 @@ CharAgain:
|
||||
|
||||
|
||||
|
||||
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
|
||||
|
@ -40,7 +40,6 @@
|
||||
|
||||
/* common */
|
||||
#include "filepos.h"
|
||||
#include "inline.h"
|
||||
|
||||
/* ca65 */
|
||||
#include "token.h"
|
||||
@ -56,7 +55,7 @@
|
||||
/* 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 */
|
||||
@ -93,22 +92,6 @@ void UpcaseSVal (void);
|
||||
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
|
||||
@ -136,3 +119,4 @@ void DoneScanner (void);
|
||||
|
||||
|
||||
|
||||
|
||||
|
62
src/ca65/token.c
Normal file
62
src/ca65/token.c
Normal file
@ -0,0 +1,62 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* 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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* token.c */
|
||||
/* token.h */
|
||||
/* */
|
||||
/* Token list for the ca65 macro assembler */
|
||||
/* */
|
||||
@ -38,6 +38,11 @@
|
||||
|
||||
|
||||
|
||||
/* common */
|
||||
#include "inline.h"
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
@ -45,7 +50,7 @@
|
||||
|
||||
|
||||
/* Tokens */
|
||||
enum Token {
|
||||
typedef enum Token {
|
||||
TOK_NONE, /* Start value, invalid */
|
||||
TOK_EOF, /* End of input file */
|
||||
TOK_SEP, /* Separator (usually newline) */
|
||||
@ -98,7 +103,7 @@ enum Token {
|
||||
TOK_HASH, /* # */
|
||||
TOK_COLON, /* : */
|
||||
TOK_LPAREN, /* ( */
|
||||
TOK_RPAREN, /* ) */
|
||||
TOK_RPAREN, /* ) */
|
||||
TOK_LBRACK, /* [ */
|
||||
TOK_RBRACK, /* ] */
|
||||
TOK_LCURLY, /* { */
|
||||
@ -241,7 +246,7 @@ enum Token {
|
||||
TOK_LASTPSEUDO = TOK_ZEROPAGE,
|
||||
|
||||
TOK_COUNT /* Count of tokens */
|
||||
};
|
||||
} Token;
|
||||
|
||||
|
||||
|
||||
@ -251,6 +256,24 @@ enum 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
|
||||
|
@ -6,8 +6,8 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (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 */
|
||||
/* */
|
||||
@ -52,7 +52,7 @@
|
||||
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 */
|
||||
@ -109,7 +109,7 @@ TokList* NewTokList (void);
|
||||
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.
|
||||
|
Loading…
Reference in New Issue
Block a user