2001-05-22 09:32:24 +00:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* */
|
|
|
|
|
/* scanner.h */
|
|
|
|
|
/* */
|
|
|
|
|
/* Source file line info structure */
|
|
|
|
|
/* */
|
|
|
|
|
/* */
|
|
|
|
|
/* */
|
2003-05-07 21:06:42 +00:00
|
|
|
|
/* (C) 1998-2003 Ullrich von Bassewitz */
|
|
|
|
|
/* R<>merstrasse 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2000-06-12 18:31:40 +00:00
|
|
|
|
/* Token definitions */
|
2000-05-28 13:40:48 +00:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-06-12 18:31:40 +00:00
|
|
|
|
typedef enum token_t {
|
|
|
|
|
TOK_CEOF,
|
|
|
|
|
|
|
|
|
|
TOK_AUTO,
|
|
|
|
|
TOK_EXTERN,
|
|
|
|
|
TOK_REGISTER,
|
2003-05-07 21:06:42 +00:00
|
|
|
|
TOK_RESTRICT,
|
2000-06-12 18:31:40 +00:00
|
|
|
|
TOK_STATIC,
|
|
|
|
|
TOK_TYPEDEF,
|
|
|
|
|
TOK_CONST,
|
|
|
|
|
TOK_VOLATILE,
|
|
|
|
|
|
|
|
|
|
/* Tokens denoting types */
|
|
|
|
|
TOK_FIRSTTYPE,
|
2003-08-01 21:29:42 +00:00
|
|
|
|
TOK_ENUM = TOK_FIRSTTYPE,
|
|
|
|
|
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,
|
|
|
|
|
TOK_LASTTYPE = TOK_VOID,
|
|
|
|
|
|
|
|
|
|
/* Control statements */
|
|
|
|
|
TOK_DO,
|
|
|
|
|
TOK_FOR,
|
|
|
|
|
TOK_GOTO,
|
|
|
|
|
TOK_IF,
|
|
|
|
|
TOK_RETURN,
|
|
|
|
|
TOK_SWITCH,
|
|
|
|
|
TOK_WHILE,
|
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|
|
|
TOK_GE,
|
|
|
|
|
TOK_GT,
|
|
|
|
|
|
2000-08-20 19:12:43 +00:00
|
|
|
|
TOK_SHL_ASSIGN,
|
|
|
|
|
TOK_SHL,
|
2000-06-12 18:31:40 +00:00
|
|
|
|
TOK_SHR_ASSIGN,
|
|
|
|
|
TOK_SHR,
|
|
|
|
|
TOK_XOR_ASSIGN,
|
|
|
|
|
TOK_XOR,
|
|
|
|
|
TOK_MOD_ASSIGN,
|
|
|
|
|
TOK_MOD,
|
|
|
|
|
TOK_QUEST,
|
|
|
|
|
TOK_COLON,
|
|
|
|
|
TOK_RPAREN,
|
|
|
|
|
TOK_SCONST,
|
|
|
|
|
TOK_ICONST,
|
|
|
|
|
TOK_CCONST,
|
|
|
|
|
TOK_FCONST,
|
|
|
|
|
|
|
|
|
|
TOK_ATTRIBUTE,
|
2000-08-14 22:18:26 +00:00
|
|
|
|
TOK_FAR,
|
2000-06-12 18:31:40 +00:00
|
|
|
|
TOK_FASTCALL,
|
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,
|
|
|
|
|
TOK_EAX,
|
2000-08-16 09:10:50 +00:00
|
|
|
|
|
2000-06-12 18:31:40 +00:00
|
|
|
|
TOK_PRAGMA
|
|
|
|
|
} token_t;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* data */
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Token stuff */
|
2001-05-22 09:32:24 +00:00
|
|
|
|
typedef struct Token Token;
|
|
|
|
|
struct Token {
|
|
|
|
|
token_t Tok; /* The token itself */
|
|
|
|
|
long IVal; /* The integer attribute */
|
|
|
|
|
double FVal; /* The float attribute */
|
|
|
|
|
ident Ident; /* Identifier if IDENT */
|
|
|
|
|
LineInfo* LI; /* Source line where the token comes from */
|
2001-03-26 21:57:07 +00:00
|
|
|
|
type* Type; /* Type if integer or float constant */
|
2000-05-28 13:40:48 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
extern Token CurTok; /* The current token */
|
|
|
|
|
extern Token NextTok; /* The next token */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2001-09-09 20:49:20 +00:00
|
|
|
|
/* code */
|
2000-05-28 13:40:48 +00:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-06-21 21:02:44 +00:00
|
|
|
|
void SymName (char* s);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
/* Get symbol from input stream */
|
|
|
|
|
|
2000-06-21 21:02:44 +00:00
|
|
|
|
int IsSym (char* s);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
/* Get symbol from input stream or return 0 if not a symbol. */
|
|
|
|
|
|
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.
|
|
|
|
|
* This routine is used for error recovery.
|
|
|
|
|
*/
|
|
|
|
|
|
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
|
2002-09-29 21:09:47 +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 */
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|