Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

248 lines
6.2 KiB

  1. //
  2. // Copyright (c) Microsoft Corporation 1995
  3. //
  4. // scanner.h
  5. //
  6. // Header file for the scanner.
  7. //
  8. // History:
  9. // 04-05-95 ScottH Created
  10. //
  11. #ifndef __SCANNER_H__
  12. #define __SCANNER_H__
  13. //
  14. // Symbols
  15. //
  16. typedef enum
  17. {
  18. SYM_EOF, // end of file
  19. SYM_UNKNOWN, // unknown lexeme
  20. SYM_COLON, // ':'
  21. SYM_COMMA, // ','
  22. SYM_IDENT, // identifier
  23. SYM_STRING_LITERAL, // a string literal
  24. SYM_INT_LITERAL, // an integer literal
  25. SYM_INTEGER, // 'integer'
  26. SYM_STRING, // 'string'
  27. SYM_BOOLEAN, // 'boolean'
  28. SYM_WAITFOR, // 'waitfor'
  29. SYM_THEN, // 'then'
  30. SYM_UNTIL, // 'until'
  31. SYM_TRANSMIT, // 'transmit'
  32. SYM_PROC, // 'proc'
  33. SYM_ENDPROC, // 'endproc'
  34. SYM_DELAY, // 'delay'
  35. SYM_HALT, // 'halt'
  36. SYM_GETIP, // 'getip'
  37. SYM_GOTO, // 'goto'
  38. SYM_WHILE, // 'while'
  39. SYM_DO, // 'do'
  40. SYM_ENDWHILE, // 'endwhile'
  41. SYM_IF, // 'if'
  42. SYM_ENDIF, // 'endif'
  43. SYM_RAW, // 'raw'
  44. SYM_MATCHCASE, // 'matchcase'
  45. SYM_SET, // 'set'
  46. SYM_IPADDR, // 'ipaddr'
  47. SYM_PORT, // 'port'
  48. SYM_DATABITS, // 'databits'
  49. SYM_STOPBITS, // 'stopbits'
  50. SYM_PARITY, // 'parity'
  51. SYM_NONE, // 'none'
  52. SYM_ODD, // 'odd'
  53. SYM_EVEN, // 'even'
  54. SYM_MARK, // 'mark'
  55. SYM_SPACE, // 'space'
  56. SYM_SCREEN, // 'screen'
  57. SYM_KEYBRD, // 'keyboard'
  58. SYM_ON, // 'on'
  59. SYM_OFF, // 'off'
  60. SYM_LPAREN, // '('
  61. SYM_RPAREN, // ')'
  62. SYM_ASSIGN, // = (assignment)
  63. SYM_TRUE, // 'TRUE'
  64. SYM_FALSE, // 'FALSE'
  65. SYM_NOT, // '!'
  66. // WARNING: The types below must match the order of their
  67. // corresponding BOT values.
  68. SYM_OR, // 'or'
  69. SYM_AND, // 'and'
  70. SYM_LEQ, // '<='
  71. SYM_LT, // '<'
  72. SYM_GEQ, // '>='
  73. SYM_GT, // '>'
  74. SYM_NEQ, // '!='
  75. SYM_EQ, // '=='
  76. SYM_PLUS, // '+'
  77. SYM_MINUS, // '-'
  78. SYM_MULT, // '*'
  79. SYM_DIV, // '/'
  80. } SYM;
  81. DECLARE_STANDARD_TYPES(SYM);
  82. //
  83. // Tokens
  84. //
  85. #define MAX_BUF_KEYWORD 32
  86. typedef enum
  87. {
  88. TT_BASE,
  89. TT_SZ,
  90. TT_INT,
  91. } TOKTYPE;
  92. // Basic Token Type
  93. typedef struct tagTOK
  94. {
  95. DWORD cbSize;
  96. SYM sym;
  97. TOKTYPE toktype;
  98. DWORD iLine;
  99. char szLexeme[MAX_BUF_KEYWORD];
  100. } TOK; // Basic token type
  101. DECLARE_STANDARD_TYPES(TOK);
  102. #define Tok_GetSize(p) (((PTOK)(p))->cbSize)
  103. #define Tok_GetSym(p) (((PTOK)(p))->sym)
  104. #define Tok_GetType(p) (((PTOK)(p))->toktype)
  105. #define Tok_GetLine(p) (((PTOK)(p))->iLine)
  106. #define Tok_GetLexeme(p) (((PTOK)(p))->szLexeme)
  107. #define Tok_SetSize(p, s) (((PTOK)(p))->cbSize = (s))
  108. #define Tok_SetSym(p, s) (((PTOK)(p))->sym = (s))
  109. #define Tok_SetType(p, tt) (((PTOK)(p))->toktype = (tt))
  110. #define Tok_SetLine(p, l) (((PTOK)(p))->iLine = (l))
  111. #define Tok_SetLexeme(p, s) lstrcpyn(((PTOK)(p))->szLexeme, s, sizeof(((PTOK)(p))->szLexeme))
  112. RES PUBLIC Tok_New(PTOK * pptok, SYM sym, LPCSTR pszLexeme, DWORD iLine);
  113. void PUBLIC Tok_Delete(PTOK this);
  114. // String Token
  115. typedef struct tagTOKSZ
  116. {
  117. TOK tok;
  118. char sz[MAX_BUF];
  119. } TOKSZ;
  120. DECLARE_STANDARD_TYPES(TOKSZ);
  121. #define TokSz_GetSz(p) (((PTOKSZ)(p))->sz)
  122. #define TokSz_SetSz(p, s) lstrcpyn(((PTOKSZ)(p))->sz, s, sizeof(((PTOKSZ)(p))->sz))
  123. RES PUBLIC TokSz_New(PTOK * pptok, SYM sym, LPCSTR pszLexeme, DWORD iLine, LPCSTR pszID);
  124. // Integer Token
  125. typedef struct tagTOKINT
  126. {
  127. TOK tok;
  128. int n;
  129. } TOKINT;
  130. DECLARE_STANDARD_TYPES(TOKINT);
  131. #define TokInt_GetVal(p) (((PTOKINT)(p))->n)
  132. #define TokInt_SetVal(p, v) (((PTOKINT)(p))->n = (v))
  133. RES PUBLIC TokInt_New(PTOK * pptok, SYM sym, LPCSTR pszLexeme, DWORD iLine, int n);
  134. //
  135. // Syntax error object
  136. //
  137. typedef struct tagSTXERR
  138. {
  139. char szLexeme[MAX_BUF_KEYWORD];
  140. DWORD iLine;
  141. RES res;
  142. } STXERR;
  143. DECLARE_STANDARD_TYPES(STXERR);
  144. #define Stxerr_GetLexeme(p) ((p)->szLexeme)
  145. #define Stxerr_GetLine(p) ((p)->iLine)
  146. #define Stxerr_GetRes(p) ((p)->res)
  147. //
  148. // Scanner
  149. //
  150. typedef struct tagSCANNER
  151. {
  152. DWORD dwFlags; // SCF_*
  153. PSESS_CONFIGURATION_INFO psci;
  154. char szScript[MAX_PATH];
  155. HANDLE hfile;
  156. LPBYTE pbBuffer; // Read buffer
  157. LPBYTE pbCur; // Current unread position in buffer
  158. DWORD cbUnread; // Count of unread bytes in buffer
  159. char chCur; // Current character, set by Scanner_GetChar()
  160. char chTailByte; // Tail byte for DBCS characters
  161. char chUnget; // Ungotten character
  162. PTOK ptokCur; // Current token, set by Scanner_GetToken()
  163. PTOK ptokUnget; // Ungotten token
  164. DWORD iLine; // The current line number
  165. HSA hsaStxerr; // List of errors
  166. DWORD isaStxerr; // Current error
  167. } SCANNER;
  168. DECLARE_STANDARD_TYPES(SCANNER);
  169. // Scanner flags
  170. #define SCF_NOSCRIPT 0x0001
  171. #define Scanner_GetStxerrHandle(this) ((this)->hsaStxerr)
  172. RES PUBLIC Scanner_Create(PSCANNER * ppscanner, PSESS_CONFIGURATION_INFO psci);
  173. RES PUBLIC Scanner_Destroy(PSCANNER this);
  174. RES PUBLIC Scanner_OpenScript(PSCANNER this, LPCSTR pszPath);
  175. RES PUBLIC Scanner_GetToken(PSCANNER this, PTOK * pptok);
  176. RES PUBLIC Scanner_UngetToken(PSCANNER this);
  177. RES PUBLIC Scanner_Peek(PSCANNER this, PSYM psym);
  178. RES PUBLIC Scanner_ReadToken(PSCANNER this, SYM sym);
  179. RES PUBLIC Scanner_CondReadToken(PSCANNER this, SYM symExpect, PTOK * pptok);
  180. DWORD PUBLIC Scanner_GetLine(PSCANNER this);
  181. RES PUBLIC Scanner_AddError(PSCANNER this, PTOK ptok, RES resErr);
  182. RES PUBLIC Stxerr_ShowErrors(HSA hsaStxerr, HWND hwndOwner);
  183. RES PUBLIC Stxerr_Add(HSA hsaStxerr, LPCSTR pszLexeme, DWORD iLine, RES resErr);
  184. RES PUBLIC Stxerr_AddTok(HSA hsaStxerr, PTOK ptok, RES resErr);
  185. #endif // __SCANNER_H__