Next: C++ Scanner Interface, Previous: C++ Location Values, Up: C++ Parsers [Contents][Index]
The output files output.hh and output.cc
declare and define the parser class in the namespace yy
. The
class name defaults to parser
, but may be changed using
‘%define parser_class_name {name}’. The interface of
this class is detailed below. It can be extended using the
%parse-param
feature: its semantics is slightly changed since
it describes an additional member of the parser class, and an
additional argument for its constructor.
The types for semantic values and locations (if enabled).
A structure that contains (only) the yytokentype
enumeration, which
defines the tokens. To refer to the token FOO
,
use yy::parser::token::FOO
. The scanner can use
‘typedef yy::parser::token token;’ to “import” the token enumeration
(see Calc++ Scanner).
This class derives from std::runtime_error
. Throw instances of it
from the scanner or from the user actions to raise parse errors. This is
equivalent with first
invoking error
to report the location and message of the syntax
error, and then to invoke YYERROR
to enter the error-recovery mode.
But contrary to YYERROR
which can only be invoked from user actions
(i.e., written in the action itself), the exception can be thrown from
function invoked from the user action.
Build a new parser object. There are no arguments by default, unless ‘%parse-param {type1 arg1}’ was used.
Instantiate a syntax-error exception.
Run the syntactic analysis, and return 0 on success, 1 otherwise.
The whole function is wrapped in a try
/catch
block, so that
when an exception is thrown, the %destructor
s are called to release
the lookahead symbol, and the symbols pushed on the stack.
Get or set the stream used for tracing the parsing. It defaults to
std::cerr
.
Get or set the tracing level. Currently its value is either 0, no trace, or nonzero, full tracing.
The definition for this member function must be supplied by the user: the parser uses it to report a parser error occurring at l, described by m. If location tracking is not enabled, the second signature is used.
Next: C++ Scanner Interface, Previous: C++ Location Values, Up: C++ Parsers [Contents][Index]