[antlr-interest] FOR_INIT tree parser implementation

dk0879 <diver7 at mail.ru> diver7 at mail.ru
Tue Jan 28 09:10:46 PST 2003


  Help me please, in my trouble. I implement interpreter
  of JavaScript and I don't understand how to
  write FOR_INIT production of "for" statement correctly.

  I simplify java.tree.g for my tasks, but it doesn't work:

--- java.tree.g ---

stat:   typeDefinition
    |   variableDef
    ...
    |   #("for"
            #(FOR_INIT   (variableDef | elist)? ) // <- QUESTION?!
            #(FOR_CONDITION (expression)? )  
            #(FOR_ITERATOR  (elist)? )
            stat
    ...
---

    #(FOR_INIT (variableDef | elist)? )

    "FOR_INIT" rule works fine to process code like this:

    for (var i = 0; i < 10; ++i)
    {  
      invoke_something();
    }  

    but doesn't work with code below:

    for (var i = 0, j = 10; i < 10; ++i, --j)
    {  
      invoke_something(j);
    }  

    Described "FOR_INIT" rule doesn't handle
    second (and next) variable declarations (and
    initializations)

    How correctly write this rule?

    stupid example of needed semantic are:
    #(FOR_INIT ((variableDef)* | (elist)? | EMPTY_STATEMENT) )


    Thank you.


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list