Sometimes when you're working with a JavaCC/JJTree grammar it's helpful to see the abstract syntax tree of the grammar itself.
org.javacc.jjtree.JJTree has a method that's handy for this; just write up a little driver program like this:
Here's a simple grammar to show this in action:
Just run the driver program, set the environment variable
jjtree-dump, and get a nice AST printout:
You can see the parser productions and the tokenizer productions generally have
RE prefixes. The
FOO token has a very simple regular expression; a more complex one like
yields an AST like this:
Generating Parsers With JavaCC is coming along steadily, though - only three chapters to go. Writing this book has been a great experience, and I've gotten lots of suggestions and comments from folks. Good times indeed.