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.

274 lines
8.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1997
  6. //
  7. // File: bnparse.h
  8. //
  9. //--------------------------------------------------------------------------
  10. //
  11. // BNPARSE.H
  12. //
  13. #ifndef _BNPARSE_H_
  14. #define _BNPARSE_H_
  15. #include "symtmbn.h" // Symbol table defs
  16. #include "parser.h" // Generated YACC parser header
  17. #include "gmobj.h" // Graphical model object defs
  18. #include "parsfile.h" // Parser file stream thunks
  19. #include "domain.h" // Named domains
  20. #include "tchar.h"
  21. typedef vector<CHAR> VTCHAR;
  22. class DSCPARSER; // The parser
  23. class BNDIST; // A probability distribution
  24. #define YYSTATIC static
  25. #define YYVGLOBAL // Make parse stack "yyv" (only) global, not static
  26. // Manifests to map YACC elements to class DSCPARSER
  27. #define yyparse DSCPARSER::YaccParse
  28. #define YYPARSER DSCPARSER::YaccParse
  29. #define YYLEX TokenNext
  30. #define yylex TokenNext
  31. #define yyerror SyntaxError
  32. #define YYMAXDEPTH 150
  33. struct YYSTYPE
  34. {
  35. union {
  36. UINT ui;
  37. INT integer;
  38. REAL real;
  39. };
  40. ZSREF zsr;
  41. };
  42. extern YYSTYPE yylval, yyval;
  43. extern YYSTYPE yyv[YYMAXDEPTH];
  44. struct PROPVAR
  45. {
  46. enum ETYPE { ETPV_NONE, ETPV_STR, ETPV_REAL } _eType;
  47. ZSREF _zsref; // String
  48. REAL _r; // Real value
  49. PROPVAR ()
  50. : _eType( ETPV_NONE )
  51. {}
  52. PROPVAR ( ZSREF zsr )
  53. : _eType(ETPV_STR),
  54. _r(0.0)
  55. {
  56. _zsref = zsr;
  57. }
  58. PROPVAR ( GOBJMBN * pbnobj )
  59. : _eType(ETPV_STR),
  60. _r(0.0)
  61. {
  62. _zsref = pbnobj->ZsrefName();
  63. }
  64. PROPVAR ( REAL & r )
  65. : _eType(ETPV_REAL),
  66. _r(r)
  67. {}
  68. bool operator == ( const PROPVAR & bnp ) const;
  69. bool operator != ( const PROPVAR & bnp ) const;
  70. bool operator < ( const PROPVAR & bnp ) const;
  71. bool operator > ( const PROPVAR & bnp ) const;
  72. };
  73. // Define VPROPVAR
  74. DEFINEV(PROPVAR);
  75. enum SDPI // status of discrete parent instantiation
  76. {
  77. sdpiAbsent, sdpiPresent, sdpiNotNeeded,
  78. };
  79. DEFINEV(SDPI);
  80. class DSCPARSER
  81. {
  82. protected:
  83. enum
  84. {
  85. _cchTokenMax = 256,
  86. _cstrMax = _cchTokenMax,
  87. _crealMax = _cstrMax,
  88. _csymbMax = 32,
  89. _cuiMax = _csymbMax
  90. };
  91. enum EBLKTYPE
  92. {
  93. EBLKNONE, // No block
  94. EBLKNET, // Network block
  95. EBLKPROP, // Properties block
  96. EBLKNODE, // Node block
  97. EBLKPROB, // Probabilities block
  98. EBLKDOM, // Domain block
  99. EBLKDIST, // Distribution block
  100. EBLKIGN, // Ignore block
  101. };
  102. public:
  103. DSCPARSER ( MBNET & mbnet,
  104. PARSIN & flpIn,
  105. PARSOUT & flpOut );
  106. ~ DSCPARSER ();
  107. // Open the target file
  108. bool BInitOpen(SZC szcFile);
  109. // Parse it; return tallies of errors and warnings
  110. bool BParse ( UINT & cError, UINT & cWarning );
  111. // Return the network being built
  112. MBNET & Mbnet ()
  113. { return _mbnet ; }
  114. protected:
  115. MPSYMTBL & Mpsymtbl () { return _mbnet.Mpsymtbl(); }
  116. MPPD & Mppd () { return _mbnet.Mppd(); }
  117. // Parsing function (in PARSER.Y/PARSER.CPP)
  118. INT YaccParse();
  119. // Parsing functions
  120. GNODEMBND* PgndbnAdd(ZSREF zsr);
  121. void AddSymb(ZSREF zsr);
  122. void AddStr(ZSREF zsr);
  123. void AddPropVar (ZSREF zsr);
  124. void AddPropVar (REAL & r);
  125. void AddPv ( PROPVAR & pv );
  126. void AddUi(UINT ui);
  127. void AddReal(REAL real);
  128. UINT UiDpi(ZSREF zsr);
  129. UINT UiDpi(UINT ui);
  130. void SetNodeFullName(ZSREF zsr);
  131. void SetNodePosition( int x, int y );
  132. void SetCreator(ZSREF zsr);
  133. void SetFormat(ZSREF zsr);
  134. void SetVersion(REAL r);
  135. void SetNetworkSymb(ZSREF zsr);
  136. void ClearNodeInfo();
  137. void SetNodeSymb(ZSREF zsr, bool bNew);
  138. void StartNodeDecl(ZSREF zsr);
  139. void CheckNodeInfo();
  140. void SetNodeCstate(UINT cstate);
  141. void CheckParentList();
  142. void CheckProbVector();
  143. void InitProbEntries();
  144. void CheckProbEntries();
  145. void EmptyProbEntries();
  146. void CheckCIFunc(ZSREF zsr);
  147. void CheckDPI(bool bDefault);
  148. void AddPropType(ZSREF zsrName, UINT fType, ZSREF zsrComment);
  149. void ImportPropStandard();
  150. void ImportProp(ZSREF zsrName);
  151. void ClearCstr();
  152. void ClearVpv();
  153. void CheckProperty( ZSREF zsrName );
  154. void StartProperties();
  155. void EndProperties();
  156. void SetStates();
  157. void CheckDomain(ZSREF zsr);
  158. void ClearDomain();
  159. void SetRanges( bool bLower, REAL rLower, bool bUpper, REAL rUpper);
  160. void SetRanges( ZSREF zsrLower, ZSREF zsrUpper);
  161. void AddRange( ZSREF zsr, bool bSingleton = false );
  162. void SetNodeDomain( ZSREF zsr );
  163. //NYI START
  164. void CheckPDF(ZSREF zsr);
  165. void CheckIdent( ZSREF zsr );
  166. //NYI END
  167. // Lexing functions
  168. TOKEN TokenKeyword();
  169. TOKEN TokenNext();
  170. TOKEN TokenNextBasic();
  171. SZC SzcToken() { return & _vchToken[0]; }
  172. void Warning(SZC szcFormat, ...);
  173. void Error(SZC szcFormat, ...);
  174. void ErrorWarn( bool bErr, SZC szcFormat, va_list & valist );
  175. void ErrorWarn(bool bErr, SZC szcFormat, ...);
  176. void ErrorWarnNode(bool bErr, SZC szcFormat, ...);
  177. void WarningSkip ( ZSREF zsrBlockName );
  178. bool BChNext();
  179. void SkipWS();
  180. void SkipToEOL();
  181. void AddChar ( TCHAR tch = 0 );
  182. void AddCharStr ( TCHAR tch = 0 );
  183. char ChEscape();
  184. void CloseToken(SZC szcTokenType);
  185. void CloseIdentifier();
  186. GOBJMBN * PbnobjFind ( SZC szcName );
  187. GNODEMBND * PgndbnFind ( SZC szcName );
  188. void SkipUntil(SZC szcStop, bool bDidLookAhead = false);
  189. void SyntaxError(SZC szcError);
  190. void ReportNYI (SZC szcWhich);
  191. void PrintDPI ( UINT idpi );
  192. void ResetParser ();
  193. // Return true if current node and its distribution are valid
  194. bool BNodeProbOK () const
  195. { return _pnode != NULL && _refbndist.BRef(); }
  196. // Return the current distribution reference
  197. REFBNDIST & RefBndist ()
  198. { return _refbndist; }
  199. // Allocate and identify a new distribution
  200. void CreateBndist ( const VTKNPD & vtknpd, const VIMD & vimdDim );
  201. protected:
  202. // Parsing and lexing control variables
  203. PARSIN & _flpIn; // Input stream
  204. PARSOUT & _flpOut; // Output Stream
  205. char _chCur; // Last character read
  206. char _chUnget; // Pushed-back character (if != 0)
  207. VTCHAR _vchToken; // The current token being built
  208. UINT _cchToken; // Length of token
  209. UINT _iLine; // Line number
  210. UINT _cError; // Error count
  211. UINT _cWarning; // Warning count
  212. UINT _cerrorNode; // Number of errors for current node
  213. TOKEN _tokenCur; // Current token
  214. bool _bUngetToken; // Return current token again?
  215. // Semantic variables
  216. MBNET & _mbnet; // The belief network
  217. GNODEMBND* _pnode; // Current node
  218. BNDIST::EDIST _edist; // Type of distribution
  219. REFBNDIST _refbndist; // Current distribution for the node
  220. VIMD _vimdDim; // Dimensions for dense prob table
  221. UINT _cdpi; // Number of discrete parent instantiations
  222. VSDPI _vsdpi; // Checks discrete parent instantiations
  223. UINT _cui; // DPI checking
  224. INT _idpi; // Number of unprefixed DPIs seen
  225. INT _idpiLast; // Ptable index of last DPI seen
  226. bool _bCI; // Causally independent CPT
  227. bool _bDefault; // Does CPT have have a default entry
  228. bool _bPropDefs; // File had private property definitions
  229. INT _cNode; // Count of node declarations seen
  230. VZSREF _vzsrParent; // Parents of the node
  231. EBLKTYPE _eBlk; // Type of block being parsed
  232. VUINT _vui; // Storage for arrays of integers
  233. VREAL _vreal; // Storage for arrays of reals
  234. VZSREF _vzsr; // Storage for arrays of strings
  235. VPROPVAR _vpv; // Storage for PROPVARs
  236. PROPMGR * _ppropMgr; // Property manager
  237. ESTDLBL _elbl; // Node label
  238. RDOMAIN _domain; // Domain list for domain declarations
  239. RANGELIM _rlimLower; // Lower bound of domain subrange
  240. RANGELIM _rlimUpper; // Upper bound of domain subrange
  241. INT _ilimNext; // Last upper bound given
  242. };
  243. #endif