Skip to content
Advertisement

Tag: antlr

How to get from parse tree to Java class file

I am working on a command-line tool with the following functionality: Parse modified .java files using an extended ANTLR4 Java9 grammar. The syntax in the files is Java, with one modification to the method declaration which includes a purpose, like in this example: public void {marketing} sendEmail() {} Collect and remove all purposes using a visitor. Collection and analysis of

ANTLR AST visitor that returns different data types

I finished converting the ANTLR CST into an AST and created a specific Visitor<T> interface that allows me to visit all my AST nodes, but the main issue i’m having is that some visits should return different data types, and i’m not sure how to go about this. For example, for simple arithmetics operations i want to return a double

How to parse Java code in Python using ANTLRv4

I’m trying to parse some Java code in Python using ANTLRv4. I’ve tried to follow this post, but I get the following error: I can’t figure out what I’m doing wrong. The file I’m trying to parse is proper Java, it’s extracted from the docker-maven-plugin package. I’ve tried with other files, but I get the same error. Any idea ?

Separate definitions of decimal number and word in ANTLR grammar

I’m working on defining a grammar in ANTLR4 which includes words and numbers separately. Numbers are described: and words are described: The simplified grammar below describes the addition between either a word or a letter (and needs to be defined recursively like this): The issue is that when I enter ‘d3’ into the parser, I get a returned instance of

Can Antlr ignore some of the keyword?

I’m new to Antlr but I’m trying to change some of the Grammar from my existing project. The example of the grammar looks like this The grammar is supposed to parse something like this a=10 AND s=1 AND s=2 or ((a=9 AND s=1) AND s=2). The question is is it possible to ignore anything that’s not s={ANYTHING}. So from the

How to force ANTLR to parse all input CharStream

I’m using ANTLR4 to parse a syntax file. When I use BaseErrorListener to detect errors, I got a problem. When faced with an illegal input string, ANTLR automatically matches the appropriate branch and then ignores the subsequent stream of characters even if it contains errors. And I want to detect that error. Here are my g4 file and java file.

Advertisement