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

Bug with return values?

Expand Messages
  • Markus Pilzecker
    For grammar rules like ... epos returns [int[] p] ... ; ... antlr [version 2.7.0] generates something like ... public final int[] epos() throws
    Message 1 of 1 , Mar 1, 2000
    • 0 Attachment
      For grammar rules like

      -------------8<----------------------
      epos
      returns [int[] p]
      : p=pos
      ;
      -------------8<----------------------

      antlr [version 2.7.0] generates something like

      -------------8<----------------------
      public final int[] epos() throws RecognitionException, TokenStreamException {
      int[] p;


      try { // for error handling
      p=pos();
      }
      catch (RecognitionException ex) {
      reportError(ex);
      consume();
      consumeUntil(_tokenSet_4);
      }
      return p;
      }
      -------------8<----------------------

      , which again is complained by ``javac'' [version 1.2.2]

      -------------8<----------------------
      CFA_to_location.java:259: Variable p may not have been initialized.
      return p;
      ^
      -------------8<----------------------
      .

      As far as I can judge, ``int[] p;'' should be replaced by
      ``int[] p = null;'', which, for the purist, also is a hack -- well, at least a
      deterministic one.

      Now, I ask:
      - did I miss anything
      - is this all a bug of antlr 2.7.0
      - is javac 1.2.2 extraordinarily fussy
      - does anybody have a workaround
      ?


      Bye,

      Markus
    Your message has been successfully submitted and would be delivered to recipients shortly.