Questions tagged [antlr4]
Version 4 of ANother Tool for Language Recognition (ANTLR), a flexible lexer/parser generator. ANTLR4 features an enhanced adaptive LL(*) parsing algorithm, that improves on the simpler LL(*) algorithm used in ANTLR3.
3,925
questions
0
votes
1
answer
16
views
Parsing Python code using ANTLR in Java with gradle
Context
I am trying to parse some Python code, and find a function inside a .py file using ANTLR. However I am experiencing some difficulties understanding how to use ANTLR within java.
build.gradle
...
1
vote
2
answers
55
views
Is the ANTLR4 PostgreSQL Grammar broken?
I have downloaded Lexer and Parser .g4 files from github grammars-v4
In Visual Studio I started a new Class Library project with the packages Antlr4 4.6.6 and Antlr4.Runtime.Standard 4.13.1
When I ...
0
votes
0
answers
25
views
antlr4 - not getting function correctly [duplicate]
grammar Expr;
// parser rules
prog : ((decl_list expr_seq | expr_seq) ';' NEWLINE?)*;
decl_list : decl (decl)*;
expr_seq : expr (expr)*;
decl : DEF fun var_list '=' expr ENDEF
| DEF fun '=' ...
0
votes
0
answers
20
views
antlr4 - mismatched input and not catching function syntax in lexer [duplicate]
grammar Expr;
// parser rules
prog : ((decl_list expr_seq | expr_seq) ';' NEWLINE?)*;
decl_list : decl (decl)*;
expr_seq : expr (expr)*;
decl : DEF fun var_list '=' expr ENDEF
| DEF fun '=' ...
0
votes
1
answer
32
views
antlr4 - parsing f1vae
grammar Expr;
// parser rules
prog : ((decl_list expr | expr) ';' NEWLINE?)*;
decl_list : decl decl_list
| decl
;
decl : DEF fun var_list '=' expr ENDEF
| DEF fun '=' expr ENDEF
...
0
votes
1
answer
40
views
ANTLR 4 - not parsing correctly
grammar Expr;
// parser rules
prog : ((decl_list expr | expr) ';' NEWLINE?)*;
decl_list : decl decl_list
| decl
;
decl : DEF FUN var_list '=' expr ENDEF
| DEF FUN '=' expr ENDEF
...
-1
votes
0
answers
29
views
Why can't the IDEA ANTLR4 plugin generate the expected files for a lexer grammar .g4 file?
I'm new to antlr4,and my question is that why can't the plugin generate the expected files like the 'hello.g4' generated with the plugin?
use the plugin to generate a list of files like '...
1
vote
1
answer
26
views
Grammar with issues - optional block with at least one alternative that can match an empty string
I am in process of writing a new grammar file for openHAB project configuration files. Existing implementation rely on Eclipse Xtext which is great for IDE tooling, but makes things pretty hard when ...
0
votes
1
answer
26
views
Antlr left recursion
I'm writing a simple language but I have a left recursion that I don't know how to solve.
booleanExpression
: expression EQUALS expression
;
numericExpression
:
;
expression
: ...
0
votes
1
answer
43
views
Trouble with ANTLR Visitor Pattern - Not Entering visitExpressFrag Method
I am working on a lexical and syntax analyser that I amimplementing semantic analysis and intermediate representation generation using ANTLR, and I've encountered a problem with my visitor ...
0
votes
0
answers
20
views
How to auto-complete JSON syntax strings?
Specifically, it is required that given the string above, the output will be the next character set that matches the JSON syntax.
Example 1: All Possible Next Tokens for the empty text ("") ...
0
votes
1
answer
86
views
mismatched input ''.'' in ANTLR4
I am new to ANTLR4 and my grammar contains a rule STRING: '\'' (~'\'' | '.' | '\\\'')* '\'' ;, but when I try to parse something containing '.' I obtain the error mismatched input ''.'' expecting {'(',...
0
votes
1
answer
32
views
ANTLR Mismatched input 'echo 1' expecting {'<', '>', ''', '`', '"', WS, UNQUOTED}
The grammar I wrote is meant to parse Shell commands.
grammar cmdline;
command : call | pipe | command ';' command;
pipe : call '|' call
| pipe '|' call ;
call : WS? (...
0
votes
1
answer
69
views
Purpose of ANTLR lexer "tokens" section
The docs for lexer rules shows the following example for the lexer command type(...)
lexer grammar SetType;
tokens { STRING }
DOUBLE : '"' .*? '"' -> type(STRING) ;
SINGLE : '\'' .*? '\'...
0
votes
0
answers
30
views
Must the Antlr generation tool version match the runtime version?
I have a project with a custom grammar, and I'm using using Antlr4 to generate the parser. I also include a third party lib, which just so happens to use Antlr4 to implement the stuff that they are ...
0
votes
0
answers
70
views
ANTLR C# target running faster in profile mode
I have a complex tool using ANTLR. It is written in C#.
My tool takes more than 3 minutes to process a file.
Unless I set the profiling option to true:
parser.Profile = true;
Now, the file processes ...
1
vote
1
answer
51
views
Drawing cfg using antlr4, graphiz and python and parser is empty
I am using 2 files I will be sharing link if any doubt can visit one is cfg_from_stding.py and cfg_extractor_visitor.py and also I will share the lexer and go file go file is simple and correct.
I ...
-2
votes
1
answer
70
views
ANTLR4 Visitor Method cannot find symbol Error in Java
I'm working with ANTLR4 in Java to create a custom language parser. I've generated my lexer and parser using a grammar file (CCAL.g4), and I'm implementing a visitor class (EvalVisitor) extending ...
0
votes
0
answers
32
views
Why is the fullstop not recognised?
This grammar:
grammar TextBlock;
textBlock: sentence+ EOF;
entence: word+ FullStop;
word: LETTER+;
LETTER: [a-zA-Z];
FullStop: '.';
Results in:
1:14 token recognition error at: '.'
2:28 token ...
-1
votes
1
answer
102
views
Trouble Adding ANTLR to Classpath in Java: "package org.antlr.v4.runtime.tree does not exist"
I'm having difficulties adding ANTLR to my Java classpath and getting it to work. I've followed the usual steps, but I'm still encountering the error message:
package org.antlr.v4.runtime.tree does ...
-1
votes
1
answer
41
views
ANTLR4 'error: package org.antlr.v4.runtime does not exist' on MacOS
I'm trying to build a compiler using ANTLR4 for a uni project and for now I'm stuck. I tried running
javac TestPiinkk.java Piinkk*.java
and about 100 errors came up:
I've looked at some other ...
1
vote
1
answer
51
views
Is my antlr4 visitor code incorrect? It produces the wrong value but I can't figure out what I am doing wrong
My grammar for simple math expression is:
grammar Arithmetics;
expr : term (PLUS term | MINUS term)*;
term : factor (MULT factor | DIV factor)*;
factor : INT;
PLUS : '+';
MINUS : '-';
MULT : '*';
...
2
votes
1
answer
46
views
Can you conditionally change ANTLR lexer modes?
I'm working on a language where there is an outer grammar that defines objects and an inner grammar that defines code. The inner grammar is embedded in various places. The inner grammar starts with ...
0
votes
0
answers
88
views
Debug antlr in vscode with launch.json
I'm using vscode 1.84.0 and ANTLR4 grammar syntax support v2.4.2.
I also installed Debugger for Java v0.55.0 and I have Java-11 installed.
The tokens, lexer and listener files are created.
Now I want ...
2
votes
1
answer
45
views
ANTLR4 grammar handling reserved keywords that appear inside "free-text" fields
I'm attempting to write an ANTLR4 grammar for lookml. The schema for this language is relatively straight forward but it has 2 wrinkles -- 1 is that it supports a templating language that can be used ...
0
votes
1
answer
29
views
How to get the EOF token/node from the listener
Is there a way to get the EOF from the listener in Python ?
While looking at listener interface, I noticed EOF is not present, probably because it is not a rule.
In my grammar I use a standard EOF at ...
0
votes
1
answer
52
views
Antlr Lexer cant recognize Real Number
So I have been developing my own compiler from scratch. I have the assembler Completed and I had it working with Integer Numbers. I wanted to add support for Real Numbers that get assembled into ...
0
votes
0
answers
62
views
How do I test out my parser grammar in ANTLR4?
I wrote a parser grammar in ANTLR4 which looks like this:
parser grammar IFJ23;
tokens {
Identifier, Type,
LeftBracket, RightBracket,
LeftCurlyBracket, RightCurlyBracket,
Semicolon, ...
0
votes
0
answers
31
views
Why does having EOF in parser rules influence the lexer in ANTLR4?
Start with simple grammar:
grammar Simple;
file : lines ;
lines : (ID | INT | STRING)+ '\r'? '\n';
ID : [a-zA-Z_]*;
INT : [0-9]*;
STRING : '"' ~["\r\n]* '"';
COMMA : '...
1
vote
1
answer
64
views
Can I match an empty function argument with ANTLR?
I need to be able to recognize an empty argument to a function with ANTLR. For a given function, I would like to be able to support any argument being empty when parsing and the fact that a non-empty ...
0
votes
1
answer
20
views
how Altlr4 to choose alternative rules when there is ambiguity?
I'm drafting a grammar file for a pretty much 'unstructured' text output, something like:
grammar Output;
rules : (msgline|textline)* EOF;
msgline : MSG ' '* TEXT+ NL;
textline:(TEXT+ NL)|NL;
...
1
vote
0
answers
68
views
ANTLR4 C++ Generated lexer not accepting input stream
I am using Ubuntu.
I am including the parser and lexer ANTLR4 generates when I use the -Dlanguage=Cpp flag. I did not change the files at all and I have taken this code from the docs.
This is my code:
...
0
votes
1
answer
52
views
Can ANTLR grammar delegate some of its parsing to an opaque parser
Suppose we have a non-ANTLR parser that can parse certain expressions. The parser is represented by a C++ function that accepts a string and returns a parsed object. We can additionally assume that we ...
0
votes
1
answer
25
views
library version mismatch between direct dep and indirect dep
My project is using toml and config parser, the library is '1.0.0', in the mean time antlr4 is used to parse another piece of input data, but the project fails to run with following error:
ANTLR Tool ...
0
votes
0
answers
64
views
Reserved keyword rule in ANTLR
I'm new to Antlr4.
There is g4 grammar rules:
Function
: first
| second
| third
;
first
: FIRST'(' (STRING) (',' firstMode)? ')'
;
firstMode
: A
| B
;
A
: '"' F I R S T '"'
;
B
: '"'...
0
votes
1
answer
52
views
customized grammar similar to json
I'm trying to create a grammar that is similar to json but not exactly, the data is like this:
{foo=123,bar=abc}
basically, names and strings do not have double quotes and equal sign instead of comma ...
0
votes
0
answers
36
views
add_custom_target() can't create antlr4_runtime target because it already exists?
In my current project I have two sub-projects that use ANTLR4. My main CMakeLists.txt in root directory looks like this:
add_subdirectory(project1)
add_subdirectory(project2)
both project1 and ...
0
votes
1
answer
19
views
Is it possible to define an ANTLR4 grammar, nestable block where begin and end are the same token?
I would like to define a grammar where the start of each block is a tagname starting with the introducer character %. The difference between the start and end is that the start would have parameters ...
0
votes
1
answer
29
views
how to create an antlr4 identifier token that accepts any unicode word?
Antlr4 supports unicode.
I have tried creating a rule with unicode characters, and it works, something like:
IDENT:
[A-Za-zα-ω][A-Za-zα-ω0-9]* ;
but of course putting in all the letters from all ...
1
vote
1
answer
47
views
How ANTLR4 lexer consume more any tokens and stop at existing rules?
Is ANTLR4 lexer can consume more any tokens and stop at existing rules?
Expect consume more chars into one token.
Small rules
lexer grammar PhpLexer;
options {
superClass = PhpLexerBase;
...
0
votes
1
answer
47
views
Why is my antlr4 grammar not parsing this text correctly
I have the following grammar in antlr4 that I am using to parse betting lines.
grammar betting;
/*
* Parser Rules
*/
market
: zero
| array
| grid
;
zero
: (...
0
votes
0
answers
23
views
How do I add source code generated by a tool to my Netbeans Ant project?
I'm using ANTLR4 to generate a parser and lexer for a project with Netbeans and Ant. I was able to add a "-pre-compile" target override to my build.xml that executes the ANTLR4 tool to ...
0
votes
0
answers
36
views
How to associate distant tokens in ANTLER
Suppose I have the text "1,2,3:A,B,C". I would like to build an ANTLR4 grammar that produces a token that associates 1 with A, 2 with B and 3 with C for the above example. I know we can use ...
0
votes
0
answers
30
views
Antlr: failing predicate results in not further alternatives exploration
After the upgrade from Antlr 4.6.6 to 4.13.1, a specific unit test for a large grammar stopped being recognized. The grammar has a similar structure as:
Rule0 -> Rule1 | Rule2 | Rule3
Rule1 -> ...
1
vote
1
answer
73
views
ANTLR not generating ParserBase
I am new to ANTLR and was looking into the CPP14 grammar here. I tried using
antlr4 -Dlanguage=Python3 CPP14Lexer.g4
antlr4 -Dlanguage=Python3 CPP14Parser.g4
Then use the following driver code:
import ...
0
votes
0
answers
36
views
Antlr4 Grun command ignores parameters [duplicate]
At the Definitive Antlr 4 reference's Hello.g4 example I want to use grum as supposed. I have the classpath+path variables set:
ClassPath: C:\Users\jofwf\lib\antlr-4.13.1-complete.jar
Path: C:\Users\...
0
votes
3
answers
86
views
Visitor/Listener pattern confusion in -Dlanguage=TypeScript
I am investigating moving from antlr4ts to the main Typescript target. The documentation for the Typescript target says Visitors and Listeners are defined differently ...
class CustomVisitor extends ...
1
vote
1
answer
48
views
How to approach writing antlr4 lexer for ambiguous grammar?
Suppose I have a grammar like:
grammar ambiguity;
activity : Action Sep Argument;
Action : [0-9];
Argument: [0-9];
Sep: ':';
WS: [ \t\r\n]+ -> skip;
The simple test is, say, "1:2";
The ...
1
vote
0
answers
52
views
ANTLR left recursive rule precedence
when attempting to define ANTLR grammars containing left-recursive rules, the precedence of the alternative does sometimes behave unexpectedly.
For example, assuming a (minimal) grammar which should ...
0
votes
0
answers
31
views
My ANTLR4 listener produces correct dates but I am getting error output as well. Why?
Grammar is to parse the date string of MM/DD/YYYY format. Main function has three test strings, each one produces correct date but for the strings with 01 as DAY there is an warning or error output by ...