* data/glr.c (YYERROR): Update definition.

(yyrecoverSyntaxError): Correct yyerrState logic. Correct comment.
Allow states with only a default reduction.

Fixes to avoid problem that $-N rules in GLR parsers can cause
buffer overruns, corrupting state.

* src/output.c (prepare_rules): Output max_left_semantic_context.
* src/reader.h (max_left_semantic_context): New
* src/scan-gram.l (max_left_semantic_context): Define.
(handle_action_dollar): Update max_left_semantic_context.
* data/glr.c (YYMAXLEFT): New.
(yydoAction): Increase yyrhsVals size.
(yyresolveAction): Ditto.

Fixes to problems with location handling in GLR parsers reported by
Frank Heckenbach (2003/06/05).

* data/glr.c (YYLTYPE): Make trivial if locations not used.
(YYRHSLOC): Add parentheses, make depend on whether locations used.
(YYLLOC_DEFAULT): Ditto.
(yyuserAction): Use YYLLOC_DEFAULT.
(yydoAction): Remove redundant code.

* tests/cxx-type.at: Exercise location information.
(yylex): Track locations.
(stmtMerge): Return value rather than printing.
This commit is contained in:
Paul Hilfinger
2003-06-10 02:44:58 +00:00
parent 144c1e767a
commit 25005f6ab0
6 changed files with 240 additions and 144 deletions

View File

@@ -253,6 +253,7 @@ prepare_rules (void)
muscle_insert_short_table ("merger", merger, 0, 0, nrules);
MUSCLE_INSERT_INT ("rules_number", nrules);
MUSCLE_INSERT_INT ("max_left_semantic_context", max_left_semantic_context);
free (rhs);
free (prhs);

View File

@@ -38,6 +38,7 @@ typedef struct merger_list
extern FILE *gram_in;
extern int gram__flex_debug;
extern boundary scanner_cursor;
extern int max_left_semantic_context;
void scanner_initialize (void);
void scanner_free (void);
void scanner_last_string_free (void);

View File

@@ -649,6 +649,11 @@ splice (\\[ \f\t\v]*\n)*
%%
/* Keeps track of the maximum number of semantic values to the left of
a handle (those referenced by $0, $-1, etc.) are required by the
semantic actions of this grammar. */
int max_left_semantic_context = 0;
/* Set *LOC and adjust scanner cursor to account for token TOKEN of
size SIZE. */
@@ -781,6 +786,8 @@ handle_action_dollar (char *text, location loc)
if (INT_MIN <= num && num <= rule_length && ! get_errno ())
{
int n = num;
if (1-n > max_left_semantic_context)
max_left_semantic_context = 1-n;
if (!type_name && n > 0)
type_name = symbol_list_n_type_name_get (current_rule, loc, n);
if (!type_name && typed)