[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: %nterm directive incorrectly accepts character literals and quoted s
From: |
Akim Demaille |
Subject: |
Re: %nterm directive incorrectly accepts character literals and quoted strings |
Date: |
Tue, 27 Nov 2018 07:21:23 +0100 |
> Le 27 nov. 2018 à 07:18, Akim Demaille <address@hidden> a écrit :
>
> The following two patches make %nterm safe to use.
Here is the second one.
commit c0addf14ae23f48d4d99808bf589ecb0044a49ac
Author: Akim Demaille <address@hidden>
Date: Sun Nov 25 18:07:46 2018 +0100
%nterm: do not accept character literals
Reported by Rici Lake.
http://lists.gnu.org/archive/html/bug-bison/2018-10/msg00000.html
* src/complain.h: Formatting change.
* src/parse-gram.y (id): Reject character literals used in a context
for non-terminals.
* tests/input.at (Invalid %nterm uses): Check that.
diff --git a/src/complain.h b/src/complain.h
index 599afb97..41d0c566 100644
--- a/src/complain.h
+++ b/src/complain.h
@@ -78,8 +78,7 @@ void complain_init (void);
typedef enum
{
- /**< Issue no warnings. */
- Wnone = 0,
+ Wnone = 0, /**< Issue no warnings. */
Wmidrule_values = 1 << warning_midrule_values,
Wyacc = 1 << warning_yacc,
diff --git a/src/parse-gram.y b/src/parse-gram.y
index 73eda17b..05e840bb 100644
--- a/src/parse-gram.y
+++ b/src/parse-gram.y
@@ -317,7 +317,7 @@ prologue_declaration:
| "%token-table" { token_table_flag = true; }
| "%verbose" { report_flag |= report_states; }
| "%yacc" { yacc_flag = true; }
-| error ";" { yyerrok; }
+| error ";" { current_class = unknown_sym; yyerrok; }
| /*FIXME: Err? What is this horror doing here? */ ";"
;
@@ -553,6 +553,9 @@ symbol_def:
symbol_defs.1:
symbol_def
| symbol_defs.1 symbol_def
+ /* FIXME: cannot do that, results in infinite loop in LAC.
+| error { yyerrok; }
+ */
;
@@ -669,6 +672,12 @@ id:
{ $$ = symbol_from_uniqstr ($1, @1); }
| CHAR
{
+ if (current_class == nterm_sym)
+ {
+ gram_error (&@1,
+ "character literals cannot be non-terminals");
+ YYERROR;
+ }
$$ = symbol_get (char_name ($1), @1);
symbol_class_set ($$, token_sym, @1, false);
symbol_user_token_number_set ($$, $1, @1);
diff --git a/tests/input.at b/tests/input.at
index 84fd0944..4618d513 100644
--- a/tests/input.at
+++ b/tests/input.at
@@ -140,10 +140,12 @@ AT_DATA([input.y],
[[%nterm expr "expression";
%nterm term 123;
%nterm fact 124 "factor";
+%nterm '+' '*';
+%nterm "number";
%%
expr: expr '+' term | term;
term: term '*' fact | fact;
-fact: '0';
+fact: "number";
]])
AT_BISON_CHECK([-fcaret input.y], [1], [],
@@ -168,6 +170,18 @@ input.y:3.13-15: error: non-terminals cannot be given an
explicit number
input.y:3.17-24: error: non-terminals cannot be given a string alias
%nterm fact 124 "factor";
^^^^^^^^
+input.y:4.1-6: warning: deprecated directive, use '%type' [-Wdeprecated]
+ %nterm '+' '*';
+ ^^^^^^
+input.y:4.8-10: error: character literals cannot be non-terminals
+ %nterm '+' '*';
+ ^^^
+input.y:5.1-6: warning: deprecated directive, use '%type' [-Wdeprecated]
+ %nterm "number";
+ ^^^^^^
+input.y:5.8-15: error: syntax error, unexpected string, expecting char or
identifier or <tag>
+ %nterm "number";
+ ^^^^^^^^
]])
AT_CLEANUP