2016-03-24 7 views
0

Ich habe die folgende Grammatik:Wie Shift-Reduce-Konflikt in Yacc Grammatik zu entfernen?

Expression 
    : SimpleExpression {$$ = $1;}; 
    | SimpleExpression LTnum SimpleExpression 
     { MkLeftC($1, $2); $$ = MkRightC($3, $2); } 
    | SimpleExpression LEnum SimpleExpression 
     { MkLeftC($1, $2); $$ = MkRightC($3, $2); } 
    | SimpleExpression EQnum SimpleExpression 
     { MkLeftC($1, $2); $$ = MkRightC($3, $2); } 
    | SimpleExpression NEnum SimpleExpression 
     { MkLeftC($1, $2); $$ = MkRightC($3, $2); } 
    | SimpleExpression GEnum SimpleExpression 
     { MkLeftC($1, $2); $$ = MkRightC($3, $2); } 
    | SimpleExpression GTnum SimpleExpression 
     { MkLeftC($1, $2); $$ = MkRightC($3, $2); } 
    ; 

SimpleExpression 
    : PLUSnum Term op_terms 
     { $$ = MakeTree(AddOp,$3,$2); } 
    | MINUSnum Term op_terms 
     { $$ = MakeTree(SubOp,$3,$2); } 
    ; 

op_terms 
    : PLUSnum Term 
     { $$ = MakeTree(AddOp,NullExp(),$2); } 
    | PLUSnum Term op_terms 
     { $$ = MakeTree(AddOp,$3,$2); } 
    | MINUSnum Term 
     { $$ = MakeTree(SubOp,NullExp(),$2); } 
    | MINUSnum Term op_terms 
     { $$ = MakeTree(SubOp,$3,$2); } 
    | ORnum Term 
     { $$ = MakeTree(OrOp,NullExp(),$2); } 
    | ORnum Term op_terms 
     { $$ = MakeTree(OrOp,$3,$2); } 
    ; 

ich folgende shift-reduce Konflikte in der y.output Datei:

51: shift/reduce conflict (shift 74, reduce 57) on GTnum 
51: shift/reduce conflict (shift 75, reduce 57) on NEnum 
51: shift/reduce conflict (shift 76, reduce 57) on EQnum 
51: shift/reduce conflict (shift 77, reduce 57) on GEnum 
51: shift/reduce conflict (shift 78, reduce 57) on LEnum 
51: shift/reduce conflict (shift 79, reduce 57) on LTnum 
state 51 
    Expression : SimpleExpression . (57) 
    Expression : SimpleExpression . LTnum SimpleExpression (58) 
    Expression : SimpleExpression . LEnum SimpleExpression (59) 
    Expression : SimpleExpression . EQnum SimpleExpression (60) 
    Expression : SimpleExpression . NEnum SimpleExpression (61) 
    Expression : SimpleExpression . GEnum SimpleExpression (62) 
    Expression : SimpleExpression . GTnum SimpleExpression (63) 

Ich brauche Hilfe bei diesen Konflikten zu entfernen. Was mache ich hier falsch? Ich habe versucht, Vorrangregeln zu setzen, aber sie scheinen hier irgendwie nicht zu funktionieren. Irgendwelche Ideen?

Antwort

0

Seltsame Grammatik. Es sollte von diesem Formular sein:

d. H. Mit Links-Rekursion.

Seltsamer Baum auch. Es sollte von der allgemeinen Form sein:

$$ = MkBinaryNode($1,$2,$3); 
+0

Ich änderte die Grammatik zu der oben genannten, aber ich bekomme immer noch die gleichen Konflikte. – ExeCode

+0

Es funktionierte danke für die Hilfe. – ExeCode

Verwandte Themen