[sorry for the delay in the response]

Andrew G. Hammond wrote:
> I'm looking for a grammar to parse javascript.  Anybody know where I could
> get one?
> 
> The goal is to create a javascript compressor which maintains semantic
> equivilance while minimizing size of a javascript file (remove whitespace &
> comments without mangling strings, rename identifiers using variable length
> huffman codes).

There is a grammar for JavaScript, in Appendix A of the ECMA-262
standard.  You can get ECMA-262 at

        http://www.ecma.ch/ecma1/STAND/ECMA-262.HTM

Interestingly, they'll mail you a free copy of the standard, printed or
on CD, if you mail your request to [EMAIL PROTECTED]  I have mine.  :-)

Unfortunately, the grammar needs some work.  I have been preparing it
for use with Parse::Yapp, not Parse::RecDescent, so I haven't been
thinking very carefully about its use with RecDescent.  The one thing
that comes immediately to mind is the extensive use of left-recursion in
the grammar.

Note, if you use the grammar out of ECMA-262, that it is presented as a
single thing.  It is, in fact, four distinct grammars, with at least
five start symbols.  You probably only want to use the syntactic
grammar, which can be recognized by each rule having but one colon after
the nonterminal.  (See section 5.1)

Or you can wait for JavaScript::Parser, due from me Real Soon Now.

-- 
David "Cogent" Hand 
<http://davidhand.com/> <mailto:[EMAIL PROTECTED]> <icq:4321282> 

Reply via email to