@@ -267,10 +267,14 @@ extern char *yyansi_ctext;
267
267
268
268
%start grammar
269
269
270
- %expect 1 /* the famous "dangling `else'" ambiguity */
270
+ %expect 2 /* the famous "dangling `else'" ambiguity */
271
271
/* results in one shift/reduce conflict */
272
272
/* that we don't want to be reported */
273
273
274
+ /* a second shift/reduce conflict arises due to enum underlying */
275
+ /* type specifications and bitfield specifications, which are both */
276
+ /* introduced by a ':' and follow a type */
277
+
274
278
%{
275
279
/* ***********************************************************************/
276
280
/* ** rules **************************************************************/
@@ -1790,38 +1794,70 @@ bit_field_size:
1790
1794
enum_name :
1791
1795
enum_key
1792
1796
gcc_type_attribute_opt
1797
+ enum_underlying_type_opt
1793
1798
{
1794
1799
// an anon enum
1800
+ if (parser_stack($3 ).is_not_nil())
1801
+ {
1802
+ parser_stack ($1 ).set(ID_enum_underlying_type, parser_stack($3 ));
1803
+ }
1795
1804
}
1796
1805
' {' enumerator_list_opt ' }'
1797
1806
gcc_type_attribute_opt
1798
1807
{
1799
- parser_stack ($1 ).operands().swap(parser_stack($5 ).operands());
1800
- $$ =merge($1 , merge($2 , $7 )); // throw in the gcc attributes
1808
+ parser_stack ($1 ).operands().swap(parser_stack($6 ).operands());
1809
+ $$ =merge($1 , merge($2 , $8 )); // throw in the gcc attributes
1801
1810
}
1802
1811
| enum_key
1803
1812
gcc_type_attribute_opt
1804
1813
identifier_or_typedef_name
1814
+ enum_underlying_type_opt
1805
1815
{
1806
1816
// an enum with tag
1807
1817
parser_stack ($1 ).set(ID_tag, parser_stack($3 ));
1818
+
1819
+ if (parser_stack($4 ).is_not_nil())
1820
+ {
1821
+ parser_stack ($1 ).set(ID_enum_underlying_type, parser_stack($4 ));
1822
+ }
1808
1823
}
1809
- ' { ' enumerator_list_opt ' } '
1824
+ braced_enumerator_list_opt
1810
1825
gcc_type_attribute_opt
1811
1826
{
1812
- parser_stack ($1 ).operands().swap(parser_stack($6 ).operands());
1813
- $$ =merge($1 , merge($2 , $8 )); // throw in the gcc attributes
1827
+ if (parser_stack($6 ).is_not_nil())
1828
+ {
1829
+ parser_stack ($1 ).operands().swap(parser_stack($6 ).operands());
1830
+ }
1831
+ else
1832
+ {
1833
+ parser_stack ($1 ).id(ID_c_enum_tag);
1834
+ }
1835
+
1836
+ $$ =merge($1 , merge($2 , $7 )); // throw in the gcc attributes
1814
1837
}
1815
- | enum_key
1816
- gcc_type_attribute_opt
1817
- identifier_or_typedef_name
1818
- gcc_type_attribute_opt
1838
+ ;
1839
+
1840
+ enum_underlying_type_opt :
1841
+ /* empty */
1819
1842
{
1820
- parser_stack ($1 ).id(ID_c_enum_tag); // tag only
1821
- parser_stack ($1 ).set(ID_tag, parser_stack($3 ));
1822
- $$ =merge($1 , merge($2 , $4 )); // throw in the gcc attributes
1843
+ init ($$);
1844
+ parser_stack ($$).make_nil();
1845
+ }
1846
+ | ' :' basic_type_name
1847
+ {
1848
+ $$ =$2 ;
1849
+ }
1850
+
1851
+ braced_enumerator_list_opt :
1852
+ /* empty */
1853
+ {
1854
+ init ($$);
1855
+ parser_stack ($$).make_nil();
1856
+ }
1857
+ | ' {' enumerator_list_opt ' }'
1858
+ {
1859
+ $$ =$2 ;
1823
1860
}
1824
- ;
1825
1861
1826
1862
enum_key : TOK_ENUM
1827
1863
{
0 commit comments