Ablscan.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. //===========================================================================//
  2. // Copyright (C) Microsoft Corporation. All rights reserved. //
  3. //===========================================================================//
  4. //***************************************************************************
  5. //
  6. // SCANNER.H
  7. //
  8. //***************************************************************************
  9. #ifndef ABLSCAN_H
  10. #define ABLSCAN_H
  11. #ifndef ABLGEN_H
  12. #include "ablgen.h"
  13. #endif
  14. #ifndef ABLERR_H
  15. #include "ablerr.h"
  16. #endif
  17. //***************************************************************************
  18. #define TAB_SIZE 4
  19. //#define MIN_INTEGER -2147483648
  20. #define MAX_INTEGER 2147483647
  21. #define MAX_DIGIT_COUNT 20
  22. #define MAX_EXPONENT 20
  23. //***************************************************************************
  24. //------------
  25. // TOKEN CODES
  26. typedef enum {
  27. TKN_NONE,
  28. TKN_IDENTIFIER,
  29. TKN_NUMBER,
  30. TKN_TYPE,
  31. TKN_STRING,
  32. TKN_STAR,
  33. TKN_LPAREN,
  34. TKN_RPAREN,
  35. TKN_MINUS,
  36. TKN_PLUS,
  37. TKN_EQUAL,
  38. TKN_LBRACKET,
  39. TKN_RBRACKET,
  40. TKN_COLON,
  41. TKN_SEMICOLON,
  42. TKN_LT,
  43. TKN_GT,
  44. TKN_COMMA,
  45. TKN_PERIOD,
  46. TKN_FSLASH,
  47. TKN_EQUALEQUAL,
  48. TKN_LE,
  49. TKN_GE,
  50. TKN_NE,
  51. TKN_EOF,
  52. TKN_ERROR,
  53. TKN_CODE,
  54. TKN_ORDER,
  55. TKN_STATE,
  56. TKN_AND,
  57. TKN_SWITCH,
  58. TKN_CASE,
  59. TKN_CONST,
  60. TKN_DIV,
  61. TKN_DO,
  62. TKN_OF,
  63. TKN_ELSE,
  64. TKN_END_IF,
  65. TKN_END_WHILE,
  66. TKN_END_FOR,
  67. TKN_END_FUNCTION,
  68. TKN_END_ORDER,
  69. TKN_END_STATE,
  70. TKN_END_MODULE,
  71. TKN_END_FSM,
  72. TKN_END_LIBRARY,
  73. TKN_END_VAR,
  74. TKN_END_CODE,
  75. TKN_END_CASE,
  76. TKN_END_SWITCH,
  77. TKN_FOR,
  78. TKN_FUNCTION,
  79. TKN_IF,
  80. TKN_MOD,
  81. TKN_NOT,
  82. TKN_OR,
  83. TKN_REPEAT,
  84. TKN_THEN,
  85. TKN_TO,
  86. TKN_UNTIL,
  87. TKN_VAR,
  88. TKN_REF,
  89. TKN_WHILE,
  90. TKN_ELSIF,
  91. TKN_RETURN,
  92. TKN_MODULE,
  93. TKN_FSM,
  94. TKN_TRANS,
  95. TKN_TRANS_BACK,
  96. TKN_LIBRARY,
  97. TKN_ETERNAL,
  98. TKN_STATIC,
  99. TKN_POUND,
  100. TKN_UNEXPECTED_TOKEN,
  101. TKN_STATEMENT_MARKER,
  102. TKN_ADDRESS_MARKER,
  103. NUM_TOKENS
  104. } TokenCodeType;
  105. typedef enum {
  106. CHR_LETTER,
  107. CHR_DIGIT,
  108. CHR_DQUOTE,
  109. CHR_SPECIAL,
  110. CHR_EOF
  111. } CharCodeType;
  112. typedef struct {
  113. char* string;
  114. TokenCodeType tokenCode;
  115. } ReservedWord;
  116. //***************************************************************************
  117. //------------------
  118. // LITERAL structure
  119. typedef enum {
  120. LIT_INTEGER,
  121. LIT_REAL,
  122. LIT_STRING
  123. } LiteralType;
  124. typedef struct {
  125. LiteralType type;
  126. struct {
  127. long integer;
  128. float real;
  129. char string[MAXLEN_TOKENSTRING];
  130. } value;
  131. } Literal;
  132. //---------------------------------------------------------------------------
  133. typedef struct CaseItem {
  134. int labelValue;
  135. char* branchLocation;
  136. struct CaseItem* next;
  137. } CaseItem;
  138. typedef CaseItem* CaseItemPtr;
  139. //***************************************************************************
  140. class ABLFile {
  141. public:
  142. char* fileName;
  143. void* file;
  144. static long (*createCB) (void** file, char* fName);
  145. static long (*openCB) (void** file, char* fName);
  146. static long (*closeCB) (void** file);
  147. static bool (*eofCB) (void* file);
  148. static long (*readCB) (void* file, unsigned char* buffer, long length);
  149. static long (*readLongCB) (void* file);
  150. static long (*readStringCB) (void* file, unsigned char* buffer);
  151. static long (*readLineExCB) (void* file, unsigned char* buffer, long maxLength);
  152. static long (*writeCB) (void* file, unsigned char* buffer, long length);
  153. static long (*writeByteCB) (void* file, unsigned char byte);
  154. static long (*writeLongCB) (void* file, long value);
  155. static long (*writeStringCB) (void* file, char* buffer);
  156. public:
  157. void* operator new (size_t ourSize);
  158. void operator delete (void *us);
  159. void init (void);
  160. ABLFile (void) {
  161. init();
  162. }
  163. void destroy (void);
  164. ~ABLFile (void) {
  165. destroy();
  166. }
  167. long set (void* fPtr) {
  168. file = fPtr;
  169. }
  170. void* get (void) {
  171. return(file);
  172. }
  173. long create (char* fileName);
  174. long open (char* fileName);
  175. long close (void);
  176. bool eof (void);
  177. long read (unsigned char* buffer, long length);
  178. long readLong (void);
  179. long readString (unsigned char* buffer);
  180. long readLineEx (unsigned char* buffer, long maxLength);
  181. long write (unsigned char* buffer, long length);
  182. long writeByte (unsigned char val);
  183. long writeLong (long val);
  184. long writeString (char* buffer);
  185. };
  186. //***************************************************************************
  187. //----------
  188. // FUNCTIONS
  189. inline CharCodeType calcCharCode (long ch);
  190. long isReservedWord (void);
  191. void initScanner (char* fileName);
  192. void quitScanner (void);
  193. void skipComment (void);
  194. void skipBlanks (void);
  195. void getChar(void);
  196. void crunchToken (void);
  197. void downShiftWord (void);
  198. void getToken(void);
  199. void getWord (void);
  200. void accumulateValue (float* valuePtr, SyntaxErrorType errCode);
  201. void getNumber (void);
  202. void getString (void);
  203. void getSpecial (void);
  204. bool tokenIn (TokenCodeType* tokenList);
  205. void synchronize (TokenCodeType* tokenList1,
  206. TokenCodeType* tokenList2,
  207. TokenCodeType* tokenList3);
  208. bool getSourceLine (void);
  209. void printLine (char* line);
  210. void initPageHeader (char* fileName);
  211. void printPageHeader (void);
  212. //----------
  213. // VARIABLES
  214. extern char wordString[MAXLEN_TOKENSTRING];
  215. extern void* (*ABLSystemMallocCallback) (unsigned long memSize);
  216. extern void* (*ABLStackMallocCallback) (unsigned long memSize);
  217. extern void* (*ABLCodeMallocCallback) (unsigned long memSize);
  218. extern void* (*ABLSymbolMallocCallback) (unsigned long memSize);
  219. extern void (*ABLSystemFreeCallback) (void* memBlock);
  220. extern void (*ABLStackFreeCallback) (void* memBlock);
  221. extern void (*ABLCodeFreeCallback) (void* memBlock);
  222. extern void (*ABLSymbolFreeCallback) (void* memBlock);
  223. extern void (*ABLDebugPrintCallback) (char* s);
  224. extern long (*ABLRandomCallback) (long range);
  225. extern void (*ABLSeedRandomCallback) (unsigned long range);
  226. extern unsigned long (*ABLGetTimeCallback) (void);
  227. extern void (*ABLFatalCallback) (long code, char* s);
  228. //***************************************************************************
  229. #endif