mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
lalr1.cc: syntax_error as exceptions.
It is common to use sort of factories in the user actions. These factories may check some "syntactic" constraints that are not enforced by the grammar itself. This is possible using YYERROR within the action itself. Provide the user with a means to throw a syntax_error exception. * data/c++.m4 (b4_public_types_declare, b4_public_types_define): Declare and define yy::parser::syntax_error. * data/lalr1.cc: Include stdexcept. (yy::parser::parse): Wrap the user action within a try/catch. * data/glr.cc: Include stdexcept.
This commit is contained in:
@@ -147,6 +147,7 @@ dnl FIXME: This is wrong, we want computed header guards.
|
||||
]b4_percent_code_get([[requires]])[
|
||||
|
||||
]b4_parse_assert_if([#include <cassert>])[
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include "stack.hh"
|
||||
@@ -814,12 +815,21 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param)));])[
|
||||
|
||||
// Perform the reduction.
|
||||
YY_REDUCE_PRINT (yyn);
|
||||
switch (yyn)
|
||||
try
|
||||
{
|
||||
switch (yyn)
|
||||
{
|
||||
]b4_user_actions[
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (const syntax_error& yyexc)
|
||||
{
|
||||
error (]b4_args(b4_locations_if([yyexc.location]),
|
||||
[[yyexc.what()]])[);
|
||||
YYERROR;
|
||||
}
|
||||
YY_SYMBOL_PRINT ("-> $$ =", yylhs);
|
||||
]b4_variant_if([[
|
||||
// Destroy the rhs symbols.
|
||||
|
||||
Reference in New Issue
Block a user