Next: , Previous: , Up: Parser C-Language Interface   [Contents][Index]


4.2 Push Parser Interface

You call the function yypstate_new to create a new parser instance. This function is available if either the ‘%define api.push-pull push’ or ‘%define api.push-pull both’ declaration is used. See A Push Parser.

Function: yypstate* yypstate_new (void)

Return a valid parser instance if there is memory available, 0 otherwise. In impure mode, it will also return 0 if a parser instance is currently allocated.

You call the function yypstate_delete to delete a parser instance. function is available if either the ‘%define api.push-pull push’ or ‘%define api.push-pull both’ declaration is used. See A Push Parser.

Function: void yypstate_delete (yypstate *yyps)

Reclaim the memory associated with a parser instance. After this call, you should no longer attempt to use the parser instance.

You call the function yypush_parse to parse a single token. This function is available if either the ‘%define api.push-pull push’ or ‘%define api.push-pull both’ declaration is used. See A Push Parser.

Function: int yypush_parse (yypstate *yyps)

The value returned by yypush_parse is the same as for yyparse with the following exception: it returns YYPUSH_MORE if more input is required to finish parsing the grammar.

After yypush_parse returned, the instance may be consulted. For instance check yynerrs to see whether there were (possibly recovered) syntax errors.

After yypush_parse returns a status other than YYPUSH_MORE, the parser instance yyps may be reused for a new parse.

The fact that the parser state is reusable even after an error simplifies reuse. For example, a calculator application which parses each input line as an expression can just keep reusing the same yyps even if an input was invalid.

You call the function yypull_parse to parse the rest of the input stream. This function is available if the ‘%define api.push-pull both’ declaration is used. See A Push Parser.

Function: int yypull_parse (yypstate *yyps)

The value returned by yypull_parse is the same as for yyparse.

The parser instance yyps may be reused for new parses.

Function: int yypstate_expected_tokens (const yypstate *yyps, yysymbol_kind_t argv[], int argc)

Fill argv with the expected tokens, which never includes YYSYMBOL_YYEMPTY, YYSYMBOL_YYerror, or YYSYMBOL_YYUNDEF.

Never put more than argc elements into argv, and on success return the number of tokens stored in argv. If there are more expected tokens than argc, fill argv up to argc and return 0. If there are no expected tokens, also return 0, but set argv[0] to YYSYMBOL_YYEMPTY.

When LAC is enabled, may return a negative number on errors, such as YYENOMEM on memory exhaustion.

If argv is null, return the size needed to store all the possible values, which is always less than YYNTOKENS.


Next: The Lexical Analyzer Function yylex, Previous: The Parser Function yyparse, Up: Parser C-Language Interface   [Contents][Index]