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

Re: Bug with return values?

Expand Messages
  • Jerry Patterson
    Markus, ... From: Markus Pilzecker For grammar rules like ... epos returns [int[] p] ... ; ... antlr [version 2.7.0] generates something like ...
    Message 1 of 1 , Mar 1, 2000
    • 0 Attachment

      ---last time you said
      From: Markus Pilzecker <mp@...>

      For grammar rules like

      returns [int[] p]
      : p=pos

      antlr [version 2.7.0] generates something like

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

      try { // for error handling
      catch (RecognitionException ex) {
      return p;

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

      CFA_to_location.java:259: Variable p may not have been initialized.
      return p;

      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



      [Snip Ad]

      I have found that I have to initialize the variables by hand (unless
      there is a way to automate this in antlr that I am unaware of).

      So for your example (as you have suggested) put the assignment in the
      front. I don't really think it is much of a hack, I mean you would be
      communicating that somehow pos() had failed to the caller. Anyway,
      unless I've messed up the syntax, you should be able to do the following:

      returns [int[] p]
      { p = null; }

      I wouldn't necessarily consider this an antlr *bug* as much as it is an
      annoyance. It would be nice if antlr *did* have an option to generate
      initialization (it may and I don't know it though) to avoid this problem.

      --- <pre>
      Jeremiah S Patterson | It is not likely that one would die for a
      jerpat@... --+-- righteous man; for a good man someone might
      jerpat@... | dare to die. Yet while we were still sinners,
      jerpatter@... | Christ died for us.
      jerpat@... | Romans 5:7-8 </pre>
    Your message has been successfully submitted and would be delivered to recipients shortly.