Dashboard > ANTLR 3 > ... > ANTLR v3 documentation > Grammar options
  ANTLR 3 Log In | Sign Up   View a printable version of the current page.  
  Grammar options
Added by Dieter Frej, last edited by Kunle Odutola on May 18, 2008  (view change)
Labels: 
(None)

Taken from /org/antlr/tool/Grammar.java all allowed options are

option description
language
the default is language=Java; over time new code generation target will be completed and can then be set here
tokenVocab
where ANTLR should get predefined tokens and token types. Tree grammars need it to get the token types from the parser that creates its trees
output
valid values are output=AST; and output=template;
ASTLabelType
set the type of all tree labels and tree-valued expressions. Without this option, trees are of type Object.
TokenLabelType
set the type of all token-valued expressions. Without this option, tokens are of type Token (or IToken in C#)
superClass
set the superclass of the generated recognizer
filter
In the lexer, this allows you to try a list of lexer rules in order. The first one that matches, wins. This is the token that nextToken() returns. If nothing matches, the lexer consumes a single character and tries the list of rules again.
rewrite
Use this option when your translator output looks very much like the input. Your actions can modify the TokenRewriteStream to insert, delete, or replace ranges of tokens with another object. Used in conjunction with output=template, you can very easily build translators that tweak input files.
k
limit the lookahead depth for the recognizer uses most k symbols. this prevents the decision from using acyclic LL* DFA.
backtrack
taken from http://www.antlr.org:8080/pipermail/antlr-interest/2006-July/016818.html : The new feature (a big one) is the backtrack=true option for grammar, rule, block that let's you type in any old crap and ANTLR will backtrack if it can't figure out what you meant. No errors are reported by antlr during analysis. It implicitly adds a syn pred in front of every production, using them only if static grammar LL* analysis fails. Syn pred code is not generated if the pred is not used in a decision. This is essentially a rapid prototyping mode. It is what I have used on the java.g. Oh, it doesn't memoize partial parses (i.e., rule parsing results) during backtracking automatically now. You must also say memoize=true. Can make a HUGE difference to turn on.
memoize
When backtracking, remember whether or not rule references succeed so that the same input position cannot be parsed more than once by the same rule. This effectively guarantees linear parsing when backtracking at the cost of more memory.

The options names show up at least on SeaMonkey (and probably other Gecko-based browsers) only up with their first two letters. Not that helpful. Is this a fault of the engine or of the dashboard?

Another problem: Isn't the default token class not Token, but CommonToken? 

Default type of labels in generated code is Token, though it creates CommonToken objects.

The equivalent of the the Token interface in the Java runtime (that Ter is referring to above) is the IToken interface in the C# runtime.

Site powered by a free Open Source Project / Non-profit License (more) of Confluence - the Enterprise wiki.
Learn more or evaluate Confluence for your organisation.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.1 Build:#806 May 06, 2007) - Bug/feature request - Contact Administrators