JBurg generated code can fail in two ways that are particular to it:
The first problem, failing to find a valid sequence of reductions to cover the tree, is often caused by one of these problems:
statment instead of statement will cause a pattern match to fail.Specify -g on the command line to build debugging code into your BURM.
[Java target specific] When the BURM cannot find a valid cover for a tree, it throws an IllegalStateException. Your driver can catch this exception and dump an annotated AST for analysis in JBurg's debugger, and/or otherwise fix up the error:
private static Object generateCode(CommonTree tree)
throws Exception
{
SecondTreeParser burm = new SecondTreeParser();
try
{
burm.burm(tree);
return burm.getResult();
}
catch ( IllegalStateException ex )
{
burm.dump(tree, new PrintWriter("/tmp/failedBurm.xml"));
throw ex;
}
}
JBurg's debugger is part of the source distribution; build it via ant ErrorAnalyzer.jar and invoke it... TBD
Use the DefaultErrorHandler directive to add code that gets control when the BURM cannot generate a valid cover of the input AST:
/
* Error recovery routine: deduce what we can from the problem
* tree, then abort this BURM with an exception that the caller
* can catch and ignore.
/
DefaultErrorHandler
{
new UnknownTreeHandler(reducer.getProblems()).analyze(p);
BURMAbortException.abort();
}
The UnknownTreeHandler is an Apache Falcon subsystem that explores the annotated AST and attempts to diagnose the problem. Because failure to match a subtree causes the parent tree to also fail to match, the UnknownTreeHandler recursively explores the tree and attempts to identify the most deeply nested subtree that failed to match.
Wiki: CommandLineOptions
Wiki: DirectivesGuide
Wiki: JBurg Reference
Wiki: JBurg2 Reference
Wiki: JBurg2 Syntax