I am pretty sure I have conflicting YACC rules (specifically the exp exp
and group_open exp group_close
rules). I am trying to build a simple boolean query syntax that lets people do stuff like a "b c" -(d or e) which would rougly be equivalent to a AND "b c" AND NOT (d OR e).
However I am having trouble implemnting both the group rule ()
and the AND rule (basically just spaces).
%lex
%%
\s+ ;
or|OR return 'or';
and|AND return 'and';
\"[^\"]+\" return 'phrase';
"-"\b return 'not';
"(" return 'group_open';
")" return 'group_close';
[^\s,]+ return 'word';
/lex
%token space
%token phrase
%token group_open
%token group_close
%token word
%left or
%left and
%left not
%%
query : exp { return $1; }
;
exp : term
| exp or exp { $$ = $1+" OR "+$3; }
| exp and exp { $$ = $1+" AND "+$3; }
/* this is the one that is casuing me issues */
| exp exp { $$ = $1+" AND "+$3; }
| not exp { $$ = "NOT "+$2; }
| group_open exp group_close { $$ = "("+$2+")"; }
;
term : phrase { $$ = "PHRASE"; }
| word { $$ = "WORD"; }
;
Any help would be great.
I am testing my grammar by using jison.org
Below are the errors I am getting
Conflicts encountered:
Resolve S/R conflict (shift by default.)
(1,8, 2,5) -> 1,8Resolve S/R conflict (shift by default.)
(1,9, 2,5) -> 1,9Resolve S/R conflict (shift by default.)
(1,6, 2,5) -> 1,6Resolve S/R conflict (shift by default.)
(1,7, 2,5) -> 1,7Resolve S/R conflict (shift by default.)
(1,4, 2,5) -> 1,4Resolve S/R conflict (shift by default.)
(1,5, 2,5) -> 1,5Resolve S/R conflict (shift by default.)
(1,6, 2,6) -> 1,6Resolve S/R conflict (shift by default.)
(1,7, 2,6) -> 1,7Resolve S/R conflict (shift by default.)
(1,5, 2,6) -> 1,5Resolve S/R conflict (shift by default.)
(1,6, 2,3) -> 1,6Resolve S/R conflict (shift by default.)
(1,7, 2,3) -> 1,7Resolve S/R conflict (shift by default.)
(1,5, 2,3) -> 1,5Resolve S/R conflict (shift by default.)
(1,6, 2,4) -> 1,6Resolve S/R conflict (shift by default.)
(1,7, 2,4) -> 1,7Resolve S/R conflict (shift by default.)
(1,5, 2,4) -> 1,5