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

rule return values, arrays and pre-increment operator

Expand Messages
  • Gary Schaps
    Should I be able to do this ... foo [ returns int[] V ] // init action {V = new int[15]; int i=0;} // rule ... ; bar [ returns int b] // init action b=0; //
    Message 1 of 3 , Dec 18, 1998
    • 0 Attachment
      Should I be able to do this ...

      foo [ returns int[] V ]
      // init action
      {V = new int[15]; int i=0;}

      // rule
      : V[i]=bar (COMMA V[++i]=bar)*
      ;

      bar [ returns int b]
      // init action
      b=0;
      // rule
      : "x1" { b=1; }
      | "x2" { b=2; }
      | ....
      ;

      ... assuming of course that I'm prepared to deal with
      ArrayIndexOutOfBounds exceptions? In practice I
      find that it evokes a syntax error from antlr.Tool, and
      I have to rewrite foo as ...

      foo [ returns int[] V ]
      // init action
      {V = new int[15]; int i=0; int b0=0, b1=0;}

      // rule
      : b0=bar {V[i]=b0;} (COMMA b1=bar {v[++i] = b1;})*
      ;

      I would like to use the first form of "foo" for performance and
      maintainability reasons.

      Thanks.

      -gls
    • Terence Parr
      ... That syntax seems weird. Shouldn t it be: foo returns int[] ... ? Ter
      Message 2 of 3 , Dec 21, 1998
      • 0 Attachment
        Gary Schaps hath spoken:
        >From: Gary Schaps <gary_schaps@...>
        >
        >Should I be able to do this ...
        >
        >foo [ returns int[] V ]
        > // init action
        > {V = new int[15]; int i=0;}

        That syntax seems weird. Shouldn't it be:

        foo returns int[] ...

        ?
        Ter
      • Gary Schaps
        Actually, it should be ... ... ... my mistake. In any event, it s a small point. I ll have to revisit it another time. BTW, Dr. Dobbs Journal is going to
        Message 3 of 3 , Jan 4, 1999
        • 0 Attachment
          Actually, it should be ...

          >
          >foo returns [ int[] V ]
          >

          ... my mistake. In any event, it's a small point. I'll have to revisit it
          another time.

          BTW, Dr. Dobbs Journal is going to publish an article in the March
          issue's "Programmer's ToolChest" section which I think you'll enjoy.
          I'm told it goes on sale February 1st.

          -gls

          Terence Parr wrote:

          > From: "Terence Parr" <parrt@...>
          >
          > Gary Schaps hath spoken:
          > >From: Gary Schaps <gary_schaps@...>
          > >
          > >Should I be able to do this ...
          > >
          > >foo [ returns int[] V ]
          > > // init action
          > > {V = new int[15]; int i=0;}
          >
          > That syntax seems weird. Shouldn't it be:
          >
          > foo returns int[] ...
          >
          > ?
          > Ter
          >
          > ------------------------------------------------------------------------
          > To unsubscribe from this mailing list, or to change your subscription
          > to digest, go to the ONElist web site, at http://www.onelist.com and
          > select the User Center link from the menu bar on the left.
        Your message has been successfully submitted and would be delivered to recipients shortly.