Can ANTLR 4 generate push parsers? - antlr4

Can ANTLR 4 generate push parsers, like bison does? Reference: http://www.gnu.org/software/bison/manual/html_node/Push-Decl.html
I am wondering if ANTLR is a good choice to implement parser stages in a data transformation pipeline. One configuration of the system is driven by the source stage pushing ByteBuffers upstream.
We have bought a copy of the "Definitive ANTLR 4 Reference" but a quick search in the book found no mention of something like this.

Related

Collection of Xtext Grammars as a library?

I am wondering if there is a library containing different grammar languages defined using Xtext, similar to the one available for Antlr v4 Antlr v4 Grammars. This would enable reuse and help reinventing the wheel.
No, there is no such thing, at least not as a single, integrated repository.
In the official documentation, there are the "Seven Languages In Seven Weeks" examples.
But depending on what you are trying to achieve, a basic grammar like Xbase or a textual modelling language like Xcore may serve your purpose. Other than that, you can search for real-life examples on Github.

Verify that a grammar is LL(1)

I want to verify that my ANTLR 4 grammar is LL(1). There is an option to do just that in older versions of ANTLR. Is there something similar in ANTLR 4?
I looked through through the documentation, but didn't find anything. Though especially the page on options seems to be lacking, I didn't even find a list of all possible options.
One of the design goals of ANTLR 4 is allowing language designers to focus on writing accurate grammars rather than worrying about characteristics like "LL(1)" which have little to no impact on users of the language.
However, it is likely that you can identify an LL(1) grammar by examining the generated parser. If there are no calls to adaptivePredict in the generated code, then the grammar is LL(1). The intent is for the inverse to also be true, but considering a call to adaptivePredict produces the same result as the inline version of an LL(1) decision, we have not rigorously evaluated this.

How can i manipulate the ATN-Constant generated by ANTLR V4 for Java?

I'm very new at ANTLR and use V4 to generate a lexer to integrate with netbeans.
The generated java-file gives me an error: "constant too long" at the serialized ATN.
How can i configure ANTLR to generate an compliant String (ore more of them)?
kind regards
Jan
This is a limitation of the first release of ANTLR 4 that has since been fixed. Here is the issue report:
Serialized ATN strings should be split when longer than 2^16 bytes (class file limitation)
Until ANTLR 4.1 is released sometime this Summer, you have two options:
Build a current version of ANTLR from source code, and use that.
Modify your lexer/parser to be simpler, thus requiring fewer states.

How can I build an AST using ANTLR4? [duplicate]

This question already has answers here:
How to create AST with ANTLR4?
(4 answers)
Closed 5 years ago.
I have an ANTLR3 grammar that builds an abstract syntax tree. I'm looking into upgrading to ANTLR4. However, it appears that ANTLR4 only builds parse trees and not abstract syntax trees. For example, the output=AST option is no longer recognized. Furthermore neither "AST" nor "abstract syntax" appears in the text of "The Definitive ANTLR4 reference".
I'm wondering if I'm missing something.
My application currently knows how to crawl over the AST produced by ANTLR3. Changing it to process a parse tree isn't impossible but it will be a bit of work. I want to be sure it's necessary before I start down that road.
ANTLR 4 produces parse trees based on the grammar instead of ASTs based on arbitrary AST operators and/or rewrite rules. This allows ANTLR 4 to automatically produce listener and visitor interfaces that you can implement in the code using your grammar.
The change can be dramatic for users upgrading existing applications from version 3, but as a whole the new system is much easier to use and (especially) maintain.

Is ANTLR 4 faster than ANTLR 3?

What should I expect from ANTLR 4?
Is it faster ANTLR 3? I mean the parsing speed.
Note code generation speed would be interesting too.
For design reasons?
First the easy part - the ANTLR 4 tool performs only minimal analysis of the grammar, and in particular does not need to statically compute the DFA tables like ANTLR 3 did. As such, it's much, much faster than ANTLR 3 for generating parsers.
The initial 4.0 release of ANTLR 4 varies from slightly faster than ANTLR 3 to much slower than it, depending on the grammar and input. However, ANTLR 4 is able to handle many grammars and inputs that ANTLR 3 simply cannot handle at all. In addition, an optimized version of the ANTLR 4 runtime which substantially outperforms ANTLR 3 is already in development.
Debugging aids and how-to documentation is coming which helps users find and correct (or avoid) performance problems related to grammar design. I believe some of this is available in the ANTLR 4 book as well.

Resources