Questions tagged [antlr]

ANTLR, ANother Tool for Language Recognition, is a language tool that provides a framework for constructing recognizers, interpreters, compilers, and translators from grammatical descriptions containing actions in a variety of target languages.

What is ANTLR?

"ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files. It's widely used to build languages, tools, and frameworks. From a grammar, ANTLR generates a parser that can build and walk parse trees. From https://www.antlr.org/

Since ANTLR is not commercial software, it is not required and does not maintain backward compatibility with previous major versions and even between some minor versions.

Updated links

On January 24th 2013, the www.antlr.org address was changed from pointing at site for ANTLR version 3 (www.antlr3.org) to ANTLR version 4 (www.antlr4.org). So questions and answers that used www.antlr.org were correct for ANTLR 3.x before this date. The links should be updated to www.antlr3.org for ANTLR 3.x or www.antlr4.org for ATNLR 4.x.

ANTLR IDE

Useful ANTLR links

Examples and/or useful posts on SO

Related links

Code at Git

Related tags

Related projects

Installation

Antlr can most easily be installed through its NuGet package.

Install-Package Antlr

Books

4218 questions
1
vote
2 answers

ANTLR4 grammar not correctly matching escaped quotes in strings

I'm trying to create a grammar for a language that uses double quotes for strings and allows escaping of quotes with a backslash. I'm using ANTLR4 for parsing the input. I've defined the following rule for matching strings: STRING: '"' ( ESC_SEQ…
1
vote
1 answer

Match anything until end tag (generic text) in simple lexer/parser using ANTLR4

I want to make a simple parser for a simple scripting language, it has text blocks and script blocks, inside those scriptblocks, I want to be able to define a function, as well as execute generic statements of any kind. I don't really need to know…
Nicholas
  • 15
  • 4
1
vote
1 answer

ANTLR for Writing JAPE Grammar

I am using GATE to process texts written in natural language. I have to extract height, weight, bp etc from the text and store it in structured form. Now, these things(i.e height, weight etc) can be written in many forms which is unknown to me.…
Rishabh
  • 338
  • 1
  • 3
  • 17
1
vote
1 answer

ANTLR grammar discrepancy

grammar g; // %doc(file = "idocfile.yml") prog: (decl | expr)+ ; decl: VAR '=' '"' STR '"' |'%doc' '(' VAR '=' '"' STR '"' ')' |'%quiz' '(' VAR '=' '"' STR '"' ')' .*? '%quiz' ; expr:expr '*' expr |expr '+' expr |expr '-'…
1
vote
1 answer

If statement inside loop ID string name instead of value in Antlr4 based Interpreter

Good day can really appreciate if some one would help. I am working on interpreter based on Antlr4 now i am having challenge after implementation of Visitor class. The implementation is working perfectly i.e the if statement unless inside loop it…
1
vote
1 answer

Reading commands from STDIN and executing each as it is entered

I'd like to adapt the code below to use a ANTLRReaderStream so I don't have to create a new parser for each line. But it needs to process each line individually, which I don't have any idea how to do currently, and I don't see any way to ask the…
Brad Mace
  • 27,194
  • 17
  • 102
  • 148
1
vote
2 answers

Skipping sub-expressions in listener

Let's say I have logical expressions in this form ((a OR b) AND c) OR (d AND e = (f OR g)) I'm interested in getting a, b, c, d and ignore e, f, g (everything that has to do with assignments). My attempt was something like this infixOp : OR | AND…
jack malkovick
  • 503
  • 2
  • 14
1
vote
0 answers

How to add an item to an array within an Antlr Context in C#

I'm trying to generate LaTex for PGFPlots graphs using Antlr from a C# project. So far, I've created this grammar for the axis, which is essentially a set of kvps: grammar PgfPlots; axis : 'axis' '[' keyValPairs ']' ; keyValPairs :…
ScottishTapWater
  • 3,656
  • 4
  • 38
  • 81
1
vote
0 answers

Property name expected type of string but got undefined

My .babelrc.json file: { "presets": [ ["@babel/preset-env", { "targets": { "node": "current" } }], "@babel/preset-typescript" ], "plugins": [ ["@babel/plugin-proposal-decorators", {"legacy": true}], …
hehe123456
  • 31
  • 2
  • 5
1
vote
1 answer

ANTLR - Possible to process tokens with variable, specified lenght in a grammar?

Example String 023abc7defghij Header Characters 0, 1 = Size of following chunks Chunks First character = length of following string String Following characters = String with the specified length Example result So in the upper example this would…
Kai Mechel
  • 753
  • 8
  • 19
1
vote
0 answers

Antlr 4.6.1 not generating errorNodes for inputstream

I have a simple grammar like : grammar CellMath; equation : expr EOF; expr : '-'expr #UnaryNegation // unary minus | expr op=('*'|'/') expr #MultiplicativeOp // MultiplicativeOperation | expr op=('+'|'-')…
1
vote
1 answer

ANTLR Rules To Express All Symbols Except These

A newbie question. Say, I have a lexer rule simply listing all acceptable symbols : ACCEPTED_SYMBOLS: ('~' |'!' |'@' |'#' |'$' |'%' |'^' |'\-' |'\+' | '=' | '\\'|':' |'\"'|'\''|'<' |'>' |',' |'.' |'?' | '/' ) ; But sometimes I…
JavaMan
  • 4,954
  • 4
  • 41
  • 69
1
vote
1 answer

Parsing Java with Antlr, error: extraneous input 'import' expecting {...}

I am trying to use Antlr-maven-plugin @ 4.7.2 to parse some Java source code on my ubuntu22.04. I used the g4 files from Here and successfully generated the Parser and Lexer. The main function is as follows: public static void main(String[] args)…
lida ZHAO
  • 55
  • 1
  • 5
1
vote
3 answers

ANTLR Grammar to Preprocess Source Files While Preserving WhiteSpace Formatting

I am trying to preprocess my C++ source files by ANTLR. I would like to output an input file preserving all the whitespace formatting of the original source file while inserting some new source codes of my own at the appropriate locations. I know…
JavaMan
  • 4,954
  • 4
  • 41
  • 69
1
vote
1 answer

ANTLR: How to generate lexer and parser with python?

I had a look at the python run time module but I am unsure about creating the python parser and lexer files. I have written the .g files.
user944308
  • 27
  • 4