我很确定我的YACC规则存在冲突(特别是exp exp
和group_open exp group_close
规则)。我正在尝试构建一个简单的布尔查询语法,让人们可以像 a" b c" - (d或e)这将等同于 a AND" b c"而不是(d或e)。
但是我无法实现组规则()
和AND规则(基本上只是空格)。
%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"; }
;
任何帮助都会很棒。
我正在使用jison.org
测试我的语法以下是我得到的错误
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