Как обнаружить сдвиг / уменьшить конфликты у зубров? - PullRequest
0 голосов
/ 01 мая 2018

Я новичок в зубрах. Я сделал мой .y файл, но в компиляции я получаю эту ошибку:

предупреждение: 42 сдвига / уменьшения конфликтов [-Wconflicts-sr]

Я открыл созданный файл .output и увидел следующее, но не могу понять и не могу понять, в чем проблема.

Вот часть моего .output файла:

    State 63

   56 expr_decl: KW_NOT expr_decl .  [KW_END, KW_OR, OP_OR, KW_AND, OP_AND, '>', OP_LESSOREQUAL, OP_GREATEROREQUAL, '=', OP_NOTEQUAL, '<', '*', '/', KW_DIV, KW_MOD, ';', ')', '+', '-']
   59          | expr_decl . '*' expr_decl
   60          | expr_decl . '/' expr_decl
   61          | expr_decl . KW_DIV expr_decl
   62          | expr_decl . KW_MOD expr_decl
   63          | expr_decl . '+' expr_decl
   64          | expr_decl . '-' expr_decl
   65          | expr_decl . '=' expr_decl
   66          | expr_decl . '<' expr_decl
   67          | expr_decl . '>' expr_decl
   68          | expr_decl . OP_NOTEQUAL expr_decl
   69          | expr_decl . OP_LESSOREQUAL expr_decl
   70          | expr_decl . OP_GREATEROREQUAL expr_decl
   71          | expr_decl . OP_AND expr_decl
   72          | expr_decl . KW_AND expr_decl
   73          | expr_decl . KW_OR expr_decl
   74          | expr_decl . OP_OR expr_decl

    '+'  shift, and go to state 87
    '-'  shift, and go to state 88

    '+'       [reduce using rule 56 (expr_decl)]
    '-'       [reduce using rule 56 (expr_decl)]
    $default  reduce using rule 56 (expr_decl)

    Conflict between rule 56 and token KW_OR resolved as reduce (KW_OR < KW_NOT).
    Conflict between rule 56 and token OP_OR resolved as reduce (OP_OR < KW_NOT).
    Conflict between rule 56 and token KW_AND resolved as reduce (KW_AND < KW_NOT).
    Conflict between rule 56 and token OP_AND resolved as reduce (OP_AND < KW_NOT).
    Conflict between rule 56 and token '>' resolved as reduce ('>' < KW_NOT).
    Conflict between rule 56 and token OP_LESSOREQUAL resolved as reduce (OP_LESSOREQUAL < KW_NOT).
    Conflict between rule 56 and token OP_GREATEROREQUAL resolved as reduce (OP_GREATEROREQUAL < KW_NOT).
    Conflict between rule 56 and token '=' resolved as reduce ('=' < KW_NOT).
    Conflict between rule 56 and token OP_NOTEQUAL resolved as reduce (OP_NOTEQUAL < KW_NOT).
    Conflict between rule 56 and token '<' resolved as reduce ('<' < KW_NOT).
    Conflict between rule 56 and token '*' resolved as reduce ('*' < KW_NOT).
    Conflict between rule 56 and token '/' resolved as reduce ('/' < KW_NOT).
    Conflict between rule 56 and token KW_DIV resolved as reduce (KW_DIV < KW_NOT).
    Conflict between rule 56 and token KW_MOD resolved as reduce (KW_MOD < KW_NOT).

Любая помощь, пожалуйста? Я искал часы и все еще ничего ..

Вот моя часть декларации:

%left KW_OR OP_OR
%left KW_AND OP_AND
%left '>' OP_LESSOREQUAL OP_GREATEROREQUAL
%left '=' OP_NOTEQUAL '<'
%left OP_PLUS OP_MINUS
%left '*' '/' KW_DIV KW_MOD
%left cast
%right POSITIVE NEGATIVE
%right KW_NOT '!'

Вот мое правило в зубрах:

expr_decl : 
        | REAL
        | POSINT
        | '!' expr_decl { $$ = template("!(%s)", $2); }
        | KW_NOT expr_decl { $$ = template("not(%s)", $2); }
        | '+' expr_decl %prec POSITIVE { $$ = template("+(%s)", $2); }
        | '-' expr_decl %prec NEGATIVE { $$ = template("-(%s)", $2); }
        | expr_decl '*' expr_decl { $$ = template("%s * %s", $1, $3); }
        | expr_decl '/' expr_decl { $$ = template("%s / %s", $1, $3); }
        | expr_decl KW_DIV expr_decl { $$ = template("%s div %s", $1, $3); }
        | expr_decl KW_MOD expr_decl { $$ = template("%s mod %s", $1, $3); }
        | expr_decl '+' expr_decl %prec OP_PLUS{ $$ = template("%s + %s", $1, $3); }
        | expr_decl '-' expr_decl %prec OP_MINUS{ $$ = template("%s + %s", $1, $3); }
        | expr_decl '=' expr_decl { $$ = template("%s = %s", $1, $3); }
        | expr_decl '<' expr_decl { $$ = template("%s < %s", $1, $3); }
        | expr_decl '>' expr_decl { $$ = template("%s > %s", $1, $3); }
        | expr_decl OP_NOTEQUAL expr_decl { $$ = template("%s <> %s", $1, $3); }
        | expr_decl OP_LESSOREQUAL expr_decl { $$ = template("%s <= %s", $1, $3); }
        | expr_decl OP_GREATEROREQUAL expr_decl { $$ = template("%s >= %s", $1, $3); }
        | expr_decl OP_AND expr_decl { $$ = template("%s && %s", $1, $3); }
        | expr_decl KW_AND expr_decl { $$ = template("%s and %s", $1, $3); }
            | expr_decl KW_OR expr_decl { $$ = template("%s || %s", $1, $3); }
            | expr_decl OP_OR expr_decl { $$ = template("%s or %s", $1, $3); }
                | '(' expr_decl ')' { $$ = template("(%s)", $2); }
;

1 Ответ

0 голосов
/ 02 мая 2018

Эта часть выходного файла:

'+'  shift, and go to state 87
'-'  shift, and go to state 88

'+'       [reduce using rule 56 (expr_decl)]
'-'       [reduce using rule 56 (expr_decl)]

говорит вам, что у вас есть два конфликта сдвига / уменьшения в этом состоянии, на условных обозначениях '+' и '-'. [ .. ] вокруг действия сокращения указывает, что это действие было удалено (разрешение конфликта в пользу сдвига).

Сообщения:

Conflict between rule 56 and token KW_OR resolved as reduce (KW_OR < KW_NOT).
Conflict between rule 56 and token OP_OR resolved as reduce (OP_OR < KW_NOT).
Conflict between rule 56 and token KW_AND resolved as reduce (KW_AND < KW_NOT).
       :

расскажет вам о конфликтах сдвига / уменьшения, которые были разрешены правилами приоритетов в вашей грамматике (поэтому они не включены в 42 конфликта сдвига / уменьшения в предупреждении).

Правила предшествования не разрешают конфликт для '+' и '-', поскольку у вас нет приоритета для этих токенов.

...