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

Re: (no subject)

Expand Messages
  • Michael Chiasson
    Thanks very much for the advice Monty. I wanted to avoid using (lbl:...)? so as not to worry about #lbl being null but maybe it would be anyway. mjc ... From:
    Message 1 of 1 , May 28 10:00 AM
    • 0 Attachment
      Thanks very much for the advice Monty. I wanted to avoid using (lbl:...)? so
      as not to worry about #lbl being null but maybe it would be anyway.


      -----Original Message-----
      From: mzukowski@... [mailto:mzukowski@...]
      Sent: Friday, May 28, 1999 11:28 AM
      To: antlr-interest@onelist.com
      Cc: parrt@...
      Subject: Re: [antlr-interest] (no subject)

      From: mzukowski@...

      Yeah, that's sort of a java thing. Your TreeParser superclass defines
      ASTNULL as:
      public static ASTNULLType ASTNULL = new ASTNULLType();

      ASTNULL is a singleton, it doesn't do anything except participate in
      comparisons and denote an empty tree. IMHO Ter should make the above:
      public static AST ASTNULL = new ASTNULLTYPE();

      Then at least you could override by setting ASTNULL = new MyTokenType() and
      not get the class cast errors.

      Alternately you could write your rule as

      #( DUMMY_TOKEN (ot1:tree1)? (ot2:tree2)? (ot3:tree3)? )

      It is also typical to define trees to have no optional parts, and instead
      when building the trees to put in "empty" values. So a C for loop:

      #( "for" init:expr test:expr incr:expr )
      EpsilonExpression // represents "empty" expression
      | binaryExpr
      | ...

      This eliminates the lookahead tests, for the price of a slightly bigger


      > -----Original Message-----
      > From: Michael Chiasson [SMTP:mjc@...]
      > Sent: Friday, May 28, 1999 7:57 AM
      > To: antlr-interest@onelist.com
      > Subject: [antlr-interest] (no subject)
      > From: "Michael Chiasson" <mjc@...>
      > In my treeparser, I have a grammar description for a tree where the last 3
      > children are optional.
      > Eg:
      > myTree:
      > #( DUMMY_TOKEN ot1:optionalTree1 ot2:optionalTree2 ot3:optionalTree3
      > )
      > ;
      > optionalTree1 :
      > ( tree1 )?
      > ;
      > ...
      > In the generated parser, after the first of these children is not found,
      > _t
      > is assigned ASTNULL. Then when the generated code tries to assign my label
      > for the next optional child, I get a java.lang.ClassCastException. The
      > reason is because an object of type ASTNULL is being assigned to my own
      > AST
      > type which is extended from CommonAST.
      > Is this a Java thing ? Should I be able to assign an ASTNULL type which
      > implements AST to a class which is extended from CommonAST ? Or is this a
      > bug ? I suppose I could rewrite my tree grammar if I have to.
      > Any thoughts ?
      > mjc
      > ------------------------------------------------------------------------
      > ONElist: the best source for group communications.
      > http://www.onelist.com
      > Join a new list today!

      ONElist members are using Shared Files in great ways!
      Are you? If not, see our homepage for details.
    Your message has been successfully submitted and would be delivered to recipients shortly.