//***************************************************************************
//
//								SCANNER.H
//
//***************************************************************************

#ifndef ABLSCAN_H
#define	ABLSCAN_H

#include "ablgen.h"
#include "ablerr.h"
namespace ABL
{

//***************************************************************************

#define	TAB_SIZE				4

//#define	MIN_INTEGER				-2147483648
#define	MAX_INTEGER				2147483647
#define	MAX_DIGIT_COUNT			20
#define	MAX_EXPONENT			20

//***************************************************************************

//------------
// TOKEN CODES

typedef enum {
	TKN_NONE,
	TKN_IDENTIFIER,
	TKN_NUMBER,
	TKN_TYPE,
	TKN_STRING,
	TKN_STAR,
	TKN_LPAREN,
	TKN_RPAREN,
	TKN_MINUS,
	TKN_PLUS,
	TKN_EQUAL,
	TKN_LBRACKET,
	TKN_RBRACKET,
	TKN_COLON,
	TKN_SEMICOLON,
	TKN_LT,
	TKN_GT,
	TKN_COMMA,
	TKN_PERIOD,
	TKN_FSLASH,
	TKN_EQUALEQUAL,
	TKN_LE,
	TKN_GE,
	TKN_NE,
	TKN_EOF,
	TKN_ERROR,
	TKN_CODE,
	TKN_ORDERS,
	TKN_AND,
	TKN_SWITCH,
	TKN_CASE,
	TKN_CONST,
	TKN_DIV,
	TKN_DO,
	TKN_OF,
	TKN_ELSE,
	TKN_END_IF,
	TKN_END_WHILE,
	TKN_END_FOR,
	TKN_END_FUNCTION,
	TKN_END_MODULE,
	TKN_END_LIBRARY,
	TKN_END_VAR,
	TKN_END_CODE,
	TKN_END_CASE,
	TKN_END_SWITCH,
	TKN_FOR,
	TKN_FUNCTION,
	TKN_IF,
	TKN_MOD,
	TKN_NOT,
	TKN_OR,
	TKN_REPEAT,
	TKN_THEN,
	TKN_TO,
	TKN_UNTIL,
	TKN_VAR,
	TKN_REF,
	TKN_WHILE,
	TKN_ELSIF,
	TKN_RETURN,
	TKN_MODULE,
	TKN_LIBRARY,
	TKN_ETERNAL,
	TKN_STATIC,
	TKN_FSM,
	TKN_END_FSM,
	TKN_STATE,
	TKN_END_STATE,
	TKN_TRANS,
	TKN_POUND,
	TKN_UNEXPECTED_TOKEN,
	TKN_STATEMENT_MARKER,
	TKN_ADDRESS_MARKER,
	NUM_TOKENS
} TokenCodeType;

typedef enum {
	CHR_LETTER,
	CHR_DIGIT,
	CHR_DQUOTE,
	CHR_SPECIAL,
	CHR_EOF
} CharCodeType;

typedef struct {
	char*			string;
	TokenCodeType	tokenCode;
} ReservedWord;

//***************************************************************************

//------------------
// LITERAL structure

typedef enum {
	LIT_INTEGER,
	LIT_REAL,
	LIT_STRING
} LiteralType;

typedef struct {
	LiteralType		type;
	struct {
		long		integer;
		float		real;
		char		string[MAXLEN_TOKENSTRING];
	} value;
} Literal;

//---------------------------------------------------------------------------

typedef struct CaseItem {
	int					labelValue;
	char*				branchLocation;
	struct CaseItem*	next;
} CaseItem;

typedef CaseItem* CaseItemPtr;

//***************************************************************************

//----------
// FUNCTIONS

inline CharCodeType calcCharCode (long ch);
long isReservedWord (void);
void initScanner (char* fileName);
void quitScanner (void);
void skipComment (void);
void skipBlanks (void);
void getChar(void);
void crunchToken (void);
void downShiftWord (void);
void getToken(void);
void getWord (void);
void accumulateValue (float* valuePtr, SyntaxErrorType errCode);
void getNumber (void);
void getString (void);
void getSpecial (void);
bool tokenIn (TokenCodeType* tokenList);
void synchronize (TokenCodeType* tokenList1,
				  TokenCodeType* tokenList2,
				  TokenCodeType* tokenList3);
bool getSourceLine (void);
void printLine (char* line);
void initPageHeader (char* fileName);
void printPageHeader (void);

//----------
// VARIABLES

extern char			wordString[MAXLEN_TOKENSTRING];

//***************************************************************************
}	
#endif


