Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added some explanation of how the StringTemplates are used.

...

  • You'll either get the feeling "Wow, that was easy!" and move on (that happened to me) or "Eeek, what a pain!" and let someone else to the work.

Target Source Files

Your ANTLR code generation target will consist of several files in the target language. A number of run-time support files that you'll create directly, and a number of files that ANTLR will generate (in the target language) as the result of the user's grammar being processed by ANTLR. These files are generated from StringTemplates like ZYX.stg above.

ANTLR looks for the presence of certain template files and templates. Some are required, some are optional.

XYZ.stg

The principle template file. The templates in this file are used to generate the Lexer, Parser and Tree Parser generated by the user's grammar.

Template Name

Purpose

Notes

outputFile

Generates the target-language implementation of the recognizer.

Required

headerFile

Generates the target-language header file for the recognizer.

Optional

outputFile StringTemplate

Formal parameters:

Parameter Name

Description

LEXER

Boolean indicating that a Lexer is being generated.

PARSER

Boolean indicating that a Parser or Combined Lexer/Parser is being generated.

TREE_PARSER

Boolean indicating that a Tree Parser is being generated.

actionScope

 

actions

A java.util.Map of the grammar's actions.

docComment

 

recognizer

The StringTemplate named "lexer", "parser", or "treeParser", depending on the type of recognizer being generated.

name

 

tokens

 

tokenNames

 

rules

 

cyclicDFAs

A org.antlr.analysis.DFA instance.

bitsets

 

buildTemplate

Boolean

buildAST

Boolean

rewriteMode

Boolean

profile

Boolean

backtracking

Boolean

synpreds

A java.util.Set of synpreds in the grammar (if any).

memoize

Boolean

numRules

 

fileName

 

ANTLRVersion

String containing the version of the ANTLR tool generating this recognizer.

generatedTimestamp

String containing the current time.

trace

Boolean

scopes

 

superClass

 

literals

 

AST.stg

ASTParser.stg

ST.stg