Commit 48d70388 authored by Alexander Barkov's avatar Alexander Barkov

Token precedence cleanup in *.yy

We'll be fixing soon shift-reduce conflicts introduced in the new
10.3 syntax (see MDEV-15818 for details) by defining precedence for
a number of tokens (e.g. TIMESTAMP, TRANSACTION_SYM, TEXT_STRING)
and adding "%prec" directives.

Before doing this, it's better to have the existing precedences set properly,
for easier readability and maintainability.

Details:
- Changing precedence of NOT to its proper position (between AND and IS).
  It was wrong. It worked fine only because the relevant grammar reside
  in different separate rules (expr and predicate).

- Moving NOT2_SYM and BINARY to the same line with NEG and ~
  It worked fine because operators !, BINARY, ~ do not conflict
  to each other.

- Fixing associativity of NOT_SYM, NOT2_SYM, BINARY, COLLATE_SYM
  from "right" to "left". They are not dyadic (operate on a single expression
  only). So "%left" or "%right" is needed only to set precedence,
  while associativity does not matter.
  Note, it would be better to use "%precedence" for these tokens
  instead of "%left" though, but we use an old version of Bison on windows,
  which may not support %precedence yet.

This patch does not change behavior. The generated sql_yacc.cc and
sql_yacc_ora.cc are exactly the same before and after this change.
parent c2df4e9d
...@@ -1658,6 +1658,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); ...@@ -1658,6 +1658,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize);
%left OR_SYM OR2_SYM %left OR_SYM OR2_SYM
%left XOR %left XOR
%left AND_SYM AND_AND_SYM %left AND_SYM AND_AND_SYM
%left NOT_SYM
%left BETWEEN_SYM CASE_SYM WHEN_SYM THEN_SYM ELSE %left BETWEEN_SYM CASE_SYM WHEN_SYM THEN_SYM ELSE
%left '=' EQUAL_SYM GE '>' LE '<' NE IS LIKE REGEXP IN_SYM %left '=' EQUAL_SYM GE '>' LE '<' NE IS LIKE REGEXP IN_SYM
%left '|' %left '|'
...@@ -1667,9 +1668,8 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); ...@@ -1667,9 +1668,8 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize);
%left '*' '/' '%' DIV_SYM MOD_SYM %left '*' '/' '%' DIV_SYM MOD_SYM
%left '^' %left '^'
%left MYSQL_CONCAT_SYM %left MYSQL_CONCAT_SYM
%left NEG '~' %left NEG '~' NOT2_SYM BINARY
%right NOT_SYM NOT2_SYM %left COLLATE_SYM
%right BINARY COLLATE_SYM
%type <lex_str> %type <lex_str>
DECIMAL_NUM FLOAT_NUM NUM LONG_NUM DECIMAL_NUM FLOAT_NUM NUM LONG_NUM
......
...@@ -1044,6 +1044,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); ...@@ -1044,6 +1044,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize);
%left OR_SYM OR2_SYM %left OR_SYM OR2_SYM
%left XOR %left XOR
%left AND_SYM AND_AND_SYM %left AND_SYM AND_AND_SYM
%left NOT_SYM
%left BETWEEN_SYM CASE_SYM WHEN_SYM THEN_SYM ELSE %left BETWEEN_SYM CASE_SYM WHEN_SYM THEN_SYM ELSE
%left '=' EQUAL_SYM GE '>' LE '<' NE IS LIKE REGEXP IN_SYM %left '=' EQUAL_SYM GE '>' LE '<' NE IS LIKE REGEXP IN_SYM
%left '|' %left '|'
...@@ -1053,9 +1054,8 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); ...@@ -1053,9 +1054,8 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize);
%left '*' '/' DIV_SYM MOD_SYM %left '*' '/' DIV_SYM MOD_SYM
%left '^' %left '^'
%left MYSQL_CONCAT_SYM %left MYSQL_CONCAT_SYM
%left NEG '~' %left NEG '~' NOT2_SYM BINARY
%right NOT_SYM NOT2_SYM %left COLLATE_SYM
%right BINARY COLLATE_SYM
%type <lex_str> %type <lex_str>
DECIMAL_NUM FLOAT_NUM NUM LONG_NUM DECIMAL_NUM FLOAT_NUM NUM LONG_NUM
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment