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

a simple question ...

Expand Messages
  • hkhidhir
    Hi All, I just started to look at antlr, and I am writing my first grammer, I am having the following problem, I guess it is trivial, but it will be very nice
    Message 1 of 7 , Jan 5, 1999
    • 0 Attachment
      Hi All,
      I just started to look at antlr, and I am writing my first grammer, I am
      having the following problem, I guess it is trivial, but it will be very
      nice if someone can explain to me why it is happening:

      I have the following rule:

      identifierList:
      IDENTIFIER ( COMMA IDENTIFIER ) *
      ;

      and when I try to generate the parser, antlr will give me the following
      message:
      -----------------------------------------------------------------------------
      H:\win\antlr\antlr-2.5.0\khalid>java antlr.Tool trc.g
      ANTLR Parser Generator Version 2.5.0 1989-1998 MageLang Institute
      warning: line 111: nondeterminism upon
      k==1:COMMA
      k==2:IDENTIFIER

      k==3:REC_SEP,THREE_STAR,"dump","file",FILENAME,NEWLINE,"session","id",CO
      LON,SESSION_NUM1,SESSION_NUM2,"parsing","in","cursor",CURSOR_NUM,"select","all",
      "distinct","from","fetch",COMMA,"exec","parse","stat",INT,EQUAL,IDENTIFIER,"end"
      ,"of","stmt",WS,LPAREN,RPAREN,STAR,SEMI,DOT,SLASH,MINUS,PLUS,IDENT,LETTER,UNDERS
      CORE,DIGIT

      k==4:REC_SEP,THREE_STAR,"dump","file",FILENAME,NEWLINE,"session","id",CO
      LON,SESSION_NUM1,SESSION_NUM2,"parsing","in","cursor",CURSOR_NUM,"select","all",
      "distinct","from","fetch",COMMA,"exec","parse","stat",INT,EQUAL,IDENTIFIER,"end"
      ,"of","stmt",WS,LPAREN,RPAREN,STAR,SEMI,DOT,SLASH,MINUS,PLUS,IDENT,LETTER,UNDERS
      CORE,DIGIT
      between alt 1 and exit branch of block

      -----------------------------------------------------------------------------------
      I would really appriciate any help.
      Thanks to all
      Khalid
    • Terence Parr
      ... This can only be figured out with the rest of the code, but I ll tell you where to look. In this case, ANTLR cannot decide whether to match , ID in the
      Message 2 of 7 , Jan 5, 1999
      • 0 Attachment
        hkhidhir hath spoken:
        >From: hkhidhir <hkhidhir@...>
        >
        >Hi All,
        >I just started to look at antlr, and I am writing my first grammer, I am
        >having the following problem, I guess it is trivial, but it will be very
        >nice if someone can explain to me why it is happening:
        >
        >I have the following rule:
        >
        >identifierList:
        > IDENTIFIER ( COMMA IDENTIFIER ) *
        > ;
        >
        >and when I try to generate the parser, antlr will give me the following
        >message:
        >-----------------------------------------------------------------------------
        >H:\win\antlr\antlr-2.5.0\khalid>java antlr.Tool trc.g
        >ANTLR Parser Generator Version 2.5.0 1989-1998 MageLang Institute
        >warning: line 111: nondeterminism upon
        > k==1:COMMA
        > k==2:IDENTIFIER
        >

        This can only be figured out with the rest of the code, but I'll tell you
        where to look. In this case, ANTLR cannot decide whether to match ',' ID
        in the loop or by exiting identifierList and matching what can follow the
        reference to identifierList.

        Note that if the so-called FOLLOW set is contributing the COMMA IDENTIFIER,
        you may find that COMMA IDENTIFIER can never really follow as a sequence,
        but COMMA can occur first and IDENTIFIER can occur second. This is a
        result of ANTLR using linear approx LL(k) rather than full LL(k) as does
        old PCCTS, which is slightly less powerful than full LL(k). The benefit is
        that you can use really high lookahead without worrying that ANTLR will not
        terminate due to exponential cost of computing lookahead. The answer is to
        shuffle your grammar slightly.

        Hope this helps,
        Terence of San Francisco
      • Octav Chiriac
        May be this will help: identifierList: IDENTIFIER ( (COMMA IDENTIFIER)= COMMA IDENTIFIER ) * ; I m not sure about this because it is not enough information,
        Message 3 of 7 , Jan 6, 1999
        • 0 Attachment
          May be this will help:
          identifierList:
          IDENTIFIER ( (COMMA IDENTIFIER)=> COMMA IDENTIFIER ) *
          ;

          I'm not sure about this because it is not enough information,
          but you could try.

          Best Regards,
          Octav

          Terence Parr wrote:
          >From: "Terence Parr" <parrt@...>
          >
          >hkhidhir hath spoken:
          >>From: hkhidhir <hkhidhir@...>
          >>
          >>Hi All,
          >>I just started to look at antlr, and I am writing my first grammer, I am
          >>having the following problem, I guess it is trivial, but it will be very
          >>nice if someone can explain to me why it is happening:
          >>
          >>I have the following rule:
          >>
          >>identifierList:
          >> IDENTIFIER ( COMMA IDENTIFIER ) *
          >> ;
          >>
          >>and when I try to generate the parser, antlr will give me the following
          >>message:
          >>-----------------------------------------------------------------------------
          >>H:\win\antlr\antlr-2.5.0\khalid>java antlr.Tool trc.g
          >>ANTLR Parser Generator Version 2.5.0 1989-1998 MageLang Institute
          >>warning: line 111: nondeterminism upon
          >> k==1:COMMA
          >> k==2:IDENTIFIER
          >>
          >
          >This can only be figured out with the rest of the code, but I'll tell you
          >where to look. In this case, ANTLR cannot decide whether to match ',' ID
          >in the loop or by exiting identifierList and matching what can follow the
          >reference to identifierList.
          >
          >Note that if the so-called FOLLOW set is contributing the COMMA IDENTIFIER,
          >you may find that COMMA IDENTIFIER can never really follow as a sequence,
          >but COMMA can occur first and IDENTIFIER can occur second. This is a
          >result of ANTLR using linear approx LL(k) rather than full LL(k) as does
          >old PCCTS, which is slightly less powerful than full LL(k). The benefit is
          >that you can use really high lookahead without worrying that ANTLR will not
          >terminate due to exponential cost of computing lookahead. The answer is to
          >shuffle your grammar slightly.
          >
          >Hope this helps,
          >Terence of San Francisco
          >
          >------------------------------------------------------------------------
          >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.
          >

          --
          Octav Chiriac Phone: (373) 2 21 20 96
          NetInfo S.R.L. Fax: (373) 2 21 36 59
          Chisinau (373) 2 24 00 83
          Moldova, Republic of mailto:com@...
        • Terence Parr
          ... Still not enough...try digging around finding what can follow identifierList. Ter
          Message 4 of 7 , Jan 6, 1999
          • 0 Attachment
            Octav Chiriac hath spoken:
            >From: Octav Chiriac <com@...>
            >
            >May be this will help:
            >identifierList:
            > IDENTIFIER ( (COMMA IDENTIFIER)=> COMMA IDENTIFIER ) *
            > ;
            >
            >I'm not sure about this because it is not enough information,
            >but you could try.

            Still not enough...try digging around finding what can follow identifierList.

            Ter
          • hkhidhir
            Thanks for the help, I appriciate it. I am rewriting the grammer just to find out where I am making a mistake. It will help even in the identifier problem, if
            Message 5 of 7 , Jan 6, 1999
            • 0 Attachment
              Thanks for the help, I appriciate it. I am rewriting the grammer just to
              find out where I am making a mistake.
              It will help even in the identifier problem, if you can give me a hint on
              how to parse the following:

              in the input I have:

              integers: 23435 2222444 etc
              floats: 2.90 4444.5656 etc
              session_ids: 234.2345.5676.23445.12343 etc

              Thanks in advance.
              Khalid


              On Wed, 6 Jan 1999, Terence Parr wrote:

              > From: "Terence Parr" <parrt@...>
              >
              > Octav Chiriac hath spoken:
              > >From: Octav Chiriac <com@...>
              > >
              > >May be this will help:
              > >identifierList:
              > > IDENTIFIER ( (COMMA IDENTIFIER)=> COMMA IDENTIFIER ) *
              > > ;
              > >
              > >I'm not sure about this because it is not enough information,
              > >but you could try.
              >
              > Still not enough...try digging around finding what can follow identifierList.
              >
              > 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.
              >
            • Terence Parr
              ... Have you seen http://www.antlr.org in the fieldguide? Something there to help you get started. This grammar is easy though: input : (def)+ ; def : ID
              Message 6 of 7 , Jan 6, 1999
              • 0 Attachment
                hkhidhir hath spoken:
                >From: hkhidhir <hkhidhir@...>
                >
                >Thanks for the help, I appriciate it. I am rewriting the grammer just to
                >find out where I am making a mistake.
                >It will help even in the identifier problem, if you can give me a hint on
                >how to parse the following:
                >
                >in the input I have:
                >
                >integers: 23435 2222444 etc
                >floats: 2.90 4444.5656 etc
                >session_ids: 234.2345.5676.23445.12343 etc

                Have you seen http://www.antlr.org in the fieldguide? Something there to
                help you get started. This grammar is easy though:

                input : (def)+ ;

                def : ID COLON (FLOAT)+ ;

                Best regards,
                Terence
              • hkhidhir
                OK, Thanks, I actally made a mistake in specifying the input, what I ment id that the numbers will appear in the input not the words integers floats ... so
                Message 7 of 7 , Jan 6, 1999
                • 0 Attachment
                  OK, Thanks, I actally made a mistake in specifying the input, what I ment
                  id that the numbers will appear in the input not the words "integers"
                  "floats" ...
                  so my input will be:

                  1234 23.5645 34.565.565.7678.3454.343 343 3.333 4.55 23.34 2 1 34 0

                  Thanks again
                  Khalid


                  On Wed, 6 Jan 1999, Terence Parr wrote:

                  > From: "Terence Parr" <parrt@...>
                  >
                  > hkhidhir hath spoken:
                  > >From: hkhidhir <hkhidhir@...>
                  > >
                  > >Thanks for the help, I appriciate it. I am rewriting the grammer just to
                  > >find out where I am making a mistake.
                  > >It will help even in the identifier problem, if you can give me a hint on
                  > >how to parse the following:
                  > >
                  > >in the input I have:
                  > >
                  > >integers: 23435 2222444 etc
                  > >floats: 2.90 4444.5656 etc
                  > >session_ids: 234.2345.5676.23445.12343 etc
                  >
                  > Have you seen http://www.antlr.org in the fieldguide? Something there to
                  > help you get started. This grammar is easy though:
                  >
                  > input : (def)+ ;
                  >
                  > def : ID COLON (FLOAT)+ ;
                  >
                  > Best regards,
                  > Terence
                  >
                  > ------------------------------------------------------------------------
                  > 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.