JBurg Users' Guide

Installing JBurg

Generating a BURM with JBurg

Integrating the generated BURM into your compiler

Debugging the BURM

Unable to find a rule to process x(22){-1}

Notes on modifying JBurg

Rebuilding JBurg



Installing JBurg

The compiled distribution of jburg is in the distribution's bin/jburg.jar file. The jarfile is only necessary to generate the BURM.

Generating a BURM with JBurg

First create a
JBurg specification, then invoke jburg.burg.JBurgMain to generate the corresponding BURM.

Required parameters

Optional parameters

Example ANT task that generates a BURM

	<target name="reducer">
		<java classname="jburg.burg.JBurgMain" failonerror="yes" fork="yes" dir="reducer">
			<arg value="MyLanguage.jbg"/>
			<arg value="MyLanguageTreeParser.java"/>
			<!-- <arg value="-g"/> -->
			<classpath>
				<pathelement path="${jburg.jar}"/>
				<pathelement path="${ANTLR.jar}"/>
			</classpath>
		</java>
	</target>

Integrating the generated BURM into your compiler

Required data structures

JBurg's generated BURMs work on a n-ary tree generated by other passes of the compiler. The object class that represents a tree node (the "INode class") must provide the following methods:

Setting properties in the generated BURM

Use the BURMProperty JBurg specification directive to include a property in your generated BURM. For example, to include a BCEL ClassGen object as the property classGen:

BURMProperty org.apache.bcel.generic.ClassGen classGen;

JBurg will include a field of the specified type and get/set methods.


Debugging your generated BURM

Debugging a BURM is not too different from debugging any other Java code. The theory page will help you understand the structure and control flow of the BURM.

Usual BURM failure modes

Unable to find a rule to process x(22){-1}

The BURM throws this exception if it cannot find any rule to match a particular node. The elements of the diagnostic line are:

The most common causes of this exception are:

BURM debug option output

Your BURM will support emitting XML-formatted debugging information if you generate it with the JBurg -g command-line switch.

Debugging output can be written by including a default error handler, for example:

/* * Error recovery routine: deduce what we can from the problem * tree, then abort this BURM with an exception that the caller * can catch and report. */ DefaultErrorHandler { dump(p, "/tmp/failedBurm.xml"); throw new IllegalStateException("see debugging output in /tmp/failedBurm.xml"); }

Build ErrorAnalyzer.jar from the ant build target:
ant ErrorAnalyzer.jar and then run the error analyzer against the debugging output:
java -jar lib/ErrorAnalyzer.jar /tmp/failedBurm.xml

Debug Information
The error analyzer presents the annotated tree that caused the failure.

Notes on modifying JBurg

Rebuilding JBurg

JBurg's build is ant-based. The default ant target compiles the Java files and builds jburg.jar.

The files that make up JBurg are: