在编写规则以解析结构内的嵌套预处理器时移位/减少冲突。如何解决这个问题?

时间:2015-11-12 13:24:19

标签: bison yacc

这提供了66次转换/减少冲突

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

但这有效:

initializer
    : '{' initializer_list '}'       
    | '{' initializer_list ',' '}'     
    | '{' preprocessor initializer_list '}'    
    | '{' preprocessor preprocessor initializer_list '}    
    | '{' preprocessor preprocessor  preprocessor  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
    ;

预处理器规则:

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
    ;

1 个答案:

答案 0 :(得分:1)

问题是using System; using System.Collections.Generic; namespace firstconsoleproject { class MainClass { public static void Main (string[] args) { int first=4; int c=0; int ax; int ai; Console.WriteLine ("please enter n"); ax = Convert.ToInt32( Console.ReadLine()); for (int i=11 ; ax>0 ;) { if (first==1) { c = ax+1; i++; } c--; ai=i*c; for (int ten=10 ; ; ) { if(ai%ten==2) { first=0; break; }else if (ai==0) { first=1; break; } ai/=10; } if (c==0){Console.WriteLine("number is "+i);break;} }Console.ReadKey (); } } } 可以从initializer_list开始。这就是preprocessor

的片段
initializer

不明确,因为任何`preprocessor_list initializer_list` 扩展都可能属于preprocessor中的preprocessor_listinitializer。因此,选择其中一个initializer_listinitializer以包含前导initializer_list