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.

303 lines
7.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1991, Microsoft Corporation.
  4. //
  5. // File: State.hxx
  6. //
  7. // Contents: Finite automata state classes
  8. //
  9. // Classes:
  10. //
  11. // History: 01-21-92 KyleP Created
  12. //
  13. //--------------------------------------------------------------------------
  14. #pragma once
  15. #ifdef DISPLAY_INCLUDES
  16. #pragma message( "#include <" __FILE__ ">..." )
  17. #endif
  18. #include <xlatchar.hxx>
  19. class CStateSet;
  20. class CSymbolSet;
  21. //
  22. // Special transition 'states'.
  23. //
  24. UINT const stateUncomputed = (1 << (sizeof( UINT ) * 8)) - 1; // Uncomputed move.
  25. UINT const stateUndefined = (1 << (sizeof( UINT ) * 8)) - 2; // Undefined move.
  26. UINT const stateUninitialized = (1 << (sizeof( UINT ) * 8)) - 3; // Uninitialized
  27. //+-------------------------------------------------------------------------
  28. //
  29. // Class: CFAState
  30. //
  31. // Purpose: Basic finite automata state.
  32. //
  33. // History: 20-Jan-92 KyleP Created
  34. //
  35. //--------------------------------------------------------------------------
  36. class CFAState
  37. {
  38. public:
  39. inline CFAState() {};
  40. inline CFAState( UINT iState, BOOL fFinal = FALSE );
  41. inline void Init( UINT iState );
  42. inline UINT StateNumber() const;
  43. inline BOOL IsFinal() const;
  44. inline void MakeFinal();
  45. protected:
  46. UINT _iState;
  47. BOOL _fFinal;
  48. #if (CIDBG == 1)
  49. public:
  50. //
  51. // Debug methods
  52. //
  53. virtual void Display();
  54. #endif // (CIDBG == 1)
  55. };
  56. //+-------------------------------------------------------------------------
  57. //
  58. // Class: CNFAState
  59. //
  60. // Purpose: Nondeterministic finite automata state.
  61. //
  62. // History: 20-Jan-92 KyleP Created
  63. //
  64. // Notes: The array of moves is split into two pieces. Since most
  65. // states only have a small number of transitions each
  66. // CNFAState will hold a small number in the CNFAState
  67. // object itself. Overflow is on the heap.
  68. //
  69. //--------------------------------------------------------------------------
  70. const int CNFAState_cFirst = 2; // Default number of moves per state
  71. class CNFAState : public CFAState
  72. {
  73. public:
  74. inline CNFAState();
  75. CNFAState( CNFAState const & src );
  76. CNFAState & operator=( CNFAState const & src );
  77. void Init( CNFAState & src );
  78. void Init( UINT iState ) { CFAState::Init( iState ); }
  79. inline ~CNFAState();
  80. void AddTransition( UINT symbol, UINT StateNum );
  81. void RemoveTransition( UINT symbol, UINT StateNum );
  82. void Move( CStateSet & ss, UINT symbol = symEpsilon );
  83. void Move( CStateSet & ss, CSymbolSet & symset );
  84. protected:
  85. class CMove
  86. {
  87. public:
  88. inline CMove();
  89. inline CMove( UINT symbol, UINT iState );
  90. UINT _symbol;
  91. UINT _iState;
  92. };
  93. CMove _moveFirst[CNFAState_cFirst];
  94. CMove * _pmoveRest;
  95. int _cmoveRest;
  96. int _cMove;
  97. #if (CIDBG == 1)
  98. public:
  99. //
  100. // Debug methods
  101. //
  102. virtual void Display();
  103. #endif // (CIDBG == 1)
  104. };
  105. //+-------------------------------------------------------------------------
  106. //
  107. // Member: CFAState::CFAState, public
  108. //
  109. // Synopsis: Initialize new state.
  110. //
  111. // Arguments: [iState] -- State number.
  112. // [fFinal] -- TRUE if state is a final state.
  113. //
  114. // History: 20-Jan-92 KyleP Created
  115. //
  116. //--------------------------------------------------------------------------
  117. inline CFAState::CFAState( UINT iState, BOOL fFinal )
  118. : _iState( iState ),
  119. _fFinal( fFinal )
  120. {
  121. }
  122. //+-------------------------------------------------------------------------
  123. //
  124. // Member: CFAState::Init, public
  125. //
  126. // Synopsis: Initialize a new state.
  127. //
  128. // Arguments: [iState] -- State number.
  129. //
  130. // History: 10-Jul-92 KyleP Created
  131. // 23-Jul-92 KyleP Default states to non-final.
  132. //
  133. //--------------------------------------------------------------------------
  134. inline void CFAState::Init( UINT iState )
  135. {
  136. _iState = iState;
  137. _fFinal = FALSE;
  138. }
  139. //+-------------------------------------------------------------------------
  140. //
  141. // Member: CFAState::StateNumber, public
  142. //
  143. // Returns: The state number.
  144. //
  145. // History: 20-Jan-92 KyleP Created
  146. //
  147. //--------------------------------------------------------------------------
  148. inline UINT CFAState::StateNumber() const
  149. {
  150. return( _iState );
  151. }
  152. //+-------------------------------------------------------------------------
  153. //
  154. // Member: CFAState::IsFinal, public
  155. //
  156. // Returns: TRUE if this state is a final state.
  157. //
  158. // History: 20-Jan-92 KyleP Created
  159. //
  160. //--------------------------------------------------------------------------
  161. inline BOOL CFAState::IsFinal() const
  162. {
  163. return( _fFinal );
  164. }
  165. //+-------------------------------------------------------------------------
  166. //
  167. // Member: CFAState::MakeFinal, public
  168. //
  169. // Synopsis: Indicates state is a final state.
  170. //
  171. // History: 20-Jan-92 KyleP Created
  172. //
  173. //--------------------------------------------------------------------------
  174. inline void CFAState::MakeFinal()
  175. {
  176. _fFinal = TRUE;
  177. }
  178. //+-------------------------------------------------------------------------
  179. //
  180. // Member: CNFAState::CMove::CMove, private
  181. //
  182. // Synopsis: Initializes move.
  183. //
  184. // History: 20-Jan-92 KyleP Created
  185. //
  186. //--------------------------------------------------------------------------
  187. inline CNFAState::CMove::CMove()
  188. {
  189. _symbol = symInvalid;
  190. }
  191. //+-------------------------------------------------------------------------
  192. //
  193. // Member: CNFAState::CMove::CMove, private
  194. //
  195. // Synopsis: Initializes move.
  196. //
  197. // Arguments: [symbol] -- On symbol, move to ...
  198. // [iState] -- this new state.
  199. //
  200. // History: 20-Jan-92 KyleP Created
  201. //
  202. //--------------------------------------------------------------------------
  203. inline CNFAState::CMove::CMove( UINT symbol, UINT iState )
  204. : _symbol( symbol ),
  205. _iState( iState )
  206. {
  207. }
  208. //+-------------------------------------------------------------------------
  209. //
  210. // Member: CNFAState::CNFAState, public
  211. //
  212. // Synopsis: Initialize a state (no transitions)
  213. //
  214. // History: 20-Jan-92 KyleP Created
  215. //--------------------------------------------------------------------------
  216. inline CNFAState::CNFAState()
  217. : _cMove( 0 ),
  218. _pmoveRest( 0 ),
  219. _cmoveRest( 0 )
  220. {
  221. }
  222. //+-------------------------------------------------------------------------
  223. //
  224. // Member: CNFAState::~CNFAState, public
  225. //
  226. // Effects: Clean up any spillover moves.
  227. //
  228. // History: 20-Jan-92 KyleP Created
  229. //
  230. //--------------------------------------------------------------------------
  231. inline CNFAState::~CNFAState()
  232. {
  233. delete _pmoveRest;
  234. }