Loading ...
Sorry, an error occurred while loading the content.

Re: [antlr-interest] Re: [2.7.1a2] java.tree.g omission

Expand Messages
  • Alexander Lenski
    Use semantic predicates or try this: newExpression ... ( newArrayDeclarator (arrayInitializer)? ... ( objBlock { unit.addAnonymousClass(); } ... ) ) )
    Message 1 of 4 , Jan 1, 2001
    • 0 Attachment
      Use semantic predicates or try this:
      newExpression
      : #( "new" type
      ( newArrayDeclarator (arrayInitializer)?
      | elist
      ( objBlock
      { unit.addAnonymousClass(); }
      | // This is elist without objBlock
      )
      )
      )
      ;
      // Alexander Lenski

      ----- Original Message -----
      From: <chris@...>
      To: <antlr-interest@egroups.com>
      Sent: Sunday, December 31, 2000 7:14 PM
      Subject: [antlr-interest] Re: [2.7.1a2] java.tree.g omission


      > This is great! I am in the process of writing a Tree Walker that
      > needs to know when it encounters a new Anonymous type being born.
      > Unfortunately a can't seem to figure out how to tell the difference
      > between a plain elist and an elist with an objBlock. I tried
      >
      > newExpression
      > : #( "new" type
      > ( newArrayDeclarator (arrayInitializer)?
      > | elist (objBlock) { unit.addAnonymousClass(); }
      > | elist
      > )
      > )
      > ;
      >
      > But ANTLR says that's ambiguous. I figure there's probably a way in
      > the code block to tell whether there is actually an objBlock, but I
      > don't know ANTLR well enough (yet). Can anyone fill in the missing
      > pieces for me?
      >
      > newExpression
      > : #( "new" type
      > ( newArrayDeclarator (arrayInitializer)?
      > | elist (objBlock)?
      > {
      > if(?????) {
      > unit.addAnonymousClass();
      > }
      > }
      > )
      > )
      > ;
      >
      > I'm expecting something like that, but I have know idea what to
      > replace the ?????'s with. Thanks.
      > (*Chris*)
      >
      > --- In antlr-interest@egroups.com, james@e... wrote:
      > > The example Java tree walker seems to have an omission. The rule:
      > >
      > > --------------------------------------------------------------------
      > ----
      > > newExpression
      > > : #( "new" type
      > > ( newArrayDeclarator (arrayInitializer)?
      > > | elist
      > > )
      > > )
      > >
      > > ;
      > > --------------------------------------------------------------------
      > ----
      > >
      > > should be:
      > >
      > > --------------------------------------------------------------------
      > ----
      > > newExpression
      > > : #( "new" type
      > > ( newArrayDeclarator (arrayInitializer)?
      > > | elist (objBlock)?
      > > )
      > > )
      > >
      > > ;
      > > --------------------------------------------------------------------
      > ----
      > >
      > > in order to support anonymous classes.
      > > --
      > > Jerry James
      >
      >
      >
      >
      >
      >
    • Chris Pratt
      That worked perfectly. Thanks. So the idea is to bind the action to the item in the tree that you really care about, makes perfect sense. (*Chris*) ... From:
      Message 2 of 4 , Jan 1, 2001
      • 0 Attachment
        That worked perfectly. Thanks. So the idea is to bind the action to the
        item in the tree that you really care about, makes perfect sense.
        (*Chris*)

        ----- Original Message -----
        From: "Alexander Lenski" <alenski@...>
        To: <antlr-interest@egroups.com>
        Sent: Monday, January 01, 2001 12:33 PM
        Subject: Re: [antlr-interest] Re: [2.7.1a2] java.tree.g omission


        > Use semantic predicates or try this:
        > newExpression
        > : #( "new" type
        > ( newArrayDeclarator (arrayInitializer)?
        > | elist
        > ( objBlock
        > { unit.addAnonymousClass(); }
        > | // This is elist without objBlock
        > )
        > )
        > )
        > ;
        > // Alexander Lenski
        >
        > ----- Original Message -----
        > From: <chris@...>
        > To: <antlr-interest@egroups.com>
        > Sent: Sunday, December 31, 2000 7:14 PM
        > Subject: [antlr-interest] Re: [2.7.1a2] java.tree.g omission
        >
        >
        > > This is great! I am in the process of writing a Tree Walker that
        > > needs to know when it encounters a new Anonymous type being born.
        > > Unfortunately a can't seem to figure out how to tell the difference
        > > between a plain elist and an elist with an objBlock. I tried
        > >
        > > newExpression
        > > : #( "new" type
        > > ( newArrayDeclarator (arrayInitializer)?
        > > | elist (objBlock) { unit.addAnonymousClass(); }
        > > | elist
        > > )
        > > )
        > > ;
        > >
        > > But ANTLR says that's ambiguous. I figure there's probably a way in
        > > the code block to tell whether there is actually an objBlock, but I
        > > don't know ANTLR well enough (yet). Can anyone fill in the missing
        > > pieces for me?
        > >
        > > newExpression
        > > : #( "new" type
        > > ( newArrayDeclarator (arrayInitializer)?
        > > | elist (objBlock)?
        > > {
        > > if(?????) {
        > > unit.addAnonymousClass();
        > > }
        > > }
        > > )
        > > )
        > > ;
        > >
        > > I'm expecting something like that, but I have know idea what to
        > > replace the ?????'s with. Thanks.
        > > (*Chris*)
        > >
        > > --- In antlr-interest@egroups.com, james@e... wrote:
        > > > The example Java tree walker seems to have an omission. The rule:
        > > >
        > > > --------------------------------------------------------------------
        > > ----
        > > > newExpression
        > > > : #( "new" type
        > > > ( newArrayDeclarator (arrayInitializer)?
        > > > | elist
        > > > )
        > > > )
        > > >
        > > > ;
        > > > --------------------------------------------------------------------
        > > ----
        > > >
        > > > should be:
        > > >
        > > > --------------------------------------------------------------------
        > > ----
        > > > newExpression
        > > > : #( "new" type
        > > > ( newArrayDeclarator (arrayInitializer)?
        > > > | elist (objBlock)?
        > > > )
        > > > )
        > > >
        > > > ;
        > > > --------------------------------------------------------------------
        > > ----
        > > >
        > > > in order to support anonymous classes.
        > > > --
        > > > Jerry James
        > >
        > >
        > >
        > >
        > >
        > >
        >
        >
        >
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.