[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Collaborative JavaScript PROJECT proposal [was: javascript grammar]

"Uwe Hoffmann" <uwe@iamaze.com> wrote:
> I'm converting the fesi ecmascript grammar from javacc to sablecc (I just
> like sablecc better).
> http://home.worldcom.ch:80/~jmlugrin/fesi/

Hmm...  I did look at your grammar.  Fixing it should be quite easy.  You only
have to solve some common case conflicts.  But, before you do so, you might
want to reconsider the grammar all together.  Let me explain.

I did a little investigation, and found the "ECMA Script" specification:


The grammar you are working with DOES NOT implement the specification!

There is a good reason for this: FESI's grammar did not conform to the
specification in the first place!  Probably it was too much work to make
javacc parse the real thing;-) [LALR can delay decisions, unlike LL.  This
often has advantages.  Some people will tell you that "infinite lookahead" can
take care of many cases: agreed, but then your parse time is potentially
exponential in the size of the input file, while LALR parsers are linear in
the size of the AST. This can make quite a difference on long and complex

What's missing in your grammar?  An example:

An "expression" should allow for ["relational_expression" "in"
"shift_expression"].  But, your grammar does not allow this.

Concrete example: 

The specification allows a programmer to write the following statement:

for( ; foo in bar; )

Your grammar (regardless of conflicts) does not allow this statement (nor does

Furthermore, the "specification" contains a grammar (in Appendix A) which is
already "unrolled" to handle "expression/expression_no_in".

In summary:  I strongly suggest restarting your project using the official
grammar (from the specification).  There's no need to build another incomplete

We could make this a collaborative effort if other mailing list users want to
contribute.  This could be fun!  I will post a project proposal.  We can see
if there are people interested.

Etienne M. Gagnon, M.Sc.                     e-mail: egagnon@j-meg.com
Author of SableCC:                 http://www.sable.mcgill.ca/sablecc/