Antlr - Generated class

Card Puncher Data Processing

About

From the grammar

  1. The lexer rules will create the lexer class
  2. The parser rules will create the parser class

The classes generated will contain a method for each rule in the grammar.

See example

Example

from the getting started with the below Hello grammar

grammar Hello; 
r  : 'hello' ID ; 
ID : [a-z]+ ; 
WS : [ \t\r\n]+ -> skip ; 
antlr4 Hello.g4

Next to the grammar file, you got:

  • the lexer HelloLexer.java - to create the tokens
  • the parser HelloParser.java - to build the tree
  • the listener HelloListener.java - to traverse the tree
ls -A1
Hello.g4
Hello.interp
Hello.tokens
HelloBaseListener.java
HelloLexer.interp
HelloLexer.java
HelloLexer.tokens
HelloListener.java
HelloParser.java





Discover More
Card Puncher Data Processing
Antlr - (Lexical) Rule

in Antlr. Antlr has two types of rule: Name Case Type Description Example from the getting started uppercase letter lexer rule (known as Token name, they defines the token that the lexer...
Card Puncher Data Processing
Antlr - Actions

Actions are code blocks in the grammar written in the target language. Grammar actions add code to the generated class. You can use actions in a number of places within a grammar, but the syntax...
Card Puncher Data Processing
Antlr - Lexer

in Antlr The lexer is a generated class from the grammar.
Card Puncher Data Processing
Antlr - Parser

in Antlr. The parser is a generated class that is build from the grammar (specifically from the parser rule of the grammar). The job of the parser is to create a parse tree from: a parser start rule...
Card Puncher Data Processing
Antlr - Token

org/antlr/v4/runtime/Token A token can be defined via: a or the A token is primarily defined via a lexer rule (Lexical rule) Example: the lexical rule LOWERCASE that capture a string...



Share this page:
Follow us:
Task Runner