Menu

DirectivesGuide

Tom Harwood

JBurg Directives

Specification-Level Directives

These directives apply to the entire specification, and should only be specified once unless noted.

Language

Semi-optional (defaults to Java with a warning). Specifies the target language. Targets supported or under development:


  • Java : fully supported.
  • Cpp : The C++ target supports all JBurg rule types; the pattern matchers are not efficient and debugging support is TBD.
  • Javascript : experimental.

package

Optional, no default. Specifies the package for Java target.

package jburg.tutorial.first;

extends

Optional, no default. Specifies a base class for the generated BURM.

extends BaseBURM;

implements

Deprecated. Optional, no default. Specifies an interface which the generated BURM implements.

Optional, no default. Specifies import statements and other material copied verbatim into the generated BURM's class header section.

INodeType

Required. Specifies the type of AST node.

INodeType CommonTree;  // Use ANTLR AST nodes as the i-node type

INodeAdapter

Optional, but de facto required. Specifies the i-node adapter type.

INodeAdapter jburg.burg.inode.Antlr3JavaAdapter;

Builtin adapters:


  • ANTLR2 Java
  • ANTLR3 Java
  • ANTLR2 C++

Building a custom INodeAdapter

JBurg.NodeType

Optional, may be specified more than once. Specifies the type of AST node that backs a particular opcode. This AST type must be a subclass of the overall INodeType.

JBurg.NodeType INT = burmTest.LiteralIntNode;

OpcodeType

Optional, defaults to int or platform-specific analog. Specifies the name of an enumeration that encodes the type field of the i-nodes.

OpcodeType ASTNodeID;

JBurg.NonterminalType

Optional, no default. Specifies the name of an enumeration that encodes the nonterminal names used in the specification.

JBurg.NonterminalType burmTest.NonterminalTypes;

If this directive is not specified, then JBurg will generate int constants for each nonterminal it encounters, e.g., statement becomes __statement_NT. Specifying the nonterminal types as an enumeration is beneficial for documentation and also catches typos in the specification.

DefaultErrorHandler

Optional. Specifies error handling code that is compiled into the BURM and is invoked if the BURM cannot find a valid sequence of reductions to cover the input tree. See the debugging section for details.

JBurg.VolatileCostFunctions

Optional, no default. Specifies the names of cost functions that need to be re-evaluated, not cached. This directive should be used with great restraint, since it can create very slow pattern matchers.

JBurg.VolatileCostFunctions volitileCost1, volitileCost2;

Other Directives

JBurg.Constant

Optional, recommended. Specifies a named integer constant; these manifest constants are typically used instead of int literals as cost specifications. Using JBurg.Constant entries instead of references to host language manifest constants may allow JBurg to do more cost analysis at compiler-compile time and result in much faster pattern matchers.

JBurg.Constant ERROR_TRAP = 268435456;

Related

Wiki: Debugging
Wiki: FirstCodeGenerator
Wiki: INodeAdapter
Wiki: JBurg Reference
Wiki: JBurg2 Syntax