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

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

问题描述

最近我拿起了权威ANTLR 4参考的副本,因为我在处理语法和语言方面很老练,所以我想在我的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++ 输出,对吗?

(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/wiki/display/ANTLR3/代码+生成+目标

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.

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

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