是否有用于编写词法分析器的 haskell EDSL?
将词法分析器和解析阶段混合在一个阶段有时会降低 Parsec 解析器的可读性,同时也会减慢它们的速度。一种解决方案是使用 Alex 作为标记器,然后使用 Parsec 作为标记流的解析器。
这很好,但如果我能摆脱 Alex 那就更好了,因为它在编译管道中添加了一个预处理阶段,不能与 haskell“IDE”等很好地集成。我想知道是否有这样的东西一个用于描述分词器的 haskell EDSL,非常类似于 Alex 的风格,但作为一个库。
Mixing the lexer and parsing phases in one phase sometimes makes Parsec parsers less readable but also slows them down. One solution is to use Alex as a tokenizer and then Parsec as a parser of the token stream.
This is fine but it would be even better if I could get rid of Alex because it adds one preprocessing phase in the compilation pipeline, doesn't integrate well with haskell "IDEs", etc. I was wondering if there was such a thing as an haskell EDSL for describing tokenizers, very much in the style of Alex, but as a library.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是 - http://www.cse.unsw.edu.au/ ~chak/papers/Cha99.html
在 Hackage 之前,Manuel 曾经在一个名为 CTK(编译器工具包)的包中发布代码。我不确定这些天项目的状态如何。
我认为 Thomas Hallgren 在论文“Lexing Haskell in Haskell”中的词法分析器是动态的,而不是代码生成器,而该版本是为词法 Haskell 量身定制的,库中的机制更加通用。 Iavor Diatchki 已将代码放在 Hackage 上。
http://hackage.haskell.org/package/haskell-lexer
Yes - http://www.cse.unsw.edu.au/~chak/papers/Cha99.html
Before Hackage, Manuel used to release the code in a package called CTK (compiler toolkit). I'm not sure what the status of project is these days.
I think Thomas Hallgren's lexer from the paper "Lexing Haskell in Haskell" was dynamic rather than a code generator, whilst the release is tailored to lexing Haskell the machinery in the library is more general. Iavor Diatchki has put the code on Hackage.
http://hackage.haskell.org/package/haskell-lexer
您也可以使用 Parsec 作为词法分析器。首先将字符串解析为标记,然后将标记解析为目标数据类型。
You can use Parsec as the lexer too. First you parse the string into tokens, then you parse the tokens into the target data type.