antlr4 Questions

1

Consider the following grammar. I have issues with the operator priority, for instance: res=2*a+b has a similar parse tree as res=2*(a+b). I know where the problem is, but no "beautiful" solution w...
Foliated asked 31/10, 2017 at 9:10

5

Solved

How to handle nested comments in antlr4 lexer? ie I need to count the number of "/*" inside this token and close only after the same number of "*/" have been received. As an example, the D language...
Thence asked 18/12, 2014 at 4:40

2

I am trying to set up a simple project with Antlr in .net core 1.0 project using VS2017. Following https://github.com/sharwell/antlr4cs, added .g4 file to the project. The project file looks like ...
Tosha asked 3/3, 2017 at 0:17

1

Solved

I am presently getting... error(56): AqlCommentTest.g4:12:4: reference to undefined rule: htmlCommentDeclaration error(56): AqlCommentTest.g4:13:4: reference to undefined rule: mdCommentDeclaratio...
Ribbonwood asked 28/9, 2017 at 22:33

1

Solved

Note: This is a self-answered question that aims to provide a reference about one of the most common mistakes made by ANTLR users. When I test this very simple grammar: grammar KeyValues; k...
Aloes asked 17/9, 2017 at 19:21

1

I am developing a compiler using ANTLR and LLVM. I have already implemented a lexer and a parser using ANTLR 4's Eclipse IDE. I want to implement a semantic analyzer and a code generator using LLVM...
Serving asked 20/8, 2015 at 5:57

1

I've created this sample grammar using the ANTLR4 plugin in IntelliJ and when I use its tool chain to generate a visual representation for some invalid content (in this case an empty string), this ...
Rosary asked 29/8, 2017 at 17:32

1

Solved

I am trying to split my ANTLR4 grammar in multiple files so i can test them more easily, i am using gradle as a build tool in a java project. Both grammar compile correctly by separate but when i ...
Butyrin asked 3/9, 2017 at 16:36

0

The view Parse Tree in Eclipse Oxygen is empty and white. I can compile my Hello.g4 grammar, see the Syntax Diagram but the Parse Tree view is empty. How can I fix it?
Zig asked 24/8, 2017 at 20:37

2

Solved

I am using antlr v4 for extracting parse tree of java programs for other purposes. I have started from this sample: ANTLR v4 visitor sample And I have tested the steps on given link to check if it...

1

Solved

I want to use Antlr to create parser and i followed instruction from Here after following all instruction while I am running following command antlr4 -visitor D:\T\arithmetic.g4 I am getting thi...
Sungkiang asked 5/8, 2017 at 7:32

1

Solved

I have 2 simple lexer rules in my ANTLR4 grammar: fragment Attrs : '.' ARCH; fragment ARCH : 'IA32' | 'X64' | 'IPF' | 'EBC' | 'common'; The generated ATN with ANTLR4.7 is like this (Visual Studio...
Snooty asked 3/8, 2017 at 1:25

1

I want to get the specific error message of ANTLR4's parser. And I found that there are two way to handle error: errorListener and errorHandler. // set error handler parser.removeErrorListeners();...
Leschen asked 31/7, 2017 at 2:57

2

Is there a way to tell ANTLR4 to inline the parser rule? It seems reasonable to have such feature. After reading the book on ANTLR ("The Definitive ANTLR 4 Reference") I haven't found such possibi...
Adenocarcinoma asked 19/7, 2017 at 12:52

2

Solved

I'm trying to convert my grammar from v3 to v4 and having some trouble finding all the right pieces. In v3 to process a String, I used: public static DataExtractor create(String dataspec) { Char...
Salivate asked 7/8, 2013 at 17:45

1

Are there any good CSS grammars out there for antlr4? I know there are some grammars for antlr3, but it turns out CSS is not trivial to parse without "lexer modes", which were added in v4. Why? Co...
Dissemble asked 3/9, 2013 at 23:39

1

Solved

With the help of this SO question How to create AST with ANTLR4? I was able to create the AST Nodes, but I'm stuck at coding the BuildAstVisitor as depicted in the accepted answer's example. I hav...
Listel asked 16/5, 2017 at 14:16

0

I am trying to use a 3rd party typescript library(antlr - https://github.com/tunnelvisionlabs/antlr4ts) in my angular 2 project created using angular-cli. It's failing with this error class constru...
Cystocele asked 1/5, 2017 at 20:7

1

Writing a pretty-printer for legacy code in an older language. The plan is for me to learn parsing and unparsing before I write a translator to output C++. I kind of got thrown into the deep end wi...
Diligence asked 11/1, 2016 at 20:8

1

Solved

I am using ANTLR4 with Python and I am currently using the following code for parsing: lexer = MyGrammarLexer(FileStream(path)) stream = CommonTokenStream(lexer) parser = MyGrammarParser(stream) r...
Ulda asked 17/1, 2017 at 9:49

1

Solved

This is a demo code label: var id let id = 10 goto label If allowed keyword as identifier will be let: var var let var = 10 goto let This is totally legal code. But it seems very hard to do t...
Jemine asked 2/1, 2017 at 5:13

1

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 ...
Oxfordshire asked 16/12, 2016 at 8:48

2

I've got an ANTLR 4 grammar and built a lexer and parser from that. Now I'm trying to instantiate that parser in such a way that it will parse until it encounters an error. If it encounters an erro...
Gaberones asked 10/3, 2016 at 18:50

1

Solved

If I have an AST and modify it, can I use StringTemplates to generate the source code for the modified AST? I have successfully implemented my grammar for Antlr4. It generates the AST of a source ...
Balustrade asked 7/7, 2016 at 9:53

2

We're starting a project where we will need to parse python source files in a C++ application. I've used Antlr2 a while back to generate a few compilers, but this is the first time I'm using Antlr4...
Sarcocarp asked 12/5, 2015 at 0:41

© 2022 - 2024 — McMap. All rights reserved.