2001-05-22 09:32:24 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* */
|
2013-05-09 11:56:54 +00:00
|
|
|
/* scanner.h */
|
2001-05-22 09:32:24 +00:00
|
|
|
/* */
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Source file line info structure */
|
2001-05-22 09:32:24 +00:00
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* */
|
2010-04-09 19:47:33 +00:00
|
|
|
/* (C) 1998-2010, Ullrich von Bassewitz */
|
2009-09-18 14:28:52 +00:00
|
|
|
/* Roemerstrasse 52 */
|
|
|
|
/* D-70794 Filderstadt */
|
|
|
|
/* EMail: uz@cc65.org */
|
2001-05-22 09:32:24 +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. */
|
|
|
|
/* */
|
|
|
|
/*****************************************************************************/
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef SCANNER_H
|
|
|
|
#define SCANNER_H
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-08-11 17:51:00 +00:00
|
|
|
/* common */
|
|
|
|
#include "fp.h"
|
|
|
|
|
2001-05-22 09:32:24 +00:00
|
|
|
/* cc65 */
|
2000-05-28 13:40:48 +00:00
|
|
|
#include "datatype.h"
|
|
|
|
#include "ident.h"
|
2001-05-22 09:32:24 +00:00
|
|
|
#include "lineinfo.h"
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Token definitions */
|
2000-05-28 13:40:48 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-06-12 18:31:40 +00:00
|
|
|
typedef enum token_t {
|
2004-05-25 20:59:38 +00:00
|
|
|
TOK_INVALID,
|
2000-06-12 18:31:40 +00:00
|
|
|
TOK_CEOF,
|
|
|
|
|
2006-02-17 20:27:51 +00:00
|
|
|
/* Storage specifiers */
|
2006-02-19 15:53:11 +00:00
|
|
|
TOK_FIRST_STORAGE_CLASS,
|
|
|
|
TOK_AUTO = TOK_FIRST_STORAGE_CLASS,
|
2000-06-12 18:31:40 +00:00
|
|
|
TOK_EXTERN,
|
|
|
|
TOK_REGISTER,
|
|
|
|
TOK_STATIC,
|
|
|
|
TOK_TYPEDEF,
|
2006-02-19 15:53:11 +00:00
|
|
|
TOK_LAST_STORAGE_CLASS = TOK_TYPEDEF,
|
2004-05-26 16:15:28 +00:00
|
|
|
|
|
|
|
/* Tokens denoting type qualifiers */
|
|
|
|
TOK_FIRST_TYPEQUAL,
|
|
|
|
TOK_CONST = TOK_FIRST_TYPEQUAL,
|
2000-06-12 18:31:40 +00:00
|
|
|
TOK_VOLATILE,
|
2006-02-17 20:19:35 +00:00
|
|
|
TOK_RESTRICT,
|
|
|
|
TOK_LAST_TYPEQUAL = TOK_RESTRICT,
|
2000-06-12 18:31:40 +00:00
|
|
|
|
2006-02-17 20:27:51 +00:00
|
|
|
/* Function specifiers */
|
|
|
|
TOK_INLINE,
|
2006-02-19 15:53:11 +00:00
|
|
|
TOK_FASTCALL,
|
2010-04-09 19:47:33 +00:00
|
|
|
TOK_CDECL,
|
2006-02-17 20:27:51 +00:00
|
|
|
|
2022-08-06 10:45:49 +00:00
|
|
|
/* Address sizes */
|
|
|
|
TOK_FAR,
|
|
|
|
TOK_NEAR,
|
|
|
|
|
2000-06-12 18:31:40 +00:00
|
|
|
/* Tokens denoting types */
|
2004-05-26 16:15:28 +00:00
|
|
|
TOK_FIRST_TYPE,
|
2013-05-09 11:56:54 +00:00
|
|
|
TOK_ENUM = TOK_FIRST_TYPE,
|
2003-08-01 21:29:42 +00:00
|
|
|
TOK_CHAR,
|
2000-06-12 18:31:40 +00:00
|
|
|
TOK_INT,
|
|
|
|
TOK_DOUBLE,
|
|
|
|
TOK_FLOAT,
|
|
|
|
TOK_LONG,
|
|
|
|
TOK_UNSIGNED,
|
|
|
|
TOK_SIGNED,
|
|
|
|
TOK_SHORT,
|
|
|
|
TOK_STRUCT,
|
|
|
|
TOK_UNION,
|
|
|
|
TOK_VOID,
|
2004-05-26 16:15:28 +00:00
|
|
|
TOK_LAST_TYPE = TOK_VOID,
|
2000-06-12 18:31:40 +00:00
|
|
|
|
2022-08-06 10:45:49 +00:00
|
|
|
/* Selection statements */
|
|
|
|
TOK_IF,
|
|
|
|
TOK_ELSE,
|
|
|
|
TOK_SWITCH,
|
|
|
|
|
|
|
|
/* Iteration statements */
|
|
|
|
TOK_WHILE,
|
2000-06-12 18:31:40 +00:00
|
|
|
TOK_DO,
|
|
|
|
TOK_FOR,
|
2022-08-06 10:45:49 +00:00
|
|
|
|
|
|
|
/* Jump statements */
|
2000-06-12 18:31:40 +00:00
|
|
|
TOK_GOTO,
|
2022-08-06 10:45:49 +00:00
|
|
|
TOK_CONTINUE,
|
|
|
|
TOK_BREAK,
|
2000-06-12 18:31:40 +00:00
|
|
|
TOK_RETURN,
|
|
|
|
|
2022-08-06 10:45:49 +00:00
|
|
|
/* Labels */
|
2000-06-12 18:31:40 +00:00
|
|
|
TOK_CASE,
|
|
|
|
TOK_DEFAULT,
|
|
|
|
|
2022-08-06 10:45:49 +00:00
|
|
|
/* Misc. */
|
|
|
|
TOK_ATTRIBUTE,
|
|
|
|
TOK_PRAGMA,
|
|
|
|
TOK_STATIC_ASSERT,
|
|
|
|
TOK_ASM,
|
|
|
|
TOK_SIZEOF,
|
2000-06-12 18:31:40 +00:00
|
|
|
|
2022-08-06 10:45:49 +00:00
|
|
|
/* Punctuators */
|
|
|
|
TOK_FIRST_PUNC,
|
|
|
|
TOK_LBRACK = TOK_FIRST_PUNC,
|
|
|
|
TOK_RBRACK,
|
2000-06-12 18:31:40 +00:00
|
|
|
TOK_LPAREN,
|
2022-08-06 10:45:49 +00:00
|
|
|
TOK_RPAREN,
|
|
|
|
TOK_LCURLY,
|
|
|
|
TOK_RCURLY,
|
2000-06-12 18:31:40 +00:00
|
|
|
TOK_DOT,
|
|
|
|
TOK_PTR_REF,
|
|
|
|
TOK_INC,
|
|
|
|
TOK_DEC,
|
2022-08-06 10:45:49 +00:00
|
|
|
TOK_ADDR,
|
|
|
|
TOK_AND = TOK_ADDR, /* Alias */
|
2000-06-12 18:31:40 +00:00
|
|
|
TOK_STAR,
|
2013-05-09 11:56:54 +00:00
|
|
|
TOK_MUL = TOK_STAR, /* Alias */
|
2022-08-06 10:45:49 +00:00
|
|
|
TOK_PLUS,
|
|
|
|
TOK_MINUS,
|
|
|
|
TOK_COMP,
|
|
|
|
TOK_BOOL_NOT,
|
2000-06-12 18:31:40 +00:00
|
|
|
TOK_DIV,
|
2022-08-06 10:45:49 +00:00
|
|
|
TOK_MOD,
|
|
|
|
TOK_SHL,
|
|
|
|
TOK_SHR,
|
|
|
|
TOK_LT,
|
|
|
|
TOK_GT,
|
|
|
|
TOK_LE,
|
|
|
|
TOK_GE,
|
|
|
|
TOK_EQ,
|
2000-06-12 18:31:40 +00:00
|
|
|
TOK_NE,
|
2022-08-06 10:45:49 +00:00
|
|
|
TOK_XOR,
|
2000-06-12 18:31:40 +00:00
|
|
|
TOK_OR,
|
2022-08-06 10:45:49 +00:00
|
|
|
TOK_BOOL_AND,
|
|
|
|
TOK_BOOL_OR,
|
|
|
|
TOK_QUEST,
|
|
|
|
TOK_COLON,
|
|
|
|
TOK_SEMI,
|
|
|
|
TOK_ELLIPSIS,
|
2000-06-12 18:31:40 +00:00
|
|
|
TOK_ASSIGN,
|
2022-08-06 10:45:49 +00:00
|
|
|
TOK_MUL_ASSIGN,
|
|
|
|
TOK_DIV_ASSIGN,
|
|
|
|
TOK_MOD_ASSIGN,
|
|
|
|
TOK_PLUS_ASSIGN,
|
|
|
|
TOK_MINUS_ASSIGN,
|
2000-08-20 19:12:43 +00:00
|
|
|
TOK_SHL_ASSIGN,
|
2000-06-12 18:31:40 +00:00
|
|
|
TOK_SHR_ASSIGN,
|
2022-08-06 10:45:49 +00:00
|
|
|
TOK_AND_ASSIGN,
|
2000-06-12 18:31:40 +00:00
|
|
|
TOK_XOR_ASSIGN,
|
2022-08-06 10:45:49 +00:00
|
|
|
TOK_OR_ASSIGN,
|
|
|
|
TOK_COMMA,
|
|
|
|
TOK_HASH,
|
|
|
|
TOK_HASH_HASH,
|
|
|
|
TOK_DOUBLE_HASH = TOK_HASH_HASH, /* Alias */
|
|
|
|
TOK_LAST_PUNC = TOK_DOUBLE_HASH,
|
|
|
|
|
|
|
|
/* Primary expressions */
|
2000-06-12 18:31:40 +00:00
|
|
|
TOK_SCONST,
|
|
|
|
TOK_ICONST,
|
|
|
|
TOK_CCONST,
|
|
|
|
TOK_FCONST,
|
2009-09-18 14:28:52 +00:00
|
|
|
TOK_WCSCONST,
|
2022-08-06 10:45:49 +00:00
|
|
|
TOK_IDENT,
|
2000-08-16 09:10:50 +00:00
|
|
|
TOK_A,
|
|
|
|
TOK_X,
|
2000-08-19 21:55:06 +00:00
|
|
|
TOK_Y,
|
2000-06-12 18:31:40 +00:00
|
|
|
TOK_AX,
|
2022-08-06 10:45:49 +00:00
|
|
|
TOK_EAX
|
2000-06-12 18:31:40 +00:00
|
|
|
} token_t;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Data */
|
2000-05-28 13:40:48 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-12-05 22:39:45 +00:00
|
|
|
/* Forward for struct Literal */
|
|
|
|
struct Literal;
|
|
|
|
|
2010-04-09 19:47:33 +00:00
|
|
|
/* Token stuff */
|
2001-05-22 09:32:24 +00:00
|
|
|
typedef struct Token Token;
|
|
|
|
struct Token {
|
2013-05-09 11:56:54 +00:00
|
|
|
token_t Tok; /* The token itself */
|
|
|
|
long IVal; /* The integer attribute */
|
|
|
|
Double FVal; /* The float attribute */
|
2009-12-05 22:39:45 +00:00
|
|
|
struct Literal* SVal; /* String literal is any */
|
2013-05-09 11:56:54 +00:00
|
|
|
ident Ident; /* Identifier if IDENT */
|
|
|
|
LineInfo* LI; /* Source line where the token comes from */
|
2021-04-05 08:40:32 +00:00
|
|
|
const Type* Type; /* Type if integer or float constant */
|
2000-05-28 13:40:48 +00:00
|
|
|
};
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
extern Token CurTok; /* The current token */
|
|
|
|
extern Token NextTok; /* The next token */
|
2022-08-05 06:03:51 +00:00
|
|
|
extern int NextLineDisabled; /* Disabled to read next line */
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Code */
|
2000-05-28 13:40:48 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-08-06 10:45:49 +00:00
|
|
|
#if defined(HAVE_INLINE)
|
|
|
|
INLINE int TokIsPunc (const Token* T)
|
|
|
|
/* Return true if the token is a punctuator */
|
|
|
|
{
|
|
|
|
return (T->Tok >= TOK_FIRST_PUNC && T->Tok <= TOK_LAST_PUNC);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
# define TokIsPunc(T) \
|
|
|
|
((T)->Tok >= TOK_FIRST_PUNC && (T)->Tok <= TOK_LAST_PUNC)
|
|
|
|
#endif
|
|
|
|
|
2006-02-19 15:53:11 +00:00
|
|
|
#if defined(HAVE_INLINE)
|
|
|
|
INLINE int TokIsStorageClass (const Token* T)
|
|
|
|
/* Return true if the token is a storage class specifier */
|
|
|
|
{
|
|
|
|
return (T->Tok >= TOK_FIRST_STORAGE_CLASS && T->Tok <= TOK_LAST_STORAGE_CLASS);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
# define TokIsStorageClass(T) \
|
|
|
|
((T)->Tok >= TOK_FIRST_STORAGE_CLASS && (T)->Tok <= TOK_LAST_STORAGE_CLASS)
|
|
|
|
#endif
|
|
|
|
|
2004-05-26 16:15:28 +00:00
|
|
|
#if defined(HAVE_INLINE)
|
|
|
|
INLINE int TokIsType (const Token* T)
|
|
|
|
/* Return true if the token is a type */
|
|
|
|
{
|
|
|
|
return (T->Tok >= TOK_FIRST_TYPE && T->Tok <= TOK_LAST_TYPE);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
# define TokIsType(T) ((T)->Tok >= TOK_FIRST_TYPE && (T)->Tok <= TOK_LAST_TYPE)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HAVE_INLINE)
|
|
|
|
INLINE int TokIsTypeQual (const Token* T)
|
|
|
|
/* Return true if the token is a type qualifier */
|
|
|
|
{
|
|
|
|
return (T->Tok >= TOK_FIRST_TYPEQUAL && T->Tok <= TOK_LAST_TYPEQUAL);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
# define TokIsTypeQual(T) ((T)->Tok >= TOK_FIRST_TYPEQUAL && (T)->Tok <= TOK_LAST_TYPEQUAL)
|
|
|
|
#endif
|
|
|
|
|
2006-02-19 15:53:11 +00:00
|
|
|
int TokIsFuncSpec (const Token* T);
|
|
|
|
/* Return true if the token is a function specifier */
|
|
|
|
|
2004-09-16 12:42:41 +00:00
|
|
|
void SymName (char* S);
|
|
|
|
/* Read a symbol from the input stream. The first character must have been
|
2014-06-30 09:10:35 +00:00
|
|
|
** checked before calling this function. The buffer is expected to be at
|
|
|
|
** least of size MAX_IDENTLEN+1.
|
|
|
|
*/
|
2004-09-16 12:42:41 +00:00
|
|
|
|
|
|
|
int IsSym (char* S);
|
|
|
|
/* If a symbol follows, read it and return 1, otherwise return 0 */
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-06-21 21:02:44 +00:00
|
|
|
void NextToken (void);
|
2000-05-28 13:40:48 +00:00
|
|
|
/* Get next token from input stream */
|
|
|
|
|
2001-09-09 20:49:20 +00:00
|
|
|
void SkipTokens (const token_t* TokenList, unsigned TokenCount);
|
|
|
|
/* Skip tokens until we reach TOK_CEOF or a token in the given token list.
|
2014-06-30 09:10:35 +00:00
|
|
|
** This routine is used for error recovery.
|
|
|
|
*/
|
2001-09-09 20:49:20 +00:00
|
|
|
|
2002-09-29 21:09:47 +00:00
|
|
|
int Consume (token_t Token, const char* ErrorMsg);
|
2000-05-28 13:40:48 +00:00
|
|
|
/* Eat token if it is the next in the input stream, otherwise print an error
|
2014-06-30 09:10:35 +00:00
|
|
|
** message. Returns true if the token was found and false otherwise.
|
|
|
|
*/
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2002-09-29 21:09:47 +00:00
|
|
|
int ConsumeColon (void);
|
2000-05-28 13:40:48 +00:00
|
|
|
/* Check for a colon and skip it. */
|
|
|
|
|
2002-09-29 21:09:47 +00:00
|
|
|
int ConsumeSemi (void);
|
2000-05-28 13:40:48 +00:00
|
|
|
/* Check for a semicolon and skip it. */
|
|
|
|
|
2002-09-29 21:09:47 +00:00
|
|
|
int ConsumeComma (void);
|
2000-09-14 19:26:13 +00:00
|
|
|
/* Check for a comma and skip it. */
|
|
|
|
|
2002-09-29 21:09:47 +00:00
|
|
|
int ConsumeLParen (void);
|
2000-05-28 13:40:48 +00:00
|
|
|
/* Check for a left parenthesis and skip it */
|
|
|
|
|
2002-09-29 21:09:47 +00:00
|
|
|
int ConsumeRParen (void);
|
2000-05-28 13:40:48 +00:00
|
|
|
/* Check for a right parenthesis and skip it */
|
|
|
|
|
2002-09-29 21:09:47 +00:00
|
|
|
int ConsumeLBrack (void);
|
2000-05-28 13:40:48 +00:00
|
|
|
/* Check for a left bracket and skip it */
|
|
|
|
|
2002-09-29 21:09:47 +00:00
|
|
|
int ConsumeRBrack (void);
|
2000-05-28 13:40:48 +00:00
|
|
|
/* Check for a right bracket and skip it */
|
|
|
|
|
2002-09-29 21:09:47 +00:00
|
|
|
int ConsumeLCurly (void);
|
2000-05-28 13:40:48 +00:00
|
|
|
/* Check for a left curly brace and skip it */
|
|
|
|
|
2002-09-29 21:09:47 +00:00
|
|
|
int ConsumeRCurly (void);
|
2000-05-28 13:40:48 +00:00
|
|
|
/* Check for a right curly brace and skip it */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* End of scanner.h */
|
|
|
|
|
2014-03-04 00:11:19 +00:00
|
|
|
#endif
|