Menu

JBurg2 Syntax

Tom Harwood

JBurg Reference

Invocation

java -jar jburg.jar [options] specificationFile

Command-line options

Commonly used options

  • -g : generate debugging code
  • -outputdir : emit the BURM in the specified directory
  • -inputdir : read the specification from the specified directory
  • -outputfile : emit the BURM into the specified file

All command-line options

Building with Apache Ant

JBurg integrates well into ant builds via a jburg macrodef.

JBurg Specification Elements

Directives

Full guide

Language

Language Java;

package

package jburg.tutorial.first;

extends

extends BaseBURM; // Optional

implements

implements FrontEndTokenTypes;  // Deprecated.

header

// Optional, no default.
header {
    import java.util.*;
}

INodeType

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

JBurg.NodeType

JBurg.NodeType INT = burmTest.LiteralIntNode;

INodeAdapter

INodeAdapter jburg.burg.inode.Antlr3JavaAdapter;

OpcodeType

OpcodeType ASTNodeID;

JBurg.NonterminalType

JBurg.NonterminalType burmTest.NonterminalTypes;

DefaultErrorHandler

DefaultErrorHandler {
    // p refers to the annotation object at
    // the root of the unreducible subtree.
    new UnknownTreeHandler().analyze(p);
}

See the debugging section for details.

JBurg.VolatileCostFunctions

JBurg.VolatileCostFunctions volatileCost1, volatileCost2;

JBurg.Constant

JBurg.Constant ERROR_TRAP = 268435456;

Ad-Hoc code

{
    // Target and implementation specific code
}

JBurg.include Directive

More information

JBurg.include "../arithmetic/IntegerArithmetic.jbg"

Macro Substitution

JBurg.include "IntegerArithmetic.jbg" SUBSTITUTE_ADD="ADD" SUBSTITUTE_INT="INT(void)" { "#int#"="intValue()" }

Rules

Pattern Rules

More information

Pattern Match: Subtree with Children

nonterminal = NODE_TYPE(subtreeNonterminal subtreeName, subtreeNonterminalPrime subtreeNamePrime): cost

Pattern Match: Subtree with no Children (Leaf)

nonterminal = NODE_TYPE(void): cost

Pattern Match: Subtree with Variadic Children

    nonterminal = NODE_TYPE(subtreeNonterminal subtreeName*): cost
    {reduction action}

or

    nonterminal = NODE_TYPE(subtreeNonterminal subtreeName+): cost
    {reduction action}

or

    nonterminal = NODE_TYPE(subtreeNonterminal subtreeName subtreeVariadicNonterminal subtreeName*): cost
    {reduction action}

Transformation Rules

More information

Simple Transformation Rule

nonterminalPrime = originalNonterminal;

General Transformation Rule

nonterminalPrime = originalNonterminal: cost
{reduction action};

Reduction Actions

More information

Inline Reduction Action

nonterminalName = NODE_TYPE(subtreeType subtree): cost
{
    return actionForNodeType(#nonterminalName, subtree);
}

Reduction Action Specified via JBurg.Reduction

intExpression = ADD(intExpression lhs, intExpression rhs): cost
JBurg.Reduction reducer.emitIntegerAdd(lhs, rhs);

Reduction Action with a Prologue

objExpression = FUNCTION(functionHeader header, functionBody body): cost
Prologue reducer.setUpFunctionExpression(p)
JBurg.Reduction reducer.emitFunctionExpression(__p, header, body);

Cost Expressions

More information

Cost as an Integer Literal

nonterminal = NODE_TYPE(void): 4 { reduction action; }

Cost as a reference to a JBurg.Constant or a field

nonterminal = NODE_TYPE(void): ManifestConstant { reduction action; }

Cost Computed via Function Call

nonterminal = NODE_TYPE(void): computedCost(getNode()) { reduction action; }

Related

Wiki: CommandLineOptions
Wiki: CostExpressionsGuide
Wiki: Debugging
Wiki: DirectivesGuide
Wiki: JBurgIncludeGuide
Wiki: PatternRuleGuide
Wiki: ReductionActionsGuide
Wiki: TransformationRuleGuide
Wiki: antbuild

MongoDB Logo MongoDB