compiler construction - Why Bison gives Conflict: 2 Shift Reduce error -
i'm trying below yacc grammar part gives me, wrong this? , how can solve it? there rules define grammar in bison/ yacc ?
c:\users\dilan\documents\lexprogram\miniproject>bison -dy videostore.y conflicts: 1 shift/reduce
and yacc code :
%start videostore %token title %token type %token name %token days %% videostore : movies customers | customers movies | movies | customers ; movies : movies movie | movie ; movie : title type rentals2 ; rentals2 : rentals2 rental2 | rental2 ; rental2 : customer1 ; customer1 : name days ; customers : customers customer | customer ; customer : name days rentals ; rentals : rentals rental | rental ; rental : movie1 ; movie1 : title type ; %% int trace=0;
my problem videostore.y: conflicts: 2 shift/reduce , how can wrote lex ?
use -v
option bison
, gives .output file showing states , conflicts are. in case, have conflicts in states 16 , 20:
state 16 7 movie: title type rentals2 . 8 rentals2: rentals2 . rental2 name shift, , go state 15 name [reduce using rule 7 (movie)] $default reduce using rule 7 (movie) rental2 go state 24 customer1 go state 18
this tells problem parser can't figure out end of movie
rule single token of lookahead -- movie
ends sequence of 1 or more rental2
rules, since rental2
begins name
, things come after movie
(such customer
rule) start name
can't tell whether should trying match more rental2
s or not.
most commonly, fix using sort of delimiter @ end of rentals2
list, such ';'
Comments
Post a Comment