Tom Copeland's Recent Posts

RSS Feeds

« NullPointerException waiting to happen | Main | Popular RubyForge themes »

Jython/Pydev JavaCC grammar notes

I came across the Jython JavaCC grammar recently - actually, the grammar in the PyDev project, which I understand is a tweaked version of the Jython grammar.  At any rate, I ran JJDoc on it which produced some nice HTML output here

Note that if you've got a JJTree grammar (e.g., python.jjt) you first need to run JJtree on it to produce a JavaCC grammar (e.g., python.jj).  Then you can run JJDoc on that JavaCC grammar.   If you run JJDoc on a JJTree grammar you'll get parsing errors since JJDoc doesn't recognize JJTree directives.

The grammar itself is interesting since it does lots of stuff to properly process whitespace.  For example, it defines a COMMON_TOKEN_ACTION to add in a newline before an EOF token.  The tokenizer uses quite a few lexical states - eighteen in addition to DEFAULT, to be exact.

Keep an eye out for my upcoming JavaCC book for more of this sort of thing.  I'm working on examples of nested syntactic lookahead at the moment, great stuff!

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d83451d3c069e200e5505cd3ec8833

Listed below are links to weblogs that reference Jython/Pydev JavaCC grammar notes:

» Jython/Pydev JavaCC grammar notes from PsychicProgrammer.com
I came across the Jython JavaCC grammar recently - actually, the grammar in the PyDev project, which I understand is a tweaked version of the Jython grammar. At any rate, I ran JJDoc on it which produced some nice HTML...Link:... [Read More]

Comments

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been saved. Comments are moderated and will not appear until approved by the author. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

Comments are moderated, and will not appear until the author has approved them.