Smacc: a Compiler-Compiler
Debugging and Testing
I believe what you want is to start debugging a parser with some script and then stepping through it.
The SmaCC debugger is activated only when the SmaCC code is in the execution context. So, if you do not have it yet you can “Step to debugger”.
For example:
- Try debugging:
JavaParser parse: 'public class A {}'
- Then from the window menu, choose “Step to debugger” / “SmaCC”
Understand Smacc Errors
shift/reduce conflicts
Reduce/reduce conficts
Unit testing
Often you would like to test productions that are not top productions. In this case, you should add start symbol that specify that we can access different productions. For example if you add the following to an hypothetical grammar:
SmaCC will generate the following class methods on the parseur: startingStateForfile
, startingStateForexpression
, startingStateForstatement
and startingStateFordeclaration
.
If you do not want to duplicate the logic in your tests you can extend the parser itself as follows. It is a design decision that is up to you.
This is useful when you incrementally build your grammar and want to test it at different points.
Parsing indentation dependent languages
Tips and Tricks
ANTRL conversion tips and tricks