用Lisp编写正式的语言解析器 [英] Writing a formal language parser with Lisp
问题描述
我的公司正在设计一种新的特定于域的脚本语言;我必须实现一个解析器,才能将我们全新的编程语言转换为通用的脚本语言,以便能够执行它.
My company is designing a new domain specific scripting language; I have to implement a parser that translates our brand new programming language into a common scripting language so as to be able to enact it.
通常这样做的方法是使用Bison
和Flex
工具生成翻译程序的C/C++
代码.
The usual way I do this is by means of Bison
and Flex
tools that generate the C/C++
code of the translator.
对于大多数主流编程语言,我发现了其他工具,但对于Lisp
,却没有.
I found other tools, for most of the mainstream programming languages, but none for Lisp
.
从未使用过Lisp
吗?用Lisp
编写解析器的通常方法是什么?
Hasn't Lisp
ever been used for that? What is the usual way to write a parser with Lisp
?
注意:对我来说,任何可以帮助的Lisp
实现/方言都可以,我没有任何偏好.
Note: to me, any Lisp
implementation / dialect that could help is ok, I do not have any preference.
推荐答案
覆盖其中的球拍部分:
人们经常编写解析器,并且有很多方法可以这样做:
People often write parsers and there are many ways to do so:
- 手动编写递归下降解析器.
- 使用lex/yacc样式的Racket中的 parser-tools 库. /li>
- 使用 Ragg ,这是一种AST生成器生成器,可让您编写BNF.
- 使用 Parsack ,这是类似于Haskell的Parsec的单语法分析器组合器库.
- 我可能至少忽略了六种其他选择(例如,我知道Racket至少有一个PEG样式库).
- Write a recursive descent parser manually.
- Use the parser-tools library in Racket, which is lex/yacc style.
- Use Ragg, an AST generator generator letting you write BNF.
- Use Parsack, a monadic parser combinator library similar to Haskell's Parsec.
- I'm probably overlooking at least a half-dozen other options (e.g. I know there's at least one PEG style lib for Racket).
这篇关于用Lisp编写正式的语言解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!