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

optional rule confusion

Expand Messages
  • Igor Fedorenko
    I must be missing something really simple, but I cannot get antlr generate reasonable parser for javadoc-like java method names (like
    Message 1 of 6 , Mar 3, 2004
    • 0 Attachment
      I must be missing something really simple, but I cannot get antlr
      generate reasonable parser for javadoc-like java method names (like
      com.something.MyClass#method).

      Here is what my parser rule looks like

      protected javaname: ID (DOT ID)* (POUND ID)?

      And here is what antlr generates for the last part

      switch ( LA(1)) {
      case POUND:
      {
      match(POUND);
      m = LT(1);
      match(ID);
      break;
      }
      case EOF:
      {
      break;
      }
      default:
      {
      throw new NoViableAltException(LT(1), getFilename());
      }
      }


      Why would antlr generate NoViableAltException for something which is
      optional?


      Regards,
      Igor Fedorenko
    • Lubos Vnuk
      I think you can get some information from a similar thread titled: Problem with x: (A)(B)? ; Regards, Lubos. ... is
      Message 2 of 6 , Mar 3, 2004
      • 0 Attachment
        I think you can get some information from a similar thread
        titled: "Problem with x: (A)(B)? ; "

        Regards,
        Lubos.

        --- In antlr-interest@yahoogroups.com, Igor Fedorenko
        <ifedorenko@r...> wrote:
        > I must be missing something really simple, but I cannot get antlr
        > generate reasonable parser for javadoc-like java method names (like
        > com.something.MyClass#method).
        >
        > Here is what my parser rule looks like
        >
        > protected javaname: ID (DOT ID)* (POUND ID)?
        >
        > And here is what antlr generates for the last part
        >
        > switch ( LA(1)) {
        > case POUND:
        > {
        > match(POUND);
        > m = LT(1);
        > match(ID);
        > break;
        > }
        > case EOF:
        > {
        > break;
        > }
        > default:
        > {
        > throw new NoViableAltException(LT(1), getFilename());
        > }
        > }
        >
        >
        > Why would antlr generate NoViableAltException for something which
        is
        > optional?
        >
        >
        > Regards,
        > Igor Fedorenko
      • Igor Fedorenko
        Thank you for the hint, Lubos, Adding dummy rule does the trick. Note however, that my rule is protected so there is no way it can be called as a top level
        Message 3 of 6 , Mar 3, 2004
        • 0 Attachment
          Thank you for the hint, Lubos, Adding dummy rule does the trick. Note
          however, that my rule is protected so there is no way it can be called
          as a top level rule.

          Lubos Vnuk wrote:

          > I think you can get some information from a similar thread
          > titled: "Problem with x: (A)(B)? ; "
          >
          > Regards,
          > Lubos.
          >
          > --- In antlr-interest@yahoogroups.com, Igor Fedorenko
          > <ifedorenko@r...> wrote:
          >
          >>I must be missing something really simple, but I cannot get antlr
          >>generate reasonable parser for javadoc-like java method names (like
          >>com.something.MyClass#method).
          >>
          >>Here is what my parser rule looks like
          >>
          >> protected javaname: ID (DOT ID)* (POUND ID)?
          >>
          >>And here is what antlr generates for the last part
          >>
          >> switch ( LA(1)) {
          >> case POUND:
          >> {
          >> match(POUND);
          >> m = LT(1);
          >> match(ID);
          >> break;
          >> }
          >> case EOF:
          >> {
          >> break;
          >> }
          >> default:
          >> {
          >> throw new NoViableAltException(LT(1), getFilename());
          >> }
          >> }
          >>
          >>
          >>Why would antlr generate NoViableAltException for something which
          >
          > is
          >
          >>optional?
          >>
          >>
          >>Regards,
          >>Igor Fedorenko
          >
          >
          >
          >
          >
          > Yahoo! Groups Links
          >
          >
          >
          >
          >
          >
        • Lubos Vnuk
          I always thought the keyword protected was meant for lexers only. ... Note ... called ... (like
          Message 4 of 6 , Mar 3, 2004
          • 0 Attachment
            I always thought the keyword protected was meant for lexers only.

            --- In antlr-interest@yahoogroups.com, Igor Fedorenko
            <ifedorenko@r...> wrote:
            > Thank you for the hint, Lubos, Adding dummy rule does the trick.
            Note
            > however, that my rule is protected so there is no way it can be
            called
            > as a top level rule.
            >
            > Lubos Vnuk wrote:
            >
            > > I think you can get some information from a similar thread
            > > titled: "Problem with x: (A)(B)? ; "
            > >
            > > Regards,
            > > Lubos.
            > >
            > > --- In antlr-interest@yahoogroups.com, Igor Fedorenko
            > > <ifedorenko@r...> wrote:
            > >
            > >>I must be missing something really simple, but I cannot get antlr
            > >>generate reasonable parser for javadoc-like java method names
            (like
            > >>com.something.MyClass#method).
            > >>
            > >>Here is what my parser rule looks like
            > >>
            > >> protected javaname: ID (DOT ID)* (POUND ID)?
            > >>
            > >>And here is what antlr generates for the last part
            > >>
            > >> switch ( LA(1)) {
            > >> case POUND:
            > >> {
            > >> match(POUND);
            > >> m = LT(1);
            > >> match(ID);
            > >> break;
            > >> }
            > >> case EOF:
            > >> {
            > >> break;
            > >> }
            > >> default:
            > >> {
            > >> throw new NoViableAltException(LT(1), getFilename());
            > >> }
            > >> }
            > >>
            > >>
            > >>Why would antlr generate NoViableAltException for something which
            > >
            > > is
            > >
            > >>optional?
            > >>
            > >>
            > >>Regards,
            > >>Igor Fedorenko
            > >
            > >
            > >
            > >
            > >
            > > Yahoo! Groups Links
            > >
            > >
            > >
            > >
            > >
            > >
          • Igor Fedorenko
            Is that true? Did not know that, but it works in parsers just fine. :-) And thank you again for helping me with that.
            Message 5 of 6 , Mar 3, 2004
            • 0 Attachment
              Is that true? Did not know that, but it works in parsers just fine. :-)
              And thank you again for helping me with that.

              Lubos Vnuk wrote:

              > I always thought the keyword protected was meant for lexers only.
              >
            • mzukowski@yci.com
              Yeah, it s only real purpose is for lexers. In parsers it might just pass through and make that method protected, I m not sure. In any event it doesn t alter
              Message 6 of 6 , Mar 3, 2004
              • 0 Attachment
                Yeah, it's only real purpose is for lexers. In parsers it might just pass
                through and make that method protected, I'm not sure. In any event it
                doesn't alter antlr's behavior.

                Monty

                -----Original Message-----
                From: Lubos Vnuk [mailto:lubos.vnuk@...]
                Sent: Wednesday, March 03, 2004 7:08 AM
                To: antlr-interest@yahoogroups.com
                Subject: [antlr-interest] Re: optional rule confusion

                I always thought the keyword protected was meant for lexers only.

                --- In antlr-interest@yahoogroups.com, Igor Fedorenko
                <ifedorenko@r...> wrote:
                > Thank you for the hint, Lubos, Adding dummy rule does the trick.
                Note
                > however, that my rule is protected so there is no way it can be
                called
                > as a top level rule.
                >
                > Lubos Vnuk wrote:
                >
                > > I think you can get some information from a similar thread
                > > titled: "Problem with x: (A)(B)? ; "
                > >
                > > Regards,
                > > Lubos.
                > >
                > > --- In antlr-interest@yahoogroups.com, Igor Fedorenko
                > > <ifedorenko@r...> wrote:
                > >
                > >>I must be missing something really simple, but I cannot get antlr
                > >>generate reasonable parser for javadoc-like java method names
                (like
                > >>com.something.MyClass#method).
                > >>
                > >>Here is what my parser rule looks like
                > >>
                > >> protected javaname: ID (DOT ID)* (POUND ID)?
                > >>
                > >>And here is what antlr generates for the last part
                > >>
                > >> switch ( LA(1)) {
                > >> case POUND:
                > >> {
                > >> match(POUND);
                > >> m = LT(1);
                > >> match(ID);
                > >> break;
                > >> }
                > >> case EOF:
                > >> {
                > >> break;
                > >> }
                > >> default:
                > >> {
                > >> throw new NoViableAltException(LT(1), getFilename());
                > >> }
                > >> }
                > >>
                > >>
                > >>Why would antlr generate NoViableAltException for something which
                > >
                > > is
                > >
                > >>optional?
                > >>
                > >>
                > >>Regards,
                > >>Igor Fedorenko
                > >
                > >
                > >
                > >
                > >
                > > Yahoo! Groups Links
                > >
                > >
                > >
                > >
                > >
                > >




                Yahoo! Groups Links
              Your message has been successfully submitted and would be delivered to recipients shortly.