Skip to main content
Jump to: navigation, search


Note: The information provided on this site is not confirmed to be correct. These are just my assumptions based on experimenting with LPG. If you find something being incorrect or missing please correct/add it.

LPG Options

  • action=(string,string,string)
  • action-block=(string,string,string)
This option defines an additional action block that may then be used in the templates to generate code in the given file.
%options action-block=("*.java", "/.", "./")
%options action-block=("", "/:", ":/")}
  • ast_directory[=string]
The package where ast classes will be generated if "automatic_ast=toplevel" is set.
  • ast_type[=string]
The name of the ast class that gets subclassed by all other ast classes.
  • attributes (default: false)
  • automatic_ast[=<none|nested|toplevel>] (default: none)
The generated ast type. "nested" generates nested ast classes in the parser file. "toplevel" generates toplevel classes for each ast node.
  • backtrack (default: false)
Used by the parser template. Sets if the generated parser should be a backtracking parser.
  • byte (default: true)
  • conflicts (default: true)
  • dat-directory=string
  • dat-file=string
  • dcl-file=string
  • debug (default: false)
prints debug messages
  • def-file=string
  • edit (default: false)
If set to true the parser will not be generated. This allows one to only edit the template file without actually generating the parser.
  • error-maps (default: false)
? Used by the parser templates
  • escape=character (default: ' ')
  • extends-parsetable=string
The superclass of the generated ParseTable
  • export-terminals=string
  • factory=string
This is actually a prefix that gets used instead of "new " when an ast node is created in the parser. Allows one to implement factory methods for creating nodes.
  • file-prefix=string
The prefix for all generated files.
  • filter=string
  • first (default: false)
Prints a map for the non terminals. Useful for debugging.
  • follow (default: false)
Prints a Follow Map. Useful for debugging.
  • glr (default: false)
? generates an GLR parser ?
sets the following options:
  • lalr_level = 1;
  • single_productions = false;
  • backtrack = true;
  • goto-default (default: false)
? from the LPG generator source code:
	// COMPUTE_DEFAULT_GOTO constructs the vector DEFAULT_GOTO, which is indexed by
	// the non-terminals in the grammar. Its task is to assign to each element
	// of the array the Action which is most frequently defined on the symbol in
	// question, and remove all such actions from the state automaton.
  • headers=(string,string,string)
  • ignore-block=string
  • imp-file=string
  • import-terminals=string
  • include-directory=string
  • lalr[=integer] (default: 1)
Sets the number of lookahead tokens for the parser.
  • legacy (default: false)
  • list (default: false)
  • margin=integer (default: 0)
Sets how much the code will be indented. A margin of 0 means that the generated code gets indented by four spaces. The higher the value the less the code will be indented.
  • max_cases=integer (default: 1024)
Sets the maximum number of cases allowed in the switch statement inside the ruleAction method of the parser. When this number is exceeded the ruleAction method gets split up into more methods. If set to 1 the "$SplitActions" macro in the parser template will get generated for each rule. This may be useful for overriding the actions in a subclass of the parser but of course it is much slower.
  • names=<optimized|maximum|minimum> (default: optimized)
  • nt-check (default: false)
? Used by the backtracking parser template.
  • or-marker=character (default: '|')
  • out_directory[=string]
  • package=string
The package of the parser.
  • parent_saved (default: false)
Creates ast nodes that know about their parent node.
  • parsetable-interfaces=string
The interfaces the generated ParseTable will implement.
example: %options ParseTable="lpg.runtime.ParseTable, SomeInterface"
  • prefix=string
The prefix for the parser token names.
  • priority (default: true)
? If set, the priority arrows ("::=?" and "->?") will get used when generating code.
  • programming_language[=<xml|c|cpp|java|plx|plxasm|ml>] (default: xml)
? The generated programming language. Not sure if all the languages are actually supported.
  • prs-file=string
The file name for the ParseTable
  • quiet (default: false)
? no console output
  • read-reduce (default: true)
? from the LPG generator source code:
    // If the READ/REDUCE option is on, we precalculate the kernel
    // of the final states which simply consists of the last item
    // in  the corresponding rule.  Rules with the ACCEPT
    // non-terminal as their left-hand side are not considered so
    // as to let the Accpet action remain as a Reduce action
    // instead of a Goto/Reduce action.
  • remap-terminals (default: true)
  • scopes (default: false)
? Used by the parser templates. Not sure what exactly this is used for. It changes the SCOPE_SIZE and SCOPE_UBOUND fields in the ParseTable. If scopes is not set these fields will return 0/-1. getScopeSize() is used by the DiagnoseParser.
  • serialize (default: false)
? Generates the binary file
  • shift-default (default: false)
  • single-productions (default: false)
? Used by the KeywordTemplate
  • slr (default: false)
? creats an slr parser
  • soft-keywords (default: false)
? sets the following options:
  • lalr_level = 1;
  • single_productions = false;
  • backtrack = true;
  • states (default: false)
Outputs the shift states. Useful for debugging
  • suffix=string
The suffix for the parser token names.
  • sym-file=string
The file name for the ParserSymbols
  • tab-file=string
  • table (default: false)
Generates a ParseTable that implements lpg.runtime.ParseTable by default.
  • template=string
The template used to generate the parser.
example: %options
  • trace[=<conflicts|full>] (default: conflicts)
  • trailers=(string,string,string)
  • variables[=<none|both|terminals|nt|nonterminals>] (default: none)
  • verbose (default: false)
Verbose output.
sets the following options:
  • first = true;
  • follow = true;
  • list = true;
  • states = true;
  • xref = true;
  • warnings = true;
  • visitor[=<none|default|preorder> (default: none)
The type of visitor for the ast classes.
  • visitor-type[=string]
The name of the visitor class.
  • warnings (default: true)
Prints warnings.
  • xref (default: false)
Prints a Cross-reference table.

LPG Help Resources

Back to the top