0

This gives 66 shift/reduce conflicts

initializer
    : '{' initializer_list '}'           
    | '{' initializer_list ',' '}'            
    | '{' preprocessor_list  initializer_list    '}'    
    ;
preprocessor_list
    : preprocessor
    | preprocessor_list preprocessor
    ;

but this works:

initializer
    : '{' initializer_list '}'       
    | '{' initializer_list ',' '}'     
    | '{' preprocessor initializer_list '}'    
    | '{' preprocessor preprocessor initializer_list '}    
    | '{' preprocessor preprocessor  preprocessor  initializer_list '}'
    ;

Please find below the definition of initializer list:

initializer_list
    : designation initializer
    | preprocessor
    | preprocessor initializer_list ','
    | preprocessor initializer_list ','  preprocessor_list
    | initializer_list ',' preprocessor_list designation initializer
    | initializer_list ','  designation initializer
    | initializer_list ',' initializer
    ;

designation
    : designator_list '='
    ;
designator_list
    : designator
    | designator_list designator
    ;

designator
    : '[' constant_expression ']'
    | '.' IDENTIFIER
    ;

Rules for preprocessor:

preprocessor
    : hash_define BLACK_SPACE define_expression
    | hash_else NEW_LINE
    | hash_if BLACK_SPACE unary_expression NEW_LINE
    | hash_ifdef BLACK_SPACE unary_expression NEW_LINE
    | hash_ifndef BLACK_SPACE unary_expression NEW_LINE
    | hash_ident BLACK_SPACE STRING_LITERAL NEW_LINE
    | hash_include STRING_LITERAL 
                 {printf("string identified in #include\n");}
      NEW_LINE   {printf("#include with quotes\n");}
    | hash_include '<' filepath  '>' NEW_LINE
    | hash_line BLACK_SPACE I_CONSTANT NEW_LINE
    | hash_line BLACK_SPACE I_CONSTANT {enable_space = 1;}
                BLACK_SPACE STRING_LITERAL NEW_LINE
    | hash_undef BLACK_SPACE IDENTIFIER NEW_LINE
    | hash_LINK BLACK_SPACE STRING_LITERAL NEW_LINE
    | hash_endif NEW_LINE
    ;
rici
  • 234,347
  • 28
  • 237
  • 341
Pinky
  • 11
  • 2
  • Difficult to answer without seeing the definitions of preprocessor and initializer-list, but your first excerpt has two consecutive colons after initializer, which is a syntax error. – rici Nov 12 '15 at 16:13
  • consecutive colon was a copy paste error(removed).I have added rules for initializer_list and its successors.Also added rule for preprocessor. – Pinky Nov 13 '15 at 04:46
  • It would be useful if you could learn how to format code blocks in questions. (It's easy: indent every line four spaces. You can use the `ctl-K` shortcut, too.) – rici Nov 13 '15 at 05:11

1 Answers1

1

The problem is that initializer_list can start with preprocessor. That makes this fragment of initializer

`preprocessor_list initializer_list`

ambiguous since any preprocessor expansions could belong to either the preprocessor_list in initializer or to initializer_list. So pick one of the initializer and initializer_list to include the leading preprocessors.

rici
  • 234,347
  • 28
  • 237
  • 341