123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- //===========================================================================//
- // Copyright (C) Microsoft Corporation. All rights reserved. //
- //===========================================================================//
- //***************************************************************************
- //
- // SCANNER.H
- //
- //***************************************************************************
- #ifndef ABLSCAN_H
- #define ABLSCAN_H
- #ifndef ABLGEN_H
- #include "ablgen.h"
- #endif
- #ifndef ABLERR_H
- #include "ablerr.h"
- #endif
- //***************************************************************************
- #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_ORDER,
- TKN_STATE,
- 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_ORDER,
- TKN_END_STATE,
- TKN_END_MODULE,
- TKN_END_FSM,
- 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_FSM,
- TKN_TRANS,
- TKN_TRANS_BACK,
- TKN_LIBRARY,
- TKN_ETERNAL,
- TKN_STATIC,
- 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;
- //***************************************************************************
- class ABLFile {
- public:
- char* fileName;
- void* file;
- static long (*createCB) (void** file, char* fName);
- static long (*openCB) (void** file, char* fName);
- static long (*closeCB) (void** file);
- static bool (*eofCB) (void* file);
- static long (*readCB) (void* file, unsigned char* buffer, long length);
- static long (*readLongCB) (void* file);
- static long (*readStringCB) (void* file, unsigned char* buffer);
- static long (*readLineExCB) (void* file, unsigned char* buffer, long maxLength);
- static long (*writeCB) (void* file, unsigned char* buffer, long length);
- static long (*writeByteCB) (void* file, unsigned char byte);
- static long (*writeLongCB) (void* file, long value);
- static long (*writeStringCB) (void* file, char* buffer);
- public:
- void* operator new (size_t ourSize);
- void operator delete (void *us);
- void init (void);
-
- ABLFile (void) {
- init();
- }
- void destroy (void);
- ~ABLFile (void) {
- destroy();
- }
-
- long set (void* fPtr) {
- file = fPtr;
- }
- void* get (void) {
- return(file);
- }
- long create (char* fileName);
- long open (char* fileName);
- long close (void);
- bool eof (void);
- long read (unsigned char* buffer, long length);
- long readLong (void);
- long readString (unsigned char* buffer);
- long readLineEx (unsigned char* buffer, long maxLength);
- long write (unsigned char* buffer, long length);
- long writeByte (unsigned char val);
- long writeLong (long val);
- long writeString (char* buffer);
- };
- //***************************************************************************
- //----------
- // 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];
- extern void* (*ABLSystemMallocCallback) (unsigned long memSize);
- extern void* (*ABLStackMallocCallback) (unsigned long memSize);
- extern void* (*ABLCodeMallocCallback) (unsigned long memSize);
- extern void* (*ABLSymbolMallocCallback) (unsigned long memSize);
- extern void (*ABLSystemFreeCallback) (void* memBlock);
- extern void (*ABLStackFreeCallback) (void* memBlock);
- extern void (*ABLCodeFreeCallback) (void* memBlock);
- extern void (*ABLSymbolFreeCallback) (void* memBlock);
- extern void (*ABLDebugPrintCallback) (char* s);
- extern long (*ABLRandomCallback) (long range);
- extern void (*ABLSeedRandomCallback) (unsigned long range);
- extern unsigned long (*ABLGetTimeCallback) (void);
- extern void (*ABLFatalCallback) (long code, char* s);
- //***************************************************************************
-
- #endif
|