Apa*_*ala 5 grammar parsing ebnf peg grako
我的同事PaulS向我询问了以下内容:
我正在为一种现有语言(SystemVerilog-IEEE标准)编写一个解析器,并且该规范中包含一个规则,该规则在结构上与此类似:
cover_point
=
[[data_type] identifier ':' ] 'coverpoint' identifier ';'
;
data_type
=
'int' | 'float' | identifier
;
identifier
=
?/\w+/?
;
Run Code Online (Sandbox Code Playgroud)
问题在于解析以下合法字符串时:
anIdentifier: coverpoint another_identifier;
Run Code Online (Sandbox Code Playgroud)
anIdentifier匹配data_type成功(通过其标识符选项),这表示Grako正在寻找另一个标识符,然后失败。然后,它不会尝试在没有data_type部分的情况下进行解析。
我可以如下重写规则,
cover_point_rewrite
=
[data_type identifier ':' | identifier ':' ] 'coverpoint' identifier ';'
;
Run Code Online (Sandbox Code Playgroud)
但我想知道是否:
这是一个一般性的PEG问题,还是一个工具(Grako)?
| 归档时间: |
|
| 查看次数: |
530 次 |
| 最近记录: |