antlr

基于ANTLR语法树编写解释引擎最佳实践

你说的曾经没有我的故事 提交于 2019-12-23 02:31:05
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> Tiny模板引擎的实现方式原来是采用的编译方式,最近发生了一些问题,因此我觉得有必要把编译方式调整为解释方式,为此就开始了此次实现活动。 编译方式存在的问题 当时采用编译方式,主要是考虑到编译方式在运行时不必再去遍历语法树,因此就采用了编译方式。但是在实际应用当中,出现了如下问题: 文件路径冲突的问题 由于采用的是编译方式,这个时候就存在在一个选择,即:Java源代码落地或不落地的选择。如果Java文件不落地,则在有问题的时候,如果想要进行代码调试(虽然这种场景并不多见),那么就没有源代码可供调试。如果Java代码落地,则会存在一个问题,那就是资源文件在磁盘文件中产生冲突的问题。 同样的问题对于class文件也存在,如果不落地,那么每次应用重启动的时候,都要重新编译这些文件以产生class文件;如果落地,则也会产生冲突的问题。 当然,Tiny模板引擎通过增加一个配置项,解决了这个冲突的问题,但是由于增加了一个配置项,从客观上增加了维护人员的工作量,也容易造成当维护人员不了解这里面的道道,忘记设置从而导致在一台服务器中部署多个Tiny应用时多个应用中的模板文件生成的java文件和class文件的冲突,从而导致出现问题。 PermSize内存占用问题 采用编译方式的时候,由于每个模板文件都要生成一个类

为什么 antlr 用于模板引擎不是个好主意

爱⌒轻易说出口 提交于 2019-12-23 02:19:09
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 我在发布 jfinal 3.0 的时候认为 antlr 用于 "模板引擎" 并不是个好主意,两年多时间过去了,我的观点更进一步:认为 antlr 在多数 “非模板引擎” 的场景下使用也不是个好主意。 在发布 jfinal 3.0 的时候谈到 antlr,只言片语信息量太少,引起了部分人的误解,今天就来稍稍展开聊一聊。 一、antlr 生成 Parser 难于调试、难于阅读 首先现场直观来感受一下 jfinal 手写 Parser 与使用 antlr 生成的 parser 的对比,下面是为 jfinal enjoy 模板引擎手写的 parser: https://gitee.com/jfinal/jfinal/blob/master/src/main/java/com/jfinal/template/stat/Parser.java 空行 + 注释 + java 代码一共 278 行,干净利落,人类轻松阅读。更重要的是其用到的 Recursive Descent 算法简洁可靠,功能强大,随手可得。了解这个算法原理的同学几个小时就可以手撸一个自己的 Parser 出来。 再来看一下 antlr 为模板引擎生成的 parse: https://gitee.com/xiandafu/beetl/blob/master

Switching to island mode on multi-character token

陌路散爱 提交于 2019-12-23 02:04:11
问题 I am working on a grammar that is basically an island grammar. Let's say the "island" is everything between braces, the "sea" is everything that is not. Like this: { (island content) } Then this simple grammar works: IslandStart : '{' -> pushMode(Island) ; Fluff : ~[\{\}]+ ; .... But I'm having trouble to come up with a similar solution to a case where I want the complex (multi-character) opening for my "island" block, like this: {# (island content) } In this case I don't know how to make a

When rewriting tree on ANTLR, java.lang.NullPointerException is thrown

北城余情 提交于 2019-12-23 01:56:25
问题 I'm trying to create a parser for QuickBasic and this is my attempt to get the comments: grammar QuickBasic; options { language = 'CSharp2'; output = AST; } tokens { COMMENT; } parse : .* EOF ; // DOESN'T WORK Comment : R E M t=~('\n')* { Text = $t; } -> ^(COMMENT $t) | Quote t=~('\n')* { Text = $t; } -> ^(COMMENT $t) ; Space : (' ' | '\t' | '\r' | '\n' | '\u000C') { Skip(); } ; fragment Quote : '\''; fragment E : 'E' | 'e'; fragment M : 'M' | 'm'; fragment R : 'R' | 'r'; Even if I rewrite

Looking for Antlr 3 / C sample main()

让人想犯罪 __ 提交于 2019-12-23 01:41:45
问题 I see a few sample main() for C floating about, e.g. http://www.antlr.org/wiki/display/ANTLR3/Five+minute+introduction+to+ANTLR+3 and http://www.antlr.org/api/C/index.html The dereference seems to be AST. I don't know what that is , and - please excuse me - don't want to if I can avoid it. I woudl like to just define the lexer & grammar (for modem AT commands) and have the main() auto-generated, or cut/pasted from somewhere. Ons slight twist is that most examples seem to read from a file,

Modify expressions, generated by Antlr?

依然范特西╮ 提交于 2019-12-23 01:41:32
问题 I would like to read expressions with Antlr4 and the perform some modifications on them. For example, if grammar is arithmetic, I would modify expression, representing 2 * (3 + 1) with 2 * 4 and then with 8 This is "calculation" or "simplification". To perform this thing I would create some tree structure and the first idea is to use the very same trees, created by Antlr. Unfortunately, I don't see any setters for children. How to accomplish? Should I really duplicate Antlr trees with my own

Antlr and PL/I grammar

元气小坏坏 提交于 2019-12-22 12:51:12
问题 Right now we would like to have the grammar of PL/I, COBOL based on Antlr4. Is there anyone provide these grammars If not, can you please share your thought/experience on developing these grammars from scratch Thanks 回答1: I assume you mean IBM PL/I and COBOL. (Not many other PL/Is around, but I don't think that really changes the answer much). The obvious place to look for mature ANTLR grammars is ANTLR3 grammar library; no PL/1 or COBOL grammars there. The Antlr V4 (a very new, radical,

Antlr and PL/I grammar

爱⌒轻易说出口 提交于 2019-12-22 12:51:01
问题 Right now we would like to have the grammar of PL/I, COBOL based on Antlr4. Is there anyone provide these grammars If not, can you please share your thought/experience on developing these grammars from scratch Thanks 回答1: I assume you mean IBM PL/I and COBOL. (Not many other PL/Is around, but I don't think that really changes the answer much). The obvious place to look for mature ANTLR grammars is ANTLR3 grammar library; no PL/1 or COBOL grammars there. The Antlr V4 (a very new, radical,

Status of Javascript in antlr 3.4 or 3.5 [closed]

佐手、 提交于 2019-12-22 11:14:29
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . What is the status of the JavaScript target in ANTLR 3.4 or 3.5? I have been looking online for an answer to this question but so far I have found nothing. I know that it was broken in v3.2 and then it was fixed in v3.3, but it's not listed in the ANTLR 3.4 release notes as a

回波总

天大地大妈咪最大 提交于 2019-12-22 11:02:18
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 波总好, 在 谈谈我对 JFinal Marketing 的一些看法 那篇博文的评论中 我们谈论到了 ANTLR, 这里继续和波总谈谈在技术上我对这方面的理解. 先说下 ANTLR 到底什么. ANTLR 官网给自己的定义是: ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files. It's widely used to build languages, tools, and frameworks. From a grammar, ANTLR generates a parser that can build and walk parse trees. 简单地说 ANTLR 是一个词法语法分析工具, 它不是一个应用层面的库, 也不是为应用程序开发使用的. ANTLR 的用户是需要定义某种语法, 并实现对该语法文件的解析的库开发者. 对 ANTLR 的应用场景在 这篇文章 中有更多的介绍. 下面列举几个使用 ANTLR 的项目: Groovy - 解析