有没有办法让parsec报告“转移

编程入门 行业动态 更新时间:2024-10-25 22:24:32
没有办法让parsec报告“转移 - 减少”冲突?(Is there any way to make parsec report “shift-reduce” conflicts?)

我正在玩parsec,并意识到我有一个模棱两可的语法。 很明显,这是我的错误,但我有点习惯yacc风格的解析器生成器让我知道我是愚蠢的。 Parsec只是按照你给它的解析器的顺序吃字符(是的,我知道try )。

有没有什么方法可以让我的语法不是左派? 为我工作的程序非常棒。

谢谢!

(我知道shift-reduce与不同类型的解析器技术有关,我只是想描述不明确的语法。)

I'm playing around with parsec and realized that I had an ambiguous grammar. Obviously that's an error on my part, but I'm sort of used to yacc-style parser generators letting me know I'm being dumb. Parsec just eats characters in the order you give it parsers (yeah, I know about try).

Is there any way to make parsec tell me when my grammar isn't left-factored? Programs that do work for me are great.

Thanks!

(I know that shift-reduce has to do with a different kind of parser technology. I simply mean to describe ambiguous grammars.)

最满意答案

我不是Parsec的专家,所以我很可能会被纠正,但我认为这是不可能的,因为Parsec对你的语法一无所知。

换句话说,虽然你的语法可能不明确,但你的Parsec分析器不是,程序也没有办法确定其他一些parsec组合器的排列方式,它们为等效输入产生不同的输出,也是一种有效的未指定的语法。

既然你确实有语法,你可能更喜欢使用happy和alex ,这会给你更多的lexx / yacc体验。

一个有趣的项目可能是让BNFC适应生成一个parsec组合器的AST代表一个语法,但我怀疑这将是一个不平凡的任务。

I am not a Parsec expert, so I'm likely to be corrected, but I don't think this is possible, for the simple reason that Parsec knows nothing about your grammar.

Or put another way, while your grammar may be ambiguous, your Parsec parser is not, and a program has no way of determining that some other arrangement of parsec combinators, which produces a different output for equivalent input, is also a valid representation of an unspecified grammar.

Since you do have a grammar, you might prefer to use happy and alex, which will give you a much more lexx/yacc-like experience.

An interesting project might be to adapt the BNFC to produce an AST of parsec combinators to represent a grammar, but I suspect this would be a non-trivial task.

更多推荐

本文发布于:2023-08-03 16:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1393620.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:没有办法   报告   parsec

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!