Integrating the generated BURM into your compiler
jburg.burg.JBurgMain
to generate the corresponding 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>
getOperator()
int getArity()
getNthChild(int index)
index
.
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 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.
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:
For example, suppose the BURM is trying to reduce a + 1
and it has the following rules:
int_value = PLUS(int_value, int_value): 1 { ... }
int_value = INTEGER_LITERAL(void): 1 { ... }
obj_value = IDENTIFIER(void) : 5 { ... }
The solution is to add a rule that allows the BURM to transform an object into an int:
int_value = obj_value: 5
{
// Call Integer.parseInt(obj.toString)), or something similar.
}
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:
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
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:
main()
method,
in grammars/jburg.g
.
Java files generated by ANTLR are:
JBurgGenerator.java contains the code that creates the actual BURM.