http://www.antlr.org/article/1136917339929/stringTemplate.html这篇文章分析比较了antlr和StringTemplate
http://www.stringtemplate.org/,其中一段比较有趣,看起来CSS和Antlr还有一定相似性的。StringTemplate则类似于直接在HTML标签中嵌套修饰性标签(如</b>等)。
引用
HTML and CSS Analogy
The situation here is analogous to that with HTML and CSS, and I don't just mean in the way CSS separates the "view" from the "data". CSS is great because instead of embedding, say, "bold" tags inside every "code" tag, you can simply say "everything inside a "code" tag should be in bold", and you say that in just one place. But if you're generating the HTML pages, and you have a 10,000 line program that generates all the HTML, you're surely going to have some sort of START_CODE_STRING constant anyway, and you can easily change that from "<code>" to "<code><b>". The only advantage that staying with CSS gives you is that the CSS could be changed later, after compile time, perhaps even by the person reading the page.
But there is no equivalent advantage (that I can see) in the StringTemplate case. Using StringTemplate to translate C to Java, you'd end up with a simple call to doEverythingRelatedToFunctionDeclarations() inside your parser, and a simple call to showWhateverWasProducedByThatOtherCall() as your output specification.
Another way to look at it is this. Suppose your generated HTML page is extremely dynamic - its look can vary completely based on the input. So you have a huge program that generates the HTML. Does it really matter whether the program generates the entire HTML page vs. having an HTML page that has one huge JSP tag? If you really can specify "the look" all in HTML, and "the data" is all generated, that's one thing. But when you're doing high-level language translation and your output is, say, Java code, there is no clear distinction between "a look" and "data". It's all just "code"! In the HTML-generating situation, by the time you're generating almost the whole page anyway, there's no advantage to even having a little bit of static HTML wrapping all that generated code. And if you're going to have 10,000 lines of code that handles converting any C function call to some equivalent Java code, then does it even make sense to have a "process all function calls here" architecture? It would make more sense to have hundreds of pattern-matching rules: one that replaces printf() calls, another that replaces read() calls, etc.
分享到:
相关推荐
2. **ANTLR的安装与配置**:介绍如何在不同的开发环境中安装ANTLR库,如在Java、Python等环境下的设置步骤。 3. **语法规则定义**:详细解释ANTLR语法文件的结构,如如何定义关键字、标识符、运算符等词法单元,...
- **兼容性**:确保你的项目环境与ANTLR 2.7.7兼容,因为它可能不支持最新的Java版本和其他开发工具。 - **维护**:由于是旧版本,可能存在的bug或安全问题可能得不到官方更新修复,需要自行评估风险。 - **文档和...
1. 兼容性:确保所选版本与项目的其他依赖项和Java运行环境兼容。 2. 功能需求:如果新版本提供了你需要的功能,那么升级是有益的。 3. 稳定性:较新的版本可能更稳定,但有时候老版本在特定场景下表现更好。 4. ...
手册强调了掌握ANTLR3对于职业发展的重要性,指出即使不具备编译器开发背景,也能通过学习ANTLR3来开发自己的领域特定语言,这对于提高工作效率和解决复杂问题具有重大意义。 ### Eclipse CDT项目与ANTLR3 Doug ...
ANTLR(ANother Tool for Language Recognition)是一个强大的解析器生成器,用于读取、处理、执行或翻译结构化文本或二进制文件。ANTLR被广泛应用于各种编程语言的编译器和解释器的构建,它能生成Java、C#、Python...
ANTLR的强大在于其灵活性和多样性,它可以处理各种复杂的语法定义,并生成高效、可维护的解析代码。配合"antlr.LICENSE.txt"文件,用户可以了解并遵守ANTLR的开源许可证规定,合法地在自己的项目中使用这一强大的...
ANTLR4 是一个强大的解析器生成器,用于读取、处理、执行或翻译结构化文本或二进制文件。它广泛应用于构建语言、工具和框架,包括SQL、Java、C#、JavaScript、Python等。在本项目中,"Antlr4 C++ 计算器"是一个基于...
总结来说,ANTLR 4.6是一个强大的解析器生成工具,新增的Go语言支持拓宽了其应用范围,使得Go开发者也能受益于ANTLR的高效和灵活性。对于任何需要处理结构化数据或构建自定义语言工具的开发者来说,理解和掌握ANTLR ...
虽然Xtext不是直接用于ANTLR,但它可以与ANTLR结合使用,帮助开发者构建基于ANTLR的语言工具链。 在配置ANTLR开发环境时,首先需要确保你的Eclipse已经安装了ANTLR 4 IDE插件。这通常可以通过Eclipse的内置软件更新...
它允许在规则中使用动作代码,使解析过程与目标代码紧密集成。 2. **自动错误恢复**:ANTLR 4具有内置的错误恢复机制,当输入不匹配预期的语法时,它可以尝试恢复解析,继续处理剩余输入,而不是立即停止。 3. **...
1. 语言定义灵活性:ANTLR 的语言定义可以非常灵活,甚至可以是自然语言,而 GraphQL 的语言定义更加结构化。 2. 后端支持:ANTLR 只需要后端支持,而 GraphQL 需要同时支持前端和后端。 然而,GraphQL 也有其优势...
6. **运行时库**: ANTLR4运行时库提供了与生成的解析器和词法分析器交互的API,包括错误处理、输入流管理等功能。 7. **测试用例和示例**: 通常源码仓库会包含一些测试用例和示例,用于验证ANTLR4的正确性和展示其...
3. **树遍历与处理(Tree Traversal and Processing)**:ANTLR生成的解析器可以生成AST,用户可以编写自定义的访问者(visitor)或监听者(listener)模式来遍历和处理AST,执行实际的业务逻辑或代码生成。...
ANTLR(ANother Tool for Language Recognition)是一门强大的解析器生成器,主要用于读取、处理、执行或翻译结构化文本或二进制文件。它广泛应用于编程语言、配置文件、通信协议、标记语言等领域,能够自动生成词法...
### ANTLR 入门与编译领域应用 #### 一、引言 ANTLR(ANother Tool for Language Recognition)是一款强大的语法解析工具,主要用于编译原理的学习和实践,特别是词法分析和语法分析方面。它是由Terence Parr教授...
通过学习ANTLR,开发者可以更高效地处理结构化数据,减少手动编写解析代码的工作量,提升软件的可靠性和可维护性。 在提供的两个PDF文件中,《ANTLR入门_Terence Parr.pdf》应该是原版英文书籍的扫描版或电子版,...
antlr 2.7.7源码,下载自:http://repo.spring.io/plugins-release/org/antlr/com.springsource.antlr/2.7.7/
1. **ANTLR 4概述**:首先,书籍会介绍ANTLR 4的基本概念,包括它的历史、目标以及与前代版本的区别。ANTLR 4引入了许多改进,例如更高效的解析算法、高级的错误处理机制以及对Unicode的全面支持。 2. **语法规则**...