@@ -892,10 +892,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize);
892892%parse-param { THD *thd }
893893%lex-param { THD *thd }
894894/*
895- Currently there are 122 shift/reduce conflicts.
895+ Currently there are 99 shift/reduce conflicts.
896896 We should not introduce new conflicts any more.
897897*/
898- %expect 122
898+ %expect 99
899899
900900/*
901901 Comments for TOKENS.
@@ -1671,6 +1671,93 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize);
16711671%left NEG '~' NOT2_SYM BINARY
16721672%left COLLATE_SYM
16731673
1674+ /*
1675+ Tokens that can change their meaning from identifier to something else
1676+ in certain context.
1677+
1678+ - TRANSACTION: identifier, history unit:
1679+ SELECT transaction FROM t1;
1680+ SELECT * FROM t1 FOR SYSTEM_TIME AS OF TRANSACTION @var;
1681+
1682+ - TIMESTAMP: identifier, literal, history unit:
1683+ SELECT timestamp FROM t1;
1684+ SELECT TIMESTAMP '2001-01-01 10:20:30';
1685+ SELECT * FROM t1 FOR SYSTEM_TIME AS OF TIMESTAMP CONCAT(@date,' ',@time);
1686+
1687+ - PERIOD: identifier, period for sytem time:
1688+ SELECT period FROM t1;
1689+ ALTER TABLE DROP PERIOD FOR SYSTEM TIME;
1690+
1691+ - SYSTEM: identifier, system versioning:
1692+ SELECT system FROM t1;
1693+ ALTER TABLE DROP SYSTEM VERSIONIONG;
1694+
1695+ Note, we need here only tokens that cause shirt/reduce conflicts
1696+ with keyword identifiers. For example:
1697+ opt_clause1: %empty | KEYWORD ... ;
1698+ clause2: opt_clause1 ident;
1699+ KEYWORD can appear both in opt_clause1 and in "ident" through the "keyword"
1700+ rule. So the parser reports a conflict on how to interpret KEYWORD:
1701+ - as a start of non-empty branch in opt_clause1, or
1702+ - as an identifier which follows the empty branch in opt_clause1.
1703+
1704+ Example#1:
1705+ alter_list_item:
1706+ DROP opt_column opt_if_exists_table_element field_ident
1707+ | DROP SYSTEM VERSIONING_SYM
1708+ SYSTEM can be a keyword in field_ident, or can be a start of
1709+ SYSTEM VERSIONING.
1710+
1711+ Example#2:
1712+ system_time_expr: AS OF_SYM history_point
1713+ history_point: opt_history_unit bit_expr
1714+ opt_history_unit: | TRANSACTION_SYM
1715+ TRANSACTION can be a non-empty history unit, or can be an identifier
1716+ in bit_expr.
1717+
1718+ In the grammar below we use %prec to explicitely tell Bison to go
1719+ through the empty branch in the optional rule only when the lookahead
1720+ token does not belong to a small set of selected tokens.
1721+
1722+ Tokens NEXT_SYM and PREVIOUS_SYM also change their meaning from
1723+ identifiers to sequence operations when followed by VALUE_SYM:
1724+ SELECT NEXT VALUE FOR s1, PREVIOUS VALUE FOR s1;
1725+ but we don't need to list them here as they do not seem to cause
1726+ conflicts (according to bison -v), as both meanings
1727+ (as identifier, and as a sequence operation) are parts of the same target
1728+ column_default_non_parenthesized_expr, and there are no any optional
1729+ clauses between the start of column_default_non_parenthesized_expr
1730+ and until NEXT_SYM / PREVIOUS_SYM.
1731+ */
1732+ %left PREC_BELOW_IDENTIFIER_OPT_SPECIAL_CASE
1733+ %left TRANSACTION_SYM TIMESTAMP PERIOD SYSTEM
1734+
1735+
1736+ /*
1737+ Tokens that can appear in a token contraction on the second place
1738+ and change the meaning of the previous token.
1739+
1740+ - TEXT_STRING: changes the meaning of TIMESTAMP/TIME/DATE
1741+ from identifier to literal:
1742+ SELECT timestamp FROM t1;
1743+ SELECT TIMESTAMP'2001-01-01 00:00:00' FROM t1;
1744+
1745+ - Parenthesis: changes the meaning of TIMESTAMP/TIME/DATE
1746+ from identifiers to CAST-alike functions:
1747+ SELECT timestamp FROM t1;
1748+ SELECT timestamp(1) FROM t1;
1749+
1750+ - VALUE: changes NEXT and PREVIOUS from identifier to sequence operation:
1751+ SELECT next, previous FROM t1;
1752+ SELECT NEXT VALUE FOR s1, PREVIOUS VALUE FOR s1;
1753+
1754+ - VERSIONING: changes SYSTEM from identifier to SYSTEM VERSIONING
1755+ SELECT system FROM t1;
1756+ ALTER TABLE t1 ADD SYSTEM VERSIONING;
1757+ */
1758+ %left PREC_BELOW_CONTRACTION_TOKEN2
1759+ %left TEXT_STRING '(' VALUE_SYM VERSIONING_SYM
1760+
16741761%type <lex_str>
16751762 DECIMAL_NUM FLOAT_NUM NUM LONG_NUM
16761763 HEX_NUM HEX_STRING
@@ -8355,7 +8442,7 @@ alter_lock_option:
83558442 ;
83568443
83578444opt_column:
8358- /* empty */ {}
8445+ /* empty */ {} %prec PREC_BELOW_IDENTIFIER_OPT_SPECIAL_CASE
83598446 | COLUMN_SYM {}
83608447 ;
83618448
@@ -9239,7 +9326,7 @@ select_options:
92399326 ;
92409327
92419328opt_history_unit:
9242- /* empty*/
9329+ /* empty*/ %prec PREC_BELOW_IDENTIFIER_OPT_SPECIAL_CASE
92439330 {
92449331 $$= VERS_UNDEFINED;
92459332 }
@@ -15440,7 +15527,7 @@ keyword_sp_data_type:
1544015527 | BOOLEAN_SYM
1544115528 | BOOL_SYM
1544215529 | CLOB
15443- | DATE_SYM
15530+ | DATE_SYM %prec PREC_BELOW_CONTRACTION_TOKEN2
1544415531 | DATETIME
1544515532 | ENUM
1544615533 | FIXED_SYM
@@ -15462,8 +15549,8 @@ keyword_sp_data_type:
1546215549 | ROW_SYM
1546315550 | SERIAL_SYM
1546415551 | TEXT_SYM
15465- | TIMESTAMP
15466- | TIME_SYM
15552+ | TIMESTAMP %prec PREC_BELOW_CONTRACTION_TOKEN2
15553+ | TIME_SYM %prec PREC_BELOW_CONTRACTION_TOKEN2
1546715554 | VARCHAR2
1546815555 | YEAR_SYM
1546915556 ;
@@ -15646,7 +15733,7 @@ keyword_sp_not_data_type:
1564615733 | MYSQL_ERRNO_SYM
1564715734 | NAME_SYM
1564815735 | NAMES_SYM
15649- | NEXT_SYM
15736+ | NEXT_SYM %prec PREC_BELOW_CONTRACTION_TOKEN2
1565015737 | NEXTVAL_SYM
1565115738 | NEW_SYM
1565215739 | NOCACHE_SYM
@@ -15677,7 +15764,7 @@ keyword_sp_not_data_type:
1567715764 | PLUGINS_SYM
1567815765 | PRESERVE_SYM
1567915766 | PREV_SYM
15680- | PREVIOUS_SYM
15767+ | PREVIOUS_SYM %prec PREC_BELOW_CONTRACTION_TOKEN2
1568115768 | PRIVILEGES
1568215769 | PROCESS
1568315770 | PROCESSLIST_SYM
@@ -15760,7 +15847,7 @@ keyword_sp_not_data_type:
1576015847 | TEMPORARY
1576115848 | TEMPTABLE_SYM
1576215849 | THAN_SYM
15763- | TRANSACTION_SYM
15850+ | TRANSACTION_SYM %prec PREC_BELOW_CONTRACTION_TOKEN2
1576415851 | TRANSACTIONAL_SYM
1576515852 | TRIGGERS_SYM
1576615853 | TRIM_ORACLE
0 commit comments