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.

108 lines
2.5 KiB

  1. /*++
  2. Copyright (C) 1999 Microsoft Corporation
  3. Module Name:
  4. GENLEX.H
  5. Abstract:
  6. Generic lexer framework classes.
  7. History:
  8. --*/
  9. #ifndef _GENLEX_H_
  10. #define _GENLEX_H_
  11. #include <Polarity.h>
  12. class CGenLexSource
  13. {
  14. public:
  15. virtual wchar_t NextChar() = 0;
  16. // Return 0 on end-of-input
  17. virtual void Pushback(wchar_t) = 0;
  18. virtual void Reset() = 0;
  19. };
  20. class CTextLexSource : public CGenLexSource
  21. {
  22. const wchar_t *m_pSrcBuf;
  23. const wchar_t *m_pStart;
  24. public:
  25. CTextLexSource(const wchar_t *pSrc) { SetString(pSrc); }
  26. // Binds directly to <pSrc> buffer, but doesn't delete it.
  27. wchar_t NextChar()
  28. {
  29. if (!m_pSrcBuf)
  30. return 0;
  31. else
  32. return *m_pSrcBuf++ ? m_pSrcBuf[-1] : 0;
  33. }
  34. void Pushback(wchar_t)
  35. {
  36. if (m_pSrcBuf)
  37. --m_pSrcBuf;
  38. }
  39. /* Per Code coverate analysis, this function is never hit. However, this can not be removed since that will
  40. make it a non-abstract class */
  41. void Reset() {
  42. #ifdef DBG
  43. DebugBreak();
  44. #endif
  45. /* m_pSrcBuf = m_pStart; */
  46. }
  47. void SetString (const wchar_t *pSrc) { m_pSrcBuf = m_pStart = pSrc; }
  48. };
  49. #pragma pack(2)
  50. struct LexEl
  51. {
  52. wchar_t cFirst, cLast;
  53. WORD wGotoState;
  54. WORD wReturnTok;
  55. WORD wInstructions;
  56. };
  57. #pragma pack()
  58. // Lexer driver instructions
  59. #define GLEX_ACCEPT 0x1 // Add the char to the token
  60. #define GLEX_CONSUME 0x2 // Consume the char without adding to token
  61. #define GLEX_PUSHBACK 0x4 // Place the char back in the source buffer for next token
  62. #define GLEX_NOT 0x8 // A match occurs if the char is NOT the one specified
  63. #define GLEX_LINEFEED 0x10 // Increase the source linecount
  64. #define GLEX_RETURN 0x20 // Return the indicated token to caller
  65. #define GLEX_ANY wchar_t(0xFFFF) // Any character
  66. #define GLEX_EMPTY wchar_t(0xFFFE) // When subrange is not specified
  67. class POLARITY CGenLexer
  68. {
  69. wchar_t *m_pTokenBuf;
  70. int m_nCurrentLine;
  71. int m_nCurBufSize;
  72. CGenLexSource *m_pSrc;
  73. LexEl *m_pTable;
  74. public:
  75. CGenLexer(LexEl *pTbl, CGenLexSource *pSrc);
  76. ~CGenLexer();
  77. int NextToken();
  78. // Returns 0 on end of input.
  79. wchar_t* GetTokenText() { return m_pTokenBuf; }
  80. int GetLineNum() { return m_nCurrentLine; }
  81. void Reset();
  82. };
  83. #endif