将ANTLR 4集成到C ++应用程序中 [英] Integrating ANTLR 4 in a C++ application

查看:949
本文介绍了将ANTLR 4集成到C ++应用程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我拿起一份 The Definitive ANTLR 4 Reference 的副本,由于我在处理语法和语言方面很复杂,我想在我的DSL上工作一次使用 yacc bison 写成。一般的想法是写一个翻译器(包括类型安全验证(1)),它在运行时将DSL翻译成JavaScript,然后由v8执行。

Recently I picked up a copy of The Definitive ANTLR 4 Reference and since I am sophisticated when it comes to working with grammars and languages I wanted to work on my DSL I once have written using yacc and bison. The general idea is to write a translator (with included validation for type safety(1)) which translates the DSL to JavaScript during runtime which is then executed by v8.

虽然ANTLR被设计为包含在Java应用程序中,我想留在本地C ++。 ANTLR 4可以生成这样的C语法分析器/词法分析器(2),我可以使用C ++样式的包装器来包含它?

Although ANTLR was designed for inclusion in Java applications I would like to stay with native C++. Can ANTLR 4 produce such a C parser/lexer(2) which I can include using a C++-style wrapper? And how to do so?

(1)这本书有一些很好的例子,将用作模板。

(2)我不确定,但我认为我在某处读到ANTLR不支持C ++中的输出,是吗? p>

(1) The book has some good examples which I will use as a template.
(2) I am not sure but I think that I read somewhere that ANTLR doesn't support output in C++, am I right?

推荐答案

ANTLR v3有各种不同的目标,最值得注意的是Java(当然),C,C#,JavaScript和Python。有关完整列表,请参阅: http://www.antlr.org/

ANTLR v3 has various different targets, most notably Java (of course), C, C#, JavaScript and Python. For a full list, see: http://www.antlr.org/wiki/display/ANTLR3/Code+Generation+Targets

ANTLR v4,但目前只有Java目标。

ANTLR v4, however, only has a Java target at this moment.

这篇关于将ANTLR 4集成到C ++应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆