1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
The following members can be used by members of parser classes generated
by bic(). When prefixed by tt(Base::) they are actually protected members
inherited from the parser's base class. These members are shown
below. Following the description of those members several more are listed:
those members are used during the parsing process, andshould not be modified
or masked by user-defined code.
itemization(
it() bf(void Base::ABORT() const throw(Return_)):nl()
This member can be called from any member function (called from any of
the parser's action blocks) to indicate a failure while parsing thus
terminating the parsing function with an error value 1. Note that this
offers a marked extension and improvement of the macro tt(YYABORT)
defined by bf(bison++) in that tt(YYABORT) could not be called from
outside of the parsing member function.
it() bf(void Base::ACCEPT() const throw(Return_)):nl()
This member can be called from any member function (called from any of
the parser's action blocks) to indicate successful parsing and thus
terminating the parsing function. Note that this offers a marked
extension and improvement of the macro tt(YYACCEPT) defined by
bf(bison++) in that tt(YYACCEPT) could not be called from outside of
the parsing member function.
it() bf(void Base::ERROR+nop()() const throw(ErrorRecovery_)):nl()
This member can be called from any member function (called from any of
the parser's action blocks) to generate an error, and results in the
parser executing its error recovery code. Note that this offers a
marked extension and improvement of the macro tt(YYERROR) defined by
bf(bison++) in that tt(YYERROR) could not be called from outside of
the parsing member function.
it() bf(void error()):nl()
By default implemented inline in the tt(parser.ih) internal header file,
it writes a simple message to the standard error stream. It is called
when a syntactic error is encountered, and its default implementation
may safely be altered.
it() bf(void exceptionHandler(std::exception const &exc)):nl()
This member's default implementation is provided inline in the
tt(parser.ih) internal header file. It consists of a mere tt(throw)
statement, rethrowing a caught exception.
The tt(parse) member function's body essentially consists of a
tt(while) statement, in which the next token is obtained via the
parser's tt(lex) member. This token is then processed according to the
current state of the parsing process. This may result in executing
actions over which the parsing process has no control and which may
result in exceptions being thrown.
Such exceptions do not necessarily have to terminate the parsing
process: they could be thrown by code, linked to the parser, that
simply checks for semantic errors (like divisions by zero)
throwing exceptions if such errors are observed.
The member tt(exceptionHandler) receives and may handle such
exceptions without necessarily ending the parsing process. It receives
any tt(std::exception) thrown by the parser's actions, as though the
action block itself was surrounded by a tt(try ... catch) statement.
It is of course still possible to use an explicit tt(try ... catch)
statement within action blocks. However, tt(exceptionHandler) can
be used to factor out code that is common to various action blocks.
The next example shows an explicit implementation of
tt(exceptionHandler): any tt(std::exception) thrown by the parser's
action blocks is caught, showing the exception's message, and
increasing the parser's error count. After this parsing continues as
if no exception had been thrown:
verb(
void Parser::exceptionHandler(std::exception const &exc)
{
std::cout << exc.what() << '\n';
++d_nErrors_;
}
)
it() bf(int lex()):nl()
By default implemented inline in the tt(parser.ih) internal header file,
it can be pre-implemented by bic() using the tt(scanner) option or
directive (see above); alternatively it em(must) be implemented by the
programmer. It interfaces to the lexical scanner, and should return the
next token produced by the lexical scanner, either as a plain character
or as one of the symbolic tokens defined in the tt(Parser::Tokens_)
enumeration. Zero or negative token values are interpreted as `end of
input'.
it() bf(void print()):nl()
By default implemented inline in the tt(parser.ih) internal header file,
this member calls tt(print_) to display the last received token and
corresponding matched text. The tt(print_) member is only implemented
if the tt(--print-tokens) option or tt(%print-tokens) directive was
used when the parsing function was generated. Calling tt(print_) from
tt(print) is unconditional, but can easily be controlled by the using
program, by defining, e.g., a command-line option.
it() bf(size_t stackSize_+nop()() const):nl()
Returns the current number of elements in the parser's state-stack.
it() bf(size_t state_+nop()() const):nl()
Returns the current parsing-state.
it() bf(bool Base::recovery_+nop()() const):nl()
Returns tt(true) while recovering from a syntax error.
it() bf(int Base::token_+nop()() const):nl()
Returns the currently considered token.
)
The following members are required during the parsing process. They should not
be modified or masked by user-defined code:
itemization(
it() bf(Base::ParserBase())
it() bf(void Base::clearin_+nop()()())
it() bf(void errorRecovery_+nop()())
it() bf(void Base::errorVerbose_+nop()())
it() bf(void executeAction_+nop()(int))
it() bf(int lex_(int token))
it() bf(int Base::lookup+nop()())
it() bf(LTYPE_ const &lsp_(int) const)nl()
(only available when tt(%lsp-needed, %ltype) or
tt(%locationstruct) was specified).
it() bf(void nextCycle_+nop()())
it() bf(void nextToken_+nop()())
it() bf(void Base::pop_+nop()())
it() bf(void Base::popToken_+nop()())
it() bf(void print_()())
it() bf(void Base::push_+nop()())
it() bf(void Base::pushToken_+nop()())
it() bf(void Base::shift_+nop()(int state))
it() bf(void Base::redoToken_+nop()(int rule))
it() bf(void Base::reduce_+nop()(int rule))
it() bf(void Base::savedToken_+nop()())
it() bf(void Base::symbol_+nop()())
it() bf(void Base::startRecovert_+nop()())
it() bf(void Base::top_+nop()())
it() bf(int Base::token_+nop()() const)
it() bf(void Base::vs_+nop()(int idx))
)
|