Leaked source code of windows server 2003
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.

122 lines
2.9 KiB

  1. // Copyright (c) 1999 Microsoft Corporation. All rights reserved.
  2. //
  3. // Declaration of Lexer.
  4. //
  5. // Lexical analyzer for AudioVBScript. Breaks down the characters of source code into a stream tokens.
  6. #pragma once
  7. const int g_iMaxBuffer = 256; // max length for VBScript identifiers is 255
  8. enum LexErr
  9. {
  10. LEXERR_NoError = 0,
  11. LEXERR_InvalidCharacter,
  12. LEXERR_NonAsciiCharacterInStringLiteral = LEXERR_InvalidCharacter,
  13. LEXERR_IdentifierTooLong,
  14. LEXERR_StringLiteralTooLong,
  15. LEXERR_StringLiteralUnterminated,
  16. LEXERR_NumericLiteralTooLarge,
  17. LEXERR_Max
  18. };
  19. enum Token
  20. {
  21. TOKEN_eof = 0, // used for end of file or an error (nenzero error_num() indicates an error)
  22. TOKEN_sub,
  23. TOKEN_dim,
  24. TOKEN_if,
  25. TOKEN_then,
  26. TOKEN_end,
  27. TOKEN_elseif,
  28. TOKEN_else,
  29. TOKEN_set,
  30. TOKEN_call,
  31. TOKEN_lparen,
  32. TOKEN_rparen,
  33. TOKEN_comma,
  34. TOKEN_op_minus,
  35. TOKEN_op_not,
  36. TOKEN_op_pow,
  37. TOKEN_op_mult,
  38. TOKEN_op_div,
  39. TOKEN_op_mod,
  40. TOKEN_op_plus,
  41. TOKEN_op_lt,
  42. TOKEN_op_leq,
  43. TOKEN_op_gt,
  44. TOKEN_op_geq,
  45. TOKEN_op_eq,
  46. TOKEN_op_neq,
  47. TOKEN_is,
  48. TOKEN_and,
  49. TOKEN_or,
  50. TOKEN_linebreak,
  51. TOKEN_identifier,
  52. TOKEN_identifierdot,
  53. TOKEN_stringliteral,
  54. TOKEN_numericliteral
  55. };
  56. struct TokenKeysym
  57. {
  58. WCHAR c;
  59. Token t;
  60. };
  61. extern const TokenKeysym g_TokenKeysyms[];
  62. struct TokenKeyword
  63. {
  64. const WCHAR *s;
  65. Token t;
  66. };
  67. extern const TokenKeyword g_TokenKeywords[];
  68. bool CheckOperatorType(Token t, bool fAcceptParens, bool fAcceptUnary, bool fAcceptBinary, bool fAcceptOverloadedAssignmentTokens);
  69. class Lexer
  70. {
  71. public:
  72. Lexer(const WCHAR *pwszSource);
  73. Lexer &operator++() { Next(); Scan(); return *this; }
  74. int line() { return m_iLine; }
  75. int column() { return m_iColumn; }
  76. operator Token() { return m_t; }
  77. // Additional token-specific info. Only valid while on this token.
  78. // error
  79. int error_num() { assert(m_t == TOKEN_eof); return num(); } // 0 if no error
  80. const char *error_descr() { assert(m_t == TOKEN_eof); return str(); }
  81. // identifier and identifierdot
  82. const char *identifier_name() { assert(m_t == TOKEN_identifier || m_t == TOKEN_identifierdot); return str(); }
  83. // numeric literal
  84. int numericliteral_val() { assert(m_t == TOKEN_numericliteral); return num(); }
  85. // string literal
  86. const char *stringliteral_text() { assert(m_t == TOKEN_stringliteral); return str(); }
  87. private:
  88. friend class CActiveScriptError;
  89. void Next();
  90. void Scan(); // handling for line break tokens and calls ScanMain
  91. void ScanMain();
  92. const char *str() { return m_szStr; } // Multipurpose string info set by some tokens.
  93. void err(LexErr iErr);
  94. int num() { return m_iNum; } // Multipurpose numeric info set by some tokens.
  95. const WCHAR *m_p;
  96. const WCHAR *m_pNext; // If this is set then the next Next call will advance the pointer (and the column) to this point.
  97. int m_iLine;
  98. int m_iColumn;
  99. Token m_t;
  100. char m_szStr[g_iMaxBuffer];
  101. int m_iNum;
  102. };