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.

473 lines
13 KiB

  1. %{
  2. #include "bnparse.h"
  3. // disable warning C4102: unreferenced label
  4. #pragma warning (disable : 4102)
  5. %}
  6. %token tokenEOF 0
  7. %token tokenNil
  8. %token tokenError
  9. %token <zsr> tokenIdent tokenString
  10. %token <ui> tokenInteger
  11. %token <real> tokenReal
  12. /* key words */
  13. %token tokenArray
  14. %token tokenContinuous
  15. %token tokenCreator
  16. %token tokenDefault
  17. %token tokenDiscrete
  18. %token tokenFormat
  19. %token tokenFunction
  20. %token tokenImport
  21. %token tokenIs
  22. %token tokenKeyword
  23. %token tokenLeak
  24. %token tokenNA
  25. %token tokenName
  26. %token tokenNamed
  27. %token tokenNetwork
  28. %token tokenNode
  29. %token tokenOf
  30. %token tokenParent
  31. %token tokenPosition
  32. %token tokenProbability
  33. %token tokenProperties
  34. %token tokenProperty
  35. %token tokenPropIdent
  36. %token tokenStandard
  37. %token tokenState
  38. %token tokenType
  39. %token tokenUser
  40. %token tokenVersion
  41. %token tokenWordChoice
  42. %token tokenWordReal
  43. %token tokenWordString
  44. %token tokenAs
  45. %token tokenLevel
  46. %token tokenDomain
  47. %token tokenDistribution
  48. %token tokenDecisionGraph
  49. %token tokenBranch
  50. %token tokenOn
  51. %token tokenLeaf
  52. %token tokenVertex
  53. %token tokenMultinoulli
  54. %token tokenMerge
  55. %token tokenWith
  56. %token tokenFor
  57. %token tokenRangeOp /* ".." */
  58. %type <ui> proptype dpientry
  59. %type <integer> signedint
  60. %type <zsr> tokentoken tokenPropIdent proptypename tokenlistel
  61. %type <zsr> creator name format
  62. %type <real> real signedreal version
  63. %left '+' '-'
  64. %left '*' '/'
  65. %right '^'
  66. %left UNARY
  67. %start start
  68. %%
  69. start : { yyclearin; } bnfile
  70. ;
  71. bnfile : header blocklst
  72. ;
  73. blocklst : block
  74. | blocklst block
  75. ;
  76. block : propblock
  77. | nodeblock
  78. | probblock
  79. | domainblock
  80. | distblock
  81. | ignoreblock
  82. ;
  83. header : headerhead headerbody
  84. ;
  85. headerhead : tokenNetwork tokentoken { SetNetworkSymb($2); }
  86. | tokenNetwork
  87. ;
  88. headerbody : '{' { _eBlk = EBLKNET; }
  89. netdeclst
  90. '}' { _eBlk = EBLKNONE; }
  91. ;
  92. netdeclst : /* empty */
  93. | netdeclst netdecl
  94. ;
  95. netdecl : format { SetFormat($1); }
  96. | version { SetVersion($1); }
  97. | creator { SetCreator($1); }
  98. ;
  99. conj : ':' /* general conjunction */
  100. | '='
  101. | tokenIs
  102. ;
  103. prep : tokenWith /* general preposition */
  104. | tokenOn
  105. ;
  106. prepopt : prep /* optional preposition */
  107. | /* empty */
  108. ;
  109. /* header block productions */
  110. format : tokenFormat conj tokenString ';' { $$ = $3; }
  111. ;
  112. version : tokenVersion conj real ';' { $$ = $3; }
  113. ;
  114. creator : tokenCreator conj tokenString ';' { $$ = $3; }
  115. ;
  116. /* unrecognized block productions */
  117. ignoreblock : tokenIdent parenexpr_opt { _eBlk = EBLKIGN; WarningSkip($1); }
  118. '{'
  119. { SkipUntil("}"); }
  120. '}' { _eBlk = EBLKNONE; }
  121. ;
  122. parenexpr_opt : /* empty */
  123. | '(' { SkipUntil(")"); } ')'
  124. ;
  125. /* node block productions */
  126. nodeblock : tokenNode tokenIdent { _eBlk = EBLKNODE; StartNodeDecl($2); }
  127. '{'
  128. ndattrlst
  129. '}' { CheckNodeInfo(); _eBlk = EBLKNONE; }
  130. ;
  131. ndattrlst : /* empty */
  132. | ndattrlst ndattr ';'
  133. ;
  134. ndattr : name
  135. | type
  136. | position
  137. | property
  138. | error
  139. ;
  140. name : tokenName conj tokenString { SetNodeFullName($3); }
  141. ;
  142. type : tokenType conj tokenDiscrete statedef
  143. ;
  144. statedef : tokenDomain tokentoken { SetNodeDomain($2); }
  145. | '[' tokenInteger ']' conj_opt { SetNodeCstate($2); } states_opt
  146. ;
  147. conj_opt : /* empty */
  148. | conj
  149. ;
  150. states_opt : /* empty */
  151. | '{' { ClearCstr(); } tokenlist '}' { SetStates(); }
  152. ;
  153. tokenlist : /* empty */
  154. | tokenlistel
  155. | tokenlist ',' tokenlistel
  156. ;
  157. tokenlistel : tokentoken { AddStr($1); }
  158. ;
  159. tokentoken : tokenIdent
  160. | tokenString
  161. ;
  162. tokenList : '[' { ClearCstr(); } tokenlist ']' ;
  163. ;
  164. position : tokenPosition conj '(' signedint ',' signedint ')' { SetNodePosition($4, $6); }
  165. ;
  166. /* probability block productions */
  167. probblock : tokenProbability { _eBlk = EBLKPROB; ClearNodeInfo(); }
  168. '('
  169. tokenIdent { SetNodeSymb($4, false); }
  170. parentlst_opt
  171. ')' { CheckParentList(); }
  172. probblocktail { _eBlk = EBLKNONE; }
  173. ;
  174. /* tail of probability block: may be empty or may be a reference to a distribution */
  175. probblocktail : probblkdistref ';'
  176. | ';' { EmptyProbEntries(); }
  177. | '{'
  178. funcattr_opt
  179. { InitProbEntries(); }
  180. probentrylst
  181. { CheckProbEntries(); }
  182. '}'
  183. ;
  184. parentlst_opt : /* empty */
  185. | '|' parentlst
  186. | error
  187. ;
  188. parentlst : tokenIdent { AddSymb($1); }
  189. | parentlst ',' tokenIdent { AddSymb($3); }
  190. ;
  191. probblkdistref : conj tokenDistribution tokenIdent distplist_opt
  192. ;
  193. distplist_opt : /* empty */
  194. | '(' distplist ')'
  195. ;
  196. distplist : tokenIdent
  197. | distplist ',' tokenIdent
  198. ;
  199. funcattr_opt : /* empty */
  200. | tokenFunction conj tokenIdent ';' { CheckCIFunc($3); }
  201. ;
  202. probentrylst : /* empty */
  203. | probentrylst probentry
  204. ;
  205. probentry : dpi doproblst ';'
  206. | dpi pdf ';'
  207. ;
  208. dpi : /* empty */ { _vui.clear(); CheckDPI(false); }
  209. | '(' dodpilst ')' conj { CheckDPI(false); }
  210. | tokenDefault conj { CheckDPI(true); }
  211. ;
  212. dodpilst : { _vui.clear(); } dpilst
  213. ;
  214. dpilst : /* empty */
  215. | dpientry { AddUi($1); }
  216. | dpilst ',' dpientry { AddUi($3); }
  217. ;
  218. dpientry : tokenInteger { $$ = UiDpi($1); }
  219. | tokenIdent { $$ = UiDpi($1); }
  220. | tokenString { $$ = UiDpi($1); }
  221. ;
  222. doproblst : { _vreal.clear(); } reallst { CheckProbVector(); }
  223. ;
  224. pdf : tokenIdent '(' exprlst_opt ')' { CheckPDF($1); }
  225. ;
  226. exprlst_opt : /* empty */
  227. | exprlst
  228. ;
  229. exprlst : expr
  230. | exprlst ',' expr
  231. ;
  232. reallst : signedreal { AddReal($1); }
  233. | reallst ',' signedreal { AddReal($3); }
  234. ;
  235. signedint : '-' tokenInteger { $$ = -INT($2); }
  236. | '+' tokenInteger { $$ = +INT($2); }
  237. | tokenInteger { $$ = INT($1); }
  238. ;
  239. signedreal : '-' real { $$ = -$2; }
  240. | '+' real { $$ = $2; }
  241. | real
  242. | tokenNA { $$ = -1; }
  243. ;
  244. real : tokenReal { $$ = $1; }
  245. | tokenInteger { $$ = REAL($1); }
  246. ;
  247. expr : '(' expr ')'
  248. | expr '+' expr
  249. | expr '-' expr
  250. | expr '*' expr
  251. | expr '/' expr
  252. | expr '^' expr
  253. | tokenIdent { CheckIdent($1); }
  254. | real
  255. | tokenString
  256. | '-' expr %prec UNARY
  257. | '+' expr %prec UNARY
  258. ;
  259. /* property declarations block productions */
  260. propblock : tokenProperties
  261. '{' { StartProperties(); }
  262. propdecllst
  263. '}' { EndProperties(); }
  264. ;
  265. propdecllst : /* empty */
  266. | propdecllst propitem ';'
  267. ;
  268. propitem : propimport
  269. | propdecl
  270. | property
  271. ;
  272. propimport : tokenImport tokenStandard { ImportPropStandard(); }
  273. | tokenImport proptypename { ImportProp($2); }
  274. ;
  275. propdecl : tokenType proptypename conj proptype ',' tokenString { AddPropType($2, $4, $6); }
  276. | tokenType proptypename conj proptype { AddPropType($2, $4, ZSREF()); }
  277. ;
  278. proptype : tokenArray tokenOf tokenWordString { $$ = fPropString | fPropArray; }
  279. | tokenArray tokenOf tokenWordReal { $$ = fPropArray; }
  280. | tokenWordString { $$ = fPropString; }
  281. | tokenWordReal { $$ = 0; }
  282. | tokenWordChoice tokenOf tokenList { $$ = fPropChoice; }
  283. ;
  284. /* A duplicate property type declaration will cause a tokenIdent to be read as a tokenPropIdent */
  285. proptypename : tokenIdent /* ident not previously seen */
  286. | tokenPropIdent /* error case */
  287. ;
  288. /* property item productions */
  289. property : tokenProperty tokenPropIdent conj { ClearVpv(); } propval { CheckProperty($2); }
  290. | tokenProperty tokenIdent conj propval /* error case */
  291. | tokenPropIdent conj { ClearVpv(); } propval { CheckProperty($1); }
  292. ;
  293. propval : '[' propvallst ']'
  294. | propvalitem
  295. ;
  296. propvallst : propvalitem
  297. | propvallst ',' propvalitem
  298. ;
  299. propvalitem : tokenString { AddPropVar( $1 ); }
  300. | tokenIdent { AddPropVar( $1 ); }
  301. | signedreal { AddPropVar( $1 ); }
  302. ;
  303. /* domain declarations */
  304. domainblock : tokenDomain { ClearDomain(); }
  305. tokentoken
  306. domainbody { CheckDomain( $3 ); }
  307. ;
  308. /* array of domain specifiers */
  309. domainbody : '{' domaindeclst '}'
  310. ;
  311. domaindeclst : /* empty */
  312. | domaindec
  313. | domaindeclst ',' domaindec
  314. ;
  315. /* range followed by symbolic name or just symbolic name */
  316. domaindec : rangespec conj tokentoken { AddRange($3, false ); }
  317. | tokentoken { AddRange($1, true ); }
  318. ;
  319. /* Pascal-style range declaration */
  320. /* variants of range specifiers for open and closed intervals */
  321. /* identifiers are allowed for use with distributions where domains may be known in advance */
  322. rangespec : real tokenRangeOp real
  323. /* 0.0 .. 1.0 */ { SetRanges( true, $1, true, $3 ); }
  324. | tokentoken tokenRangeOp tokentoken
  325. /* lname .. uname */ { SetRanges( $1, $3 ); }
  326. | tokenRangeOp real
  327. /* .. 1.0 */ { SetRanges( false, 0.0, true, $2 ); }
  328. | tokenRangeOp tokentoken
  329. /* .. uname */ { SetRanges( ZSREF(), $2 ); }
  330. | real tokenRangeOp
  331. /* 0.0 .. */ { SetRanges( true, $1, false, 0.0 ); }
  332. | tokentoken tokenRangeOp
  333. /* lname .. */ { SetRanges( $1, ZSREF() ); }
  334. | real
  335. /* 0.0 */ { SetRanges( true, $1, true, $1 ); }
  336. | tokentoken
  337. /* name */ { SetRanges( $1, $1 ); }
  338. ;
  339. /* List of range specifiers */
  340. rangedeclst : '(' rangedeclset ')'
  341. ;
  342. rangedeclset : /* empty */
  343. | rangespec
  344. | rangedeclset ',' rangespec
  345. ;
  346. /* Advanced distribution declarations */
  347. /* Only "decision graph" for now */
  348. distblock : tokenDistribution /* "distribution" */
  349. tokenDecisionGraph /* "decisionGraph" */
  350. distdeclproto /* pseudo-prototype parent list */
  351. dgraphbody /* body of decision graph items */
  352. ;
  353. distdeclproto : tokentoken /* name of distribution */
  354. '('
  355. distdeclst /* pseudo-parent list */
  356. ')'
  357. ;
  358. distdeclst : /* empty */
  359. | distdecl
  360. | distdeclst ',' distdecl
  361. ;
  362. distdecl : tokenIdent tokenAs tokentoken /* pseudo-parent and domain name*/
  363. | tokenIdent /* pseudo-parent name only */
  364. ;
  365. /* Decision graph/tree item declarations */
  366. dgraphbody : '{'
  367. dgraphitemlst
  368. '}'
  369. ;
  370. dgraphitemlst : /* empty */
  371. | dgraphitem
  372. | dgraphitemlst ',' dgraphitem
  373. ;
  374. /* decision graph/tree item.
  375. Vertices and leaves may have names for later merging.
  376. Branches and merges have contraint ranges, which are lists of Pascal-style ranges;
  377. e.g. ( 3..5, 9, 10, 20.. )
  378. */
  379. dgraphitem : /* vertex */ dgitemlevel tokenVertex tokentoken dgnamed
  380. | /* branch */ dgitemlevel tokenBranch prepopt rangedeclst
  381. | /* leaf */ dgitemlevel tokenLeaf dgitemleaf dgnamed
  382. | /* merge */ dgitemlevel tokenMerge prepopt tokentoken prepopt rangedeclst
  383. ;
  384. dgitemlevel : tokenLevel tokenInteger
  385. ;
  386. dgitemleaf : tokenMultinoulli '(' reallst ')'
  387. ;
  388. /* "named" sub-clause for verticies and leaves */
  389. dgnamed : /* empty */
  390. | tokenNamed tokentoken
  391. ;
  392. %%