antlr

Parsing SQL like syntax, design pattern

人盡茶涼 提交于 2019-12-03 05:45:54
I am trying mock sql syntax to build a simple sql like interface to a key-value storage. The values are essentially POJOs An example would be select A.B.C from OBJ_POOL where A.B.X = 45 AND A.B.Y > '88' AND A.B.Z != 'abc'; OBJ_POOL is just a list of POJOs of the same class. In this example A would be the base class. Class A Class B String C Integer X String Y String Z Now A.B.C is equivalent A.getB().getC() I am using Antlr to parse the above statement to get an AST, and then hoping to use Apache BeanUtils to reflectively get/set the field names. I wrote the grammar thats builds an AST Now I

ANTLR: call a rule from a different grammar

China☆狼群 提交于 2019-12-03 04:18:35
is it possible to invoke a rule from a different grammar? the purpose is to have two languages in the same file, the second language starting by an (begin ...) where ... is in the second language. the grammar should invoke another grammar to parse that second language. for example: grammar A; start_rule : '(' 'begin' B.program ')' //or something like that ; grammar B; program : something* EOF ; something : ... ; Your question could be interpreted in (at least) two ways: separate rules from a large grammar into separate grammars; parse a separate language inside your "main" language (island

How to configure antlr4 plugin for Intellij IDEA

点点圈 提交于 2019-12-03 04:17:47
问题 I looked all over the place for how to configure the antlr4 plugin for IntelliJ IDEA. But I can't find anything. I was only able to install the plugin. If I add .g4 files manually for a empty project I get the "Generate ANTLR Recognizer" option in right click menu. That is all. I thought It was very promising plugin. Can anyone please tell/direct me how to proceed with the plugin ? Thank you 回答1: I installed the ANTLR plugin on IntelliJ 14 and was able to get it working. A couple little

Is the ANTLR parser generator best for a C++ app with constrained memory?

眉间皱痕 提交于 2019-12-03 04:10:22
I'm looking for a good parser generator that I can use to read a custom text-file format in our large commercial app. Currently this particular file format is read with a handmade recursive parser but the format has grown and complexified to the point where that approach has become unmanageable. It seems like the ultimate solution would be to build a proper grammar for this format and then use a real parser generator like yacc to read it, but I'm having trouble deciding which such generator to use or even if they're worth the trouble at all. I've looked at ANTLR and Spirit, but our project has

java.lang.StackOverflowError解决

♀尐吖头ヾ 提交于 2019-12-03 03:49:33
在使用JPA的仓储repository进行查询时,经常用到findAllbyId的方法: repository.findAllbyId() 但如果像下面的代码,当list的size量太大的话,就会报栈溢出的的错误:java.lang.StackOverflowError @RequestMapping("/stackOverFlow") public Integer stackOverFlow() { List<String> ids = new ArrayList<>(); for (int i = 0; i < 5000; i++) { ids.add("123123123123"); } List<BillDO> allById = dwBillRepository.findAllById(ids); return allById.size(); } 报错信息如下: Caused by: java.lang.StackOverflowError at antlr.BaseAST.toString(BaseAST.java:333) ~[antlr-2.7.7.jar:?] at antlr.BaseAST.toStringList(BaseAST.java:341) ~[antlr-2.7.7.jar:?] at antlr.BaseAST.toStringList

Tutorial for walking ANTLR ASTs in C#?

馋奶兔 提交于 2019-12-03 03:45:41
问题 Is anyone aware of tutorials for walking ANTLR-generated ASTs in C#? The closest I was able to find is this, but it's not terribly helpful. My goal is to walk through trees that I'm generating based on a domain-specific language that I'm working on, and to use the trees to output generated C# code. A Java-based tutorial would be helpful, too -- anything that provides clear examples of how to traverse ANTLR ASTs. 回答1: I managed to figure this out by adapting the example at the end of Manuel

In ANTLR 3, how do I generate a lexer (and parser) at runtime instead of ahead of time?

孤街醉人 提交于 2019-12-03 03:42:29
I want to generate an antlr lexer at runtime -- that is, generate the grammar and from the grammar generate the lexer class, and its supporting bits at runtime. I am happy to feed it into the the java compiler, which is accessible at runtime. Here's a quick and dirty way to: generate a combined (!) ANTLR grammar .g file given a String as grammar-source, and create a Parser & Lexer from this .g file, compile the these Parser & Lexer .java files, create instances of the Parser & Lexer classes and invoke the entry point of the parser. Main.java import java.io.*; import javax.tools.*; import java

Building own C# compiler using ANTLR: Compilation Unit

佐手、 提交于 2019-12-03 02:59:54
// Create a scanner that reads from the input stream passed to us CSLexer lexer = new CSLexer(new ANTLRFileStream(f)); tokens.TokenSource = lexer; // Create a parser that reads from the scanner CSParser parser = new CSParser(tokens); // start parsing at the compilationUnit rule CSParser.compilation_unit_return x = parser.compilation_unit(); object ast = x.Tree; What can I do with the x which is of compilation_unit_return type, to extract its root, its classes, its methods etc? Do I have to extract its Adaptor out? How do I do that? Note that the compilation_unit_return is defined as such in my

In ANTLR 3, how do I generate a lexer (and parser) at runtime instead of ahead of time?

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to generate an antlr lexer at runtime -- that is, generate the grammar and from the grammar generate the lexer class, and its supporting bits at runtime. I am happy to feed it into the the java compiler, which is accessible at runtime. 回答1: Here's a quick and dirty way to: generate a combined (!) ANTLR grammar .g file given a String as grammar-source, and create a Parser & Lexer from this .g file, compile the these Parser & Lexer .java files, create instances of the Parser & Lexer classes and invoke the entry point of the parser. Main

ANTRL4: Can&#039;t get Python ANTLR to generate a graphic of the parse tree

匿名 (未验证) 提交于 2019-12-03 02:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a simple HelloWorld.g4 grammar (see it at the bottom). I am able to successfully generate the .py files using this: set CLASSPATH=.;antlr-complete.jar;%CLASSPATH% java org.antlr.v4.Tool -Dlanguage=Python2 HelloWorld.g4 Now I would like to use the TestRig with the -gui flag to generate a parse tree GUI. I have the ANTRL Python runtime installed ( antlr4-python2-runtime-4.5.tar.gz ). I can open a Python interpreter and type: import antlr4 and the interpreter recognizes the antlr4 module. When I run the TestRig like this: set CLASSPATH=.