Tom Copeland's Recent Posts

RSS Feeds

« RubyForge Subversion and CVS totals | Main | Who's using RubyGems 0.9.0? »

Java Expression Language JavaCC parser notes

The Glassfish project uses a JavaCC-generated parser to parse the JSP expression language.  I grabbed the parser from the Glassfish CVS repo and here's a JJDoc'd version of it.

This grammar is interested because all the productions return an Object of some sort.  The start symbol, ExpressionString, returns a String, an Expression, or an ExpressionString, and each of the lower level productions parses out its tokens and gloms them into a returned object.   I think I'm used to seeing JJTree grammars where most of the real work is done in with a visitor outside the grammar file, so this pure JavaCC grammar looks a little different.  Also, I'm not sure exactly how this parser is used - is the start symbol always called or are there places where other productions act as the start symbol? 

The lexical specification is pretty straightforward; it uses two lexical states (including DEFAULT) and pretty much skips everything outside expressions (e.g., outside ${ ... }).  I like the one token definition - BADLY_ESCAPED_STRING_LITERAL - hehe, you can tell they've had to deal with some iffy code.

Finally, work continues on my forthcoming JavaCC book... steady progress and it's very cool stuff.

TrackBack

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

Listed below are links to weblogs that reference Java Expression Language JavaCC parser notes:

» Java Expression Language JavaCC parser notes from PsychicProgrammer.com
The Glassfish project uses a JavaCC-generated parser to parse the JSP expression language. I grabbed the parser from the Glassfish CVS repo and here's a JJDoc'd version of it. This grammar is interested because all the productions return an Object...Li... [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.