antlr4

What are the ways to speed up parsing in Antlr4?

安稳与你 提交于 2020-08-19 05:34:08
问题 I have some doubts regarding the performance of Antlr4. I am currently using Python with Antlr4. It is terribly slow compared to Java (Verified using Antlr4 IntelliJ plugin). Since I need to work with bigger codes for parsing, I am planning to switch to a language which will be the fastest with Antlr (Eg: Java, C or Python). Any suggestions? Any tips on optimizing the Antlr grammar for faster parsing (I am trying some online resources) If I continue with Python itself, what are the best ways

Using Visitors in AntLR4 in a Simple Integer List Grammar

左心房为你撑大大i 提交于 2020-08-05 05:50:10
问题 I'm a newbie in AntLR. I'm using AntLR4 version. I wrote the following attribute grammar that recognizes a list of integers and print the sum of the list at the end. list.g4 grammar list; @header { import java.util.List; import java.util.ArrayList; } list : BEGL (elems[new ArrayList<Integer>()])? ENDL { int sum = 0; if($elems.text != null) for(Integer i : $elems.listOut) sum += i; System.out.println("List Sum: " + sum); } ; elems [List<Integer> listIn] returns [List<Integer> listOut] : a=elem

ANTLR Visitor Class is returning null for Parse tree in C#

时光总嘲笑我的痴心妄想 提交于 2020-07-23 08:24:10
问题 I am trying to build an AST using the visitor pattern on ANTLR Java Grammar (Java Grammar) in C# (.Net Core 3.1). I have created IJavaParserVisitor , JavaParserbaseVisitor , JavaLexer , and JavaParser file for grammar and created parse tree for java source file. But when I am trying to create AST using JavaParserBaseVisitor.Visit() I am getting null as a result. AntlrFileStream stream = new AntlrFileStream(file); ITokenSource lexer = new JavaLexer(stream); ITokenStream tokens = new

ANTLR Visitor Class is returning null for Parse tree in C#

孤人 提交于 2020-07-23 08:23:06
问题 I am trying to build an AST using the visitor pattern on ANTLR Java Grammar (Java Grammar) in C# (.Net Core 3.1). I have created IJavaParserVisitor , JavaParserbaseVisitor , JavaLexer , and JavaParser file for grammar and created parse tree for java source file. But when I am trying to create AST using JavaParserBaseVisitor.Visit() I am getting null as a result. AntlrFileStream stream = new AntlrFileStream(file); ITokenSource lexer = new JavaLexer(stream); ITokenStream tokens = new

ANTLR Visitor Class is returning null for Parse tree in C#

|▌冷眼眸甩不掉的悲伤 提交于 2020-07-23 08:22:10
问题 I am trying to build an AST using the visitor pattern on ANTLR Java Grammar (Java Grammar) in C# (.Net Core 3.1). I have created IJavaParserVisitor , JavaParserbaseVisitor , JavaLexer , and JavaParser file for grammar and created parse tree for java source file. But when I am trying to create AST using JavaParserBaseVisitor.Visit() I am getting null as a result. AntlrFileStream stream = new AntlrFileStream(file); ITokenSource lexer = new JavaLexer(stream); ITokenStream tokens = new

Reuse Antlr objects for a new input string (C++ runtime)?

天大地大妈咪最大 提交于 2020-06-23 04:23:44
问题 I've built a basic parser using the C++ runtime demo and it works fine. However I typically parse a lot of input strings, can the code be modified to reuse existing objects for repeated calls? If so, does anyone have an example of this? 回答1: Yes, reusing the objects is possible. A typcial sequence for a parse call looks like this then: input.load(newText); errors.clear(); lexer.reset(); lexer.setInputStream(&input); // Not just reset(), which only rewinds the current position. tokens

Reuse Antlr objects for a new input string (C++ runtime)?

大憨熊 提交于 2020-06-23 04:23:01
问题 I've built a basic parser using the C++ runtime demo and it works fine. However I typically parse a lot of input strings, can the code be modified to reuse existing objects for repeated calls? If so, does anyone have an example of this? 回答1: Yes, reusing the objects is possible. A typcial sequence for a parse call looks like this then: input.load(newText); errors.clear(); lexer.reset(); lexer.setInputStream(&input); // Not just reset(), which only rewinds the current position. tokens