yy.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976
  1. /*++
  2. Copyright (c) 2015 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. yy.h
  9. Abstract:
  10. This header contains definitions for the basic Lexer/Parser library.
  11. Author:
  12. Evan Green 9-Oct-2015
  13. --*/
  14. //
  15. // ------------------------------------------------------------------- Includes
  16. //
  17. //
  18. // ---------------------------------------------------------------- Definitions
  19. //
  20. #ifndef YY_API
  21. #define YY_API __DLLIMPORT
  22. #endif
  23. //
  24. // Define lexer flags.
  25. //
  26. #define YY_LEX_FLAG_IGNORE_UNKNOWN 0x00000001
  27. //
  28. // Define parser flags.
  29. //
  30. //
  31. // Set this flag to debug print every node the parser is attempting to parser.
  32. //
  33. #define YY_PARSE_FLAG_DEBUG 0x00000001
  34. //
  35. // Set this flag to debug match successes.
  36. //
  37. #define YY_PARSE_FLAG_DEBUG_MATCHES 0x00000002
  38. //
  39. // Set this flag to debug match failures (produces a lot of output).
  40. //
  41. #define YY_PARSE_FLAG_DEBUG_NON_MATCHES 0x00000004
  42. //
  43. // Define parser grammar element flags.
  44. //
  45. //
  46. // Set this flag to replace the given element with its child node if there is
  47. // only one node and zero tokens.
  48. //
  49. #define YY_GRAMMAR_COLLAPSE_ONE 0x00000001
  50. //
  51. // Set this flag to indicate that additional matches should not be added on
  52. // the end of a left recursive rule list-style, but should instead be nested
  53. // nodes.
  54. //
  55. #define YY_GRAMMAR_NEST_LEFT_RECURSION 0x00000002
  56. //
  57. // ------------------------------------------------------ Data Type Definitions
  58. //
  59. //
  60. // LALR parser definitions.
  61. //
  62. typedef enum _YY_STATUS {
  63. YyStatusSuccess,
  64. YyStatusNoMemory,
  65. YyStatusTooManyItems,
  66. YyStatusInvalidSpecification,
  67. YyStatusInvalidParameter,
  68. YyStatusParseError,
  69. YyStatusLexError,
  70. } YY_STATUS, *PYY_STATUS;
  71. typedef SHORT YY_VALUE, *PYY_VALUE;
  72. typedef
  73. PVOID
  74. (*PYY_REALLOCATE) (
  75. PVOID Context,
  76. PVOID Allocation,
  77. UINTN Size
  78. );
  79. /*++
  80. Routine Description:
  81. This routine is called to allocate, reallocate, or free memory.
  82. Arguments:
  83. Context - Supplies a pointer to the context passed into the parser.
  84. Allocation - Supplies an optional pointer to an existing allocation to
  85. either reallocate or free. If NULL, then a new allocation is being
  86. requested.
  87. Size - Supplies the size of the allocation request, in bytes. If this is
  88. non-zero, then an allocation or reallocation is being requested. If
  89. this is is 0, then the given memory should be freed.
  90. Return Value:
  91. Returns a pointer to the allocated memory on success.
  92. NULL on allocation failure or free.
  93. --*/
  94. typedef
  95. INT
  96. (*PYY_PARSER_CALLBACK) (
  97. PVOID Context,
  98. YY_VALUE Symbol,
  99. PVOID Elements,
  100. INT ElementCount,
  101. PVOID ReducedElement
  102. );
  103. /*++
  104. Routine Description:
  105. This routine is called for each grammar element that is successfully parsed.
  106. Arguments:
  107. Context - Supplies the context pointer supplied to the parse function.
  108. Symbol - Supplies the non-terminal symbol that was reduced.
  109. Elements - Supplies a pointer to an array of values containing the child
  110. elements in the rule. The function should know how many child elements
  111. there are based on the rule.
  112. ElementCount - Supplies the number of elements in the right hand side of
  113. this rule.
  114. ReducedElement - Supplies a pointer where the function can specify the
  115. reduction value to push back on the stack. If untouched, the default
  116. action is to push the first element. When called, the buffer will be
  117. set up for that, or zeroed if the rule is empty.
  118. Return Value:
  119. 0 on success.
  120. Returns a non-zero value if the parser should abort and return.
  121. --*/
  122. typedef
  123. YY_STATUS
  124. (*PYY_PARSER_ERROR) (
  125. PVOID Context,
  126. YY_STATUS Status
  127. );
  128. /*++
  129. Routine Description:
  130. This routine is called if the parser reaches an error state.
  131. Arguments:
  132. Context - Supplies the context pointer supplied to the parse function.
  133. Status - Supplies the error that occurred, probably a parse error.
  134. Return Value:
  135. 0 if the parser should try to recover.
  136. Returns a non-zero value if the parser should abort immediately and return.
  137. --*/
  138. typedef
  139. INT
  140. (*PYY_PARSER_GET_TOKEN) (
  141. PVOID Lexer,
  142. PYY_VALUE Value
  143. );
  144. /*++
  145. Routine Description:
  146. This routine is called to get a new token from the input.
  147. Arguments:
  148. Lexer - Supplies a pointer to the lexer context.
  149. Value - Supplies a pointer where the new token will be returned. The token
  150. data may be larger than simply a value, but it returns at least a
  151. value.
  152. Return Value:
  153. 0 on success, including EOF.
  154. Returns a non-zero value if there was an error reading the token.
  155. --*/
  156. /*++
  157. Structure Description:
  158. This structure stores a compiled grammar definition. These tables are
  159. machine generated by the yygen library.
  160. Members:
  161. LeftSide - Stores a pointer to an array of the left side symbol of each
  162. rule.
  163. Length - Stores a pointer to an array that describes how many elements are
  164. in each rule.
  165. DefaultReductions - Stores a pointer to an array of states to reduce to
  166. automatically.
  167. ShiftIndex - Stores an array of pointers indexed by state into the giant
  168. table of state transitions.
  169. ReduceIndex - Stores an array of pointers index by state into the giant
  170. table of state transitions.
  171. GotoIndex - Stores the goto array.
  172. Table - Stores the giant serialized table of state transitions to make.
  173. Check - Stores the giant serialized table of source states or shift symbols
  174. corresponding to each element in the table.
  175. DefaultGotos - Stores the condensed table of the most common goto for each
  176. state, which helps reduce the size of the goto table.
  177. TableSize - Stores the maximum valid element index in the table. (This
  178. index is inclusive).
  179. Names - Stores an array of strings containing the name of each terminal and
  180. non-terminal.
  181. Rules - Stores an array of strings describing each rule.
  182. FinalState - Stores the accept state index.
  183. FinalSymbol - Stores the symbol whose receipt indicates acceptance (ie can
  184. be followed by EOF).
  185. MaxToken - Stores the number of terminals in the grammar.
  186. UndefinedToken - Stores the token value in the names array that corresponds
  187. to an undefined token.
  188. --*/
  189. typedef struct _YY_GRAMMAR {
  190. const YY_VALUE *LeftSide;
  191. const YY_VALUE *RuleLength;
  192. const YY_VALUE *DefaultReductions;
  193. const YY_VALUE *ShiftIndex;
  194. const YY_VALUE *ReduceIndex;
  195. const YY_VALUE *GotoIndex;
  196. const YY_VALUE *Table;
  197. const YY_VALUE *Check;
  198. const YY_VALUE *DefaultGotos;
  199. YY_VALUE TableSize;
  200. const char **Names;
  201. const char **Rules;
  202. YY_VALUE FinalState;
  203. YY_VALUE FinalSymbol;
  204. YY_VALUE MaxToken;
  205. YY_VALUE UndefinedToken;
  206. } YY_GRAMMAR, *PYY_GRAMMAR;
  207. /*++
  208. Structure Description:
  209. This structure stores the context for an LALR(1) parser.
  210. Members:
  211. Grammar - Stores a pointer to the compiled grammar data. The yygen
  212. library should be used at build time to create this data.
  213. Reallocate - Stores a pointer to a function used to allocate, reallocate,
  214. and free memory from the heap.
  215. Callback - Stores a pointer to a function to call for each new grammar
  216. symbol parsed.
  217. Error - Stores a pointer to a function to call if the parser hits an error.
  218. Context - Stores a pointer to blindly pass into the callback function.
  219. Lexer - Stores a pointer to the initialized lexer, ready to emit tokens.
  220. GetToken - Stores a pointer to a function used to get the next lexer
  221. token.
  222. ValueSize - Stores the size in bytes of a single token or symbol. This
  223. must be at least as large as a YY_VALUE.
  224. ErrorCount - Stores the number of parsing errors that occured.
  225. Debug - Stores a boolean indicating whether or not to enable debug prints
  226. on the parser.
  227. DebugPrefix - Stores the prefix to prepend to every debug print within the
  228. parser. If this is non-null, debug prints are enabled for the parser.
  229. --*/
  230. typedef struct _YY_PARSER {
  231. PYY_GRAMMAR Grammar;
  232. PYY_REALLOCATE Reallocate;
  233. PYY_PARSER_CALLBACK Callback;
  234. PYY_PARSER_ERROR Error;
  235. PVOID Context;
  236. PVOID Lexer;
  237. PYY_PARSER_GET_TOKEN GetToken;
  238. UINTN ValueSize;
  239. UINTN ErrorCount;
  240. PSTR DebugPrefix;
  241. } YY_PARSER, *PYY_PARSER;
  242. //
  243. // Lexer definitions
  244. //
  245. /*++
  246. Structure Description:
  247. This structure stores the state for the lexer. To initialize this, zero it
  248. out.
  249. Members:
  250. Flags - Stores a bitfield of flags governing the lexer behavior. See
  251. YY_LEX_FLAG_* definitions.
  252. Allocate - Stores a pointer to a function used to allocate memory.
  253. Free - Stores a pointer to a function used to free allocated memory.
  254. Input - Stores the input buffer to lex.
  255. InputSize - Stores the size of the input buffer in bytes, including the
  256. null terminator if present.
  257. Position - Stores the current character position.
  258. Line - Stores the current one-based line number.
  259. Column - Stores the zero-based column number.
  260. TokenCount - Stores the number of tokens processed so far.
  261. LargestToken - Stores the size member of the largest single token seen so
  262. far. Note that this does not include space for a null terminator.
  263. TokenStringsSize - Stores the total number of bytes to allocate for strings
  264. for all tokens seen so far, including a null terminator on each one.
  265. Literals - Stores a pointer to a null-terminated string containing
  266. characters to pass through literally as individual tokens.
  267. Expressions - Stores an array of expression strings to match against. This
  268. must be terminated by a NULL entry.
  269. IgnoreExpressions - Stores an array of expression strings that should not
  270. produce tokens if they match. This is a place to put things like
  271. comment expressions.
  272. ExpressionNames - Stores an optional pointer to an array of strings that
  273. names each of the expressions. Useful for debugging, but not mandatory.
  274. TokenBase - Stores the value to assign for the first expression. 512 is
  275. usually a good value, as it won't alias with the literal characters.
  276. --*/
  277. typedef struct _LEXER {
  278. ULONG Flags;
  279. PCSTR Input;
  280. ULONG InputSize;
  281. ULONG Position;
  282. ULONG Line;
  283. ULONG Column;
  284. ULONG TokenCount;
  285. ULONG LargestToken;
  286. ULONG TokenStringsSize;
  287. PSTR Literals;
  288. PSTR *Expressions;
  289. PSTR *IgnoreExpressions;
  290. PSTR *ExpressionNames;
  291. ULONG TokenBase;
  292. } LEXER, *PLEXER;
  293. /*++
  294. Structure Description:
  295. This structure stores a lexer token.
  296. Members:
  297. Value - Stores the lexer token value. This may be a literal byte or a
  298. token value.
  299. Position - Stores the position of the token.
  300. Size - Stores the number of characters in the token.
  301. Line - Stores the line number of start of the token.
  302. Column - Stores the column number of the start of the token.
  303. String - Stores a pointer to the string of input text this token
  304. corresponds to. The lexer does not fill this out, but the member is
  305. provided here for convenience.
  306. --*/
  307. typedef struct _LEXER_TOKEN {
  308. ULONG Value;
  309. ULONG Position;
  310. ULONG Size;
  311. ULONG Line;
  312. ULONG Column;
  313. PSTR String;
  314. } LEXER_TOKEN, *PLEXER_TOKEN;
  315. //
  316. // Parser definitions
  317. //
  318. typedef struct _PARSER_NODE PARSER_NODE, *PPARSER_NODE;
  319. typedef
  320. PVOID
  321. (*PYY_ALLOCATE) (
  322. UINTN Size
  323. );
  324. /*++
  325. Routine Description:
  326. This routine is called when the lex/parse library needs to allocate memory.
  327. Arguments:
  328. Size - Supplies the size of the allocation request, in bytes.
  329. Return Value:
  330. Returns a pointer to the allocation if successful, or NULL if the
  331. allocation failed.
  332. --*/
  333. typedef
  334. VOID
  335. (*PYY_FREE) (
  336. PVOID Memory
  337. );
  338. /*++
  339. Routine Description:
  340. This routine is called when the lex/parse library needs to free allocated
  341. memory.
  342. Arguments:
  343. Memory - Supplies the allocation returned by the allocation routine.
  344. Return Value:
  345. None.
  346. --*/
  347. typedef
  348. KSTATUS
  349. (*PYY_GET_TOKEN) (
  350. PVOID Context,
  351. PLEXER_TOKEN Token
  352. );
  353. /*++
  354. Routine Description:
  355. This routine gets the next token for the parser.
  356. Arguments:
  357. Context - Supplies a context pointer initialized in the parser.
  358. Token - Supplies a pointer where the next token will be filled out and
  359. returned.
  360. Return Value:
  361. STATUS_SUCCESS on success.
  362. STATUS_END_OF_FILE if the file end was reached.
  363. STATUS_MALFORMED_DATA_STREAM if the given input matched no rule in the
  364. lexer and the lexer was not configured to ignore such things.
  365. --*/
  366. typedef
  367. VOID
  368. (*PYY_NODE_CALLBACK) (
  369. PVOID Context,
  370. PPARSER_NODE Node,
  371. BOOL Create
  372. );
  373. /*++
  374. Routine Description:
  375. This routine is called when a node is being created or destroyed. This
  376. callback must be prepared to create and destroy a node multiple times, as
  377. recursive descent parsers explore paths that ultimately prove to be
  378. incorrect. Unless the parser feeds back into the lexer (like in C), it is
  379. not recommended to use this callback.
  380. Arguments:
  381. Context - Supplies a context pointer initialized in the parser.
  382. Node - Supplies a pointer to the node being created or destroyed.
  383. Create - Supplies a boolean indicating if the node is being created (TRUE)
  384. or destroyed (FALSE).
  385. Return Value:
  386. None.
  387. --*/
  388. /*++
  389. Structure Description:
  390. This structure defines a grammar element in the parser grammar.
  391. Members:
  392. Name - Stores an optional pointer to the name of this grammar element. This
  393. is not used during parsing, but can be useful during debugging.
  394. Flags - Stores a bitfield of flags about this node. See YY_GRAMMAR_*
  395. definitions.
  396. Components - Stores a sequence of rule elements. Each element is either a
  397. token value or a rule value, determined by the grammar base and grammar
  398. end values in the parser. Each form of a grammar expression is
  399. terminated by a zero value. The next alternate form starts after the
  400. zero. Terminate the sequence with an additional zero to end the
  401. node form.
  402. --*/
  403. typedef struct _PARSER_GRAMMAR_ELEMENT {
  404. PSTR Name;
  405. ULONG Flags;
  406. PULONG Components;
  407. } PARSER_GRAMMAR_ELEMENT, *PPARSER_GRAMMAR_ELEMENT;
  408. /*++
  409. Structure Description:
  410. This structure stores a parsed node.
  411. Members:
  412. GrammarElement - Stores the type of grammar element this node represents.
  413. GrammarIndex - Stores the index of the rule that applied for this grammar
  414. node.
  415. StartToken - Stores a pointer to the token where parsing of this node began.
  416. Tokens - Stores a pointer to the tokens in the node.
  417. Nodes - Stores a pointer to the child nodes in the node. In the free list,
  418. the first element stores the pointer to the next element in the free
  419. list.
  420. TokenCount - Stores the number of valid tokens in the token array.
  421. NodeCount - Stores the number of vaild nodes in the node array.
  422. TokenCapacity - Stores the maximum number of tokens the array can store
  423. before it must be reallocated.
  424. NodeCapacity - Stores the maximum number of nodes the array can store
  425. before it must be reallocated.
  426. --*/
  427. struct _PARSER_NODE {
  428. ULONG GrammarElement;
  429. ULONG GrammarIndex;
  430. PLEXER_TOKEN StartToken;
  431. PLEXER_TOKEN *Tokens;
  432. PPARSER_NODE *Nodes;
  433. ULONG TokenCount;
  434. ULONG NodeCount;
  435. ULONG TokenCapacity;
  436. ULONG NodeCapacity;
  437. };
  438. /*++
  439. Structure Description:
  440. This structure stores the state for the parser. To initialize this, zero it
  441. out and call the initialize function.
  442. Members:
  443. Flags - Stores a bitfield of flags governing the lexer behavior. See
  444. YY_LEX_FLAG_* definitions.
  445. Context - Stores a context pointer that is passed to the get token function.
  446. Allocate - Stores a pointer to a function used allocate memory.
  447. Free - Stores a pointer to a function used to free memory.
  448. GetToken - Stores a pointer to a function used to get the next lexical
  449. token.
  450. NodeCallback - Stores an optional pointer to a function called when nodes
  451. are created or destroyed. Note that this callback needs to be prepared
  452. to create and destroy nodes potentially multiple times, as recursive
  453. descent parsers explore paths that may ultimately not be correct. Use
  454. of this callback is not recommended unless required (for languages like
  455. C where the parser feeds back into the lexer).
  456. Grammar - Stores a pointer to the grammar, which is defined as an array
  457. of grammar elements.
  458. GrammarBase - Stores the start of the range of component values that
  459. specify grammar elements themselves.
  460. GrammarEnd - Stores the end index of grammar elements, exclusive.
  461. Every rule component outside the range of grammar base to grammar size
  462. is assumed to be a lexer token.
  463. GrammarStart - Stores the starting element to parse.
  464. MaxRecursion - Stores the maximum allowed recursion depth. Supply 0 to
  465. allow infinite recursion.
  466. Lexer - Stores an optional pointer to the lexer, which can be used to print
  467. token names during debug.
  468. TokenArrays - Stores a pointer to an array of ever-doubling arrays of
  469. lexer tokens.
  470. TokenCount - Stores the total number of tokens stored in the token arrays.
  471. TokenCapacity - Stores the total number of tokens that can fit in the
  472. arrays before they will need to be resized.
  473. NextTokenIndex - Stores the next token index to process.
  474. NextToken - Stores a pointer to the next token, for fast access.
  475. FreeNodes - Stores a pointer to the singly linked list of free nodes.
  476. RecursionDepth - Stores the current recursion depth.
  477. --*/
  478. typedef struct _PARSER {
  479. ULONG Flags;
  480. PVOID Context;
  481. PYY_ALLOCATE Allocate;
  482. PYY_FREE Free;
  483. PYY_GET_TOKEN GetToken;
  484. PYY_NODE_CALLBACK NodeCallback;
  485. PARSER_GRAMMAR_ELEMENT *Grammar;
  486. ULONG GrammarBase;
  487. ULONG GrammarEnd;
  488. ULONG GrammarStart;
  489. ULONG MaxRecursion;
  490. PLEXER Lexer;
  491. PLEXER_TOKEN *TokenArrays;
  492. ULONG TokenCount;
  493. ULONG TokenCapacity;
  494. ULONG NextTokenIndex;
  495. PLEXER_TOKEN NextToken;
  496. PPARSER_NODE FreeNodes;
  497. ULONG RecursionDepth;
  498. } PARSER, *PPARSER;
  499. //
  500. // -------------------------------------------------------------------- Globals
  501. //
  502. //
  503. // -------------------------------------------------------- Function Prototypes
  504. //
  505. //
  506. // LALR parser functions.
  507. //
  508. YY_API
  509. YY_STATUS
  510. YyParseGrammar (
  511. PYY_PARSER Parser
  512. );
  513. /*++
  514. Routine Description:
  515. This routine parses input according to an LALR(1) compiled grammar.
  516. Arguments:
  517. Parser - Supplies a pointer to the initialized parser context.
  518. Return Value:
  519. 0 on success.
  520. Returns a non-zero value if the parsing failed, the lexer failed, or the
  521. callback failed.
  522. --*/
  523. //
  524. // Lexer functions
  525. //
  526. YY_API
  527. KSTATUS
  528. YyLexInitialize (
  529. PLEXER Lexer
  530. );
  531. /*++
  532. Routine Description:
  533. This routine initializes a lexer.
  534. Arguments:
  535. Lexer - Supplies a pointer to the lexer to initialize.
  536. Return Value:
  537. STATUS_SUCCESS on success.
  538. STATUS_INVALID_PARAMETER if the required fields of the lexer are not filled
  539. in.
  540. --*/
  541. YY_API
  542. KSTATUS
  543. YyLexGetToken (
  544. PLEXER Lexer,
  545. PLEXER_TOKEN Token
  546. );
  547. /*++
  548. Routine Description:
  549. This routine gets the next token from the lexer.
  550. Arguments:
  551. Lexer - Supplies a pointer to the lexer.
  552. Token - Supplies a pointer where the next token will be filled out and
  553. returned.
  554. Return Value:
  555. STATUS_SUCCESS on success.
  556. STATUS_END_OF_FILE if the file end was reached.
  557. STATUS_MALFORMED_DATA_STREAM if the given input matched no rule in the
  558. lexer and the lexer was not configured to ignore such things.
  559. --*/
  560. //
  561. // Parser functions
  562. //
  563. YY_API
  564. KSTATUS
  565. YyParserInitialize (
  566. PPARSER Parser
  567. );
  568. /*++
  569. Routine Description:
  570. This routine initializes a parser. This routine assumes the parser was
  571. initially zeroed out, and is currently being initialized or reset after use.
  572. Arguments:
  573. Parser - Supplies a pointer to the parser to initialize.
  574. Return Value:
  575. STATUS_SUCCESS on success.
  576. STATUS_INVALID_PARAMETER if the required fields of the lexer are not filled
  577. in.
  578. --*/
  579. YY_API
  580. VOID
  581. YyParserReset (
  582. PPARSER Parser
  583. );
  584. /*++
  585. Routine Description:
  586. This routine resets a parser, causing it to return to its initial state but
  587. not forget the tokens it has seen.
  588. Arguments:
  589. Parser - Supplies a pointer to the parser to reset.
  590. Return Value:
  591. None.
  592. --*/
  593. YY_API
  594. VOID
  595. YyParserDestroy (
  596. PPARSER Parser
  597. );
  598. /*++
  599. Routine Description:
  600. This routine frees all the resources associated with a given parser.
  601. Arguments:
  602. Parser - Supplies a pointer to the parser.
  603. Return Value:
  604. None.
  605. --*/
  606. YY_API
  607. KSTATUS
  608. YyParse (
  609. PPARSER Parser,
  610. PPARSER_NODE *Tree
  611. );
  612. /*++
  613. Routine Description:
  614. This routine attempts to parse input grammatically based on a set of
  615. grammar rules and lexer input tokens. It will build an abstract syntax
  616. tree, which will be returned as a node.
  617. Arguments:
  618. Parser - Supplies a pointer to the parser. The caller must have filled in
  619. the grammar rules and support function pointers.
  620. Tree - Supplies a pointer where the abstract syntax tree will be returned.
  621. Return Value:
  622. STATUS_SUCCESS on success.
  623. STATUS_INSUFFICIENT_RESOURCES on allocation failure.
  624. STATUS_INVALID_SEQUENCE upon parse failure.
  625. Other errors on other failures (such as lexer errors).
  626. --*/
  627. YY_API
  628. VOID
  629. YyDestroyNode (
  630. PPARSER Parser,
  631. PPARSER_NODE Node
  632. );
  633. /*++
  634. Routine Description:
  635. This routine destroys a parser node.
  636. Arguments:
  637. Parser - Supplies a pointer to the parser.
  638. Node - Supplies a pointer to the node to destroy.
  639. Return Value:
  640. None.
  641. --*/