[antlr-interest] JavaScript grammar

Chris Lambrou chris at lambrou.net
Fri Mar 28 13:13:32 PDT 2008


Hi all,

I couldn't get the ECMAScript by Greg Clemenson on the Grammar List page to
work. It's supposed to run in v3.0 without any issues, but I ran into a
whole host of problems. Since I'm fairly new to ANTLR, I thought I'd work my
way through Terence's book and have a stab at writing a JavaScript grammar
from scratch as a learning exercise. Well, I've reached a point where the
script may be useful to others, so I've attached it - it compiles cleanly,
without any warnings. I could also do with some advice, though.*
*

   1. Unlike other whitespace characters, line separators (represented by
   my LT token type) are important in JavaScript, as you're allowed to use them
   to terminate statements instead of the usual terminating semicolon
   character. As a result, I cannot 'hide' line separators like other
   whitespace characters, and my grammar is peppered with LT!* sequences. Is
   there a way to place the LT tokens on the hidden channel, and then
   optionally reveal them only in the few rules that require it?
   2. The grammar doesn't include any ^ or ! modifiers to impose any kind
   of useful structure to the generated AST. I can see how I ought to do this
   in the simple cases (e.g. 'return'^ expression), but I'm not sure how
   far I ought to go with this before relying on a subsequent tree grammar to
   finish the job.

I haven't performed much in the way of formal testing, except that it seems
to work with everything I've thrown at it using the ANTLRWorks debugger. I
guess I ought to look into writing some gunit tests...

Regards,

Chris
**
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080328/99d7c400/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ECMAScript.g
Type: application/octet-stream
Size: 34931 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20080328/99d7c400/attachment-0001.obj 


More information about the antlr-interest mailing list