Bison 删除换档/减速警告

Bison 删除换档/减速警告,bison,yacc,Bison,Yacc,我想解析一个数组名,其中@后跟任意数量的单词,一个简单变量不带@且后跟任意数量的单词: 数组名称示例:@people 简单变量名:person 我需要分析的示例文件: @people name1 name2 person name3 name4 我制定了如下规则: list of record : line list_of_record {} | line {}; line : AT_SYMBOL string string_list {} | string string_list {} ;

我想解析一个
数组名
,其中
@
后跟任意数量的单词,一个
简单变量
不带
@
且后跟任意数量的单词:

数组名称示例:
@people

简单变量名:
person

我需要分析的示例文件:

@people name1 name2
person name3 name4
我制定了如下规则:

list of record :
line list_of_record
{}
|
line
{};

line
:
AT_SYMBOL string string_list
{}
|
string string_list
{}
;

string_list:
string string_list
{}
|
string
{}
;
//here string is any string

但是我收到了
shift/reduce
警告。有没有人能建议一些方法,让我删除这些警告。

没有办法知道
行的结尾是什么。任何
字符串
都可以是
字符串列表
中的另一项,也可以是新
行的开头

因此,您需要决定如何标记
行的结尾。如果它是一个新行字符,这看起来很直观,那么你的lexer必须将新行标记传递给语法

顺便说一下,在自底向上的语法中使用左递归通常更好。所以我建议如下:

 lines: /* empty */
      | lines line NEWLINE
      ;

 line : /* empty, to allow for blank lines */
      | array
      | scalar
      ;

 array: '@' string strings ;

 scalar: string strings ;

 strings: string
        | strings string
        ;

上面要求
字符串
为非空,因此
需要至少包含两个字符串。这可能是您想要的,也可能不是。

标签太多了。选择一个。如果您要使用
'@'
而不是
换行符,那么使用
'\n'
而不是
AT\u SYMBOL