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

RE: [antlr-interest] stuck expr

Expand Messages
  • mzukowski@yci.com
    Perhaps you are never sending EOF. Is the input a file or from the command line? Try it from a file. Monty ... From: jagad [mailto:jagad@enciety.com] Sent:
    Message 1 of 11 , Oct 1, 2003
      Perhaps you are never sending EOF. Is the input a file or from the command
      line? Try it from a file.

      Monty

      -----Original Message-----
      From: jagad [mailto:jagad@...]
      Sent: Wednesday, October 01, 2003 6:32 AM
      To: ANTLR Milis
      Subject: [antlr-interest] stuck expr

      Hi All,

      I have simple parser like this one;

      //***** Parser *****
      class MyParser extends Parser;

      goal : exprList SEMI EOF;

      exprList : expr (COMMA expr);

      expr : simpleExpr (relOp simpleExpr)*;

      simpleExpr : (PLUS | MINUS)? term (addOp term)*;

      term : factor (mulOp factor)*;

      factor : NUM_INT
      | NUM_REAL
      | (LPAREN expr RPAREN)
      ;

      mulOp : STAR | SLASH | DIV | AND | SHL| SHR;
      addOp : PLUS | MINUS | OR | XOR;
      relOp : GREATHAN
      | LESSTHAN | GREATHANEQU | LESSTHANEQU |EQU|NOTEQU;

      //********************

      The I gerenate into C++ code, the problem is the parser allways stuck on
      expr and never reach the goal. I have try to set options{ k=xx} with no
      effect.

      For input:

      (1+2);

      the output is:

      NUM_INT <----- factor: NUM_INT
      term <----- term: factor
      PLUS <----- addOp: PLUS
      NUM_INT <----- factor: NUM_INT
      term <----- term: factor
      simpleExpr <----- simpleExpr: term (addOp term)*;
      expr <----- expr: simpleExpr
      ( expr ) <----- factor: (LPAREN expr RPAREN)
      term <----- term: factor
      simpleExpr <----- simpleExpr: term
      expr <----- expr: simpleExpr

      Why my parser never reach goal? please, let me know.

      Thanks in Advance and Best Regards

      jagad






      Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    • jagad
      Hi All, I have simple parser like this one; //***** Parser ***** class MyParser extends Parser; goal : exprList SEMI EOF; exprList : expr (COMMA expr);
      Message 2 of 11 , Oct 1, 2003
        Hi All,

        I have simple parser like this one;

        //***** Parser *****
        class MyParser extends Parser;

        goal : exprList SEMI EOF;

        exprList : expr (COMMA expr);

        expr : simpleExpr (relOp simpleExpr)*;

        simpleExpr : (PLUS | MINUS)? term (addOp term)*;

        term : factor (mulOp factor)*;

        factor : NUM_INT
        | NUM_REAL
        | (LPAREN expr RPAREN)
        ;

        mulOp : STAR | SLASH | DIV | AND | SHL| SHR;
        addOp : PLUS | MINUS | OR | XOR;
        relOp : GREATHAN
        | LESSTHAN | GREATHANEQU | LESSTHANEQU |EQU|NOTEQU;

        //********************

        The I gerenate into C++ code, the problem is the parser allways stuck on
        expr and never reach the goal. I have try to set options{ k=xx} with no
        effect.

        For input:

        (1+2);

        the output is:

        NUM_INT <----- factor: NUM_INT
        term <----- term: factor
        PLUS <----- addOp: PLUS
        NUM_INT <----- factor: NUM_INT
        term <----- term: factor
        simpleExpr <----- simpleExpr: term (addOp term)*;
        expr <----- expr: simpleExpr
        ( expr ) <----- factor: (LPAREN expr RPAREN)
        term <----- term: factor
        simpleExpr <----- simpleExpr: term
        expr <----- expr: simpleExpr

        Why my parser never reach goal? please, let me know.

        Thanks in Advance and Best Regards

        jagad
      • mzukowski@yci.com
        Run antlr.Tool with -traceParser and then run your parser again and see what it is doing. Take a look at the generated source code, it s pretty easy to read
        Message 3 of 11 , Oct 1, 2003
          Run antlr.Tool with -traceParser and then run your parser again and see what
          it is doing. Take a look at the generated source code, it's pretty easy to
          read and follow.

          Monty

          -----Original Message-----
          From: jagad [mailto:jagad@...]
          Sent: Wednesday, October 01, 2003 6:52 AM
          To: ANTLR Milis
          Subject: RE: [antlr-interest] stuck expr

          Hi Monty,
          Thanks for your fast response.
          BTW, the parser still stuck even I use the file as input.

          When I try with input:

          (1+2),(1+3);

          NUM_INT
          term
          PLUS
          NUM_INT
          term
          simpleExpr
          expr
          ( expr )
          term
          simpleExpr
          expr <---- end, the COMMA and (1+3) is not process

          Best Regards

          jagad








          Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
        • jagad
          The declaration: exprList : expr (COMMA expr); should be exprList : expr (COMMA expr)*; and my problem still exist, anybody could give me the ligth? TIA
          Message 4 of 11 , Oct 1, 2003
            The declaration:

            exprList : expr (COMMA expr);

            should be

            exprList : expr (COMMA expr)*;

            and my problem still exist, anybody could give me the ligth?

            TIA

            jagad

            On Wed, 2003-10-01 at 20:31, jagad wrote:
            > Hi All,
            >
            > I have simple parser like this one;
            >
            > //***** Parser *****
            > class MyParser extends Parser;
            >
            > goal : exprList SEMI EOF;
            >
            > exprList : expr (COMMA expr);
            >
            > expr : simpleExpr (relOp simpleExpr)*;
            >
            > simpleExpr : (PLUS | MINUS)? term (addOp term)*;
            >
            > term : factor (mulOp factor)*;
            >
            > factor : NUM_INT
            > | NUM_REAL
            > | (LPAREN expr RPAREN)
            > ;
            >
            > mulOp : STAR | SLASH | DIV | AND | SHL| SHR;
            > addOp : PLUS | MINUS | OR | XOR;
            > relOp : GREATHAN
            > | LESSTHAN | GREATHANEQU | LESSTHANEQU |EQU|NOTEQU;
            >
            > //********************
            >
            > The I gerenate into C++ code, the problem is the parser allways stuck on
            > expr and never reach the goal. I have try to set options{ k=xx} with no
            > effect.
            >
            > For input:
            >
            > (1+2);
            >
            > the output is:
            >
            > NUM_INT <----- factor: NUM_INT
            > term <----- term: factor
            > PLUS <----- addOp: PLUS
            > NUM_INT <----- factor: NUM_INT
            > term <----- term: factor
            > simpleExpr <----- simpleExpr: term (addOp term)*;
            > expr <----- expr: simpleExpr
            > ( expr ) <----- factor: (LPAREN expr RPAREN)
            > term <----- term: factor
            > simpleExpr <----- simpleExpr: term
            > expr <----- expr: simpleExpr
            >
            > Why my parser never reach goal? please, let me know.
            >
            > Thanks in Advance and Best Regards
            >
            > jagad
            >
            >
            >
            >
            >
            >
            > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
            >
          • jagad
            Hi Monty, Thanks for your fast response. BTW, the parser still stuck even I use the file as input. When I try with input: (1+2),(1+3); NUM_INT term PLUS
            Message 5 of 11 , Oct 1, 2003
              Hi Monty,
              Thanks for your fast response.
              BTW, the parser still stuck even I use the file as input.

              When I try with input:

              (1+2),(1+3);

              NUM_INT
              term
              PLUS
              NUM_INT
              term
              simpleExpr
              expr
              ( expr )
              term
              simpleExpr
              expr <---- end, the COMMA and (1+3) is not process

              Best Regards

              jagad
            • Ric Klaren
              ... Hmmm you are calling the goal rule I hope? And not MyParser.expr() ? Or did you cut out the traces for goal and exprList ? Cheers, Ric -- ... Before they
              Message 6 of 11 , Oct 1, 2003
                On Wed, Oct 01, 2003 at 09:05:07PM +0700, jagad wrote:
                > I use -parserTrace and try input:
                >
                > (1+2),(1+3);
                >
                > The Output:
                > ------------------------------------
                > > expr; LA(1)==(1+2),(1+3);

                Hmmm you are calling the goal rule I hope? And not MyParser.expr() ? Or did
                you cut out the traces for goal and exprList ?

                Cheers,

                Ric
                --
                -----+++++*****************************************************+++++++++-------
                ---- Ric Klaren ----- j.klaren@... ----- +31 53 4893722 ----
                -----+++++*****************************************************+++++++++-------
                Before they invented drawing boards, what did they go back to?
              • jagad
                I use -parserTrace and try input: (1+2),(1+3); ... ( ... NUM_INT
                Message 7 of 11 , Oct 1, 2003
                  I use -parserTrace and try input:

                  (1+2),(1+3);

                  The Output:
                  ------------------------------------
                  > expr; LA(1)==(1+2),(1+3);
                  (
                  > simpleExpr; LA(1)==(
                  > term; LA(1)==(
                  > factor; LA(1)==(
                  > expr; LA(1)==1
                  > simpleExpr; LA(1)==1
                  > term; LA(1)==1
                  > factor; LA(1)==1
                  NUM_INT
                  < factor; LA(1)==+
                  term
                  < term; LA(1)==+
                  > addOp; LA(1)==+
                  PLUS
                  < addOp; LA(1)==2
                  > term; LA(1)==2
                  > factor; LA(1)==2
                  NUM_INT
                  < factor; LA(1)==)
                  term
                  < term; LA(1)==)
                  simpleExpr
                  < simpleExpr; LA(1)==)
                  expr
                  < expr; LA(1)==)
                  ( expr )
                  < factor; LA(1)==,
                  term
                  < term; LA(1)==,
                  simpleExpr
                  < simpleExpr; LA(1)==,
                  expr
                  < expr; LA(1)==, <--------- lost at COMMA

                  -------------------------------------

                  The problem still exist.

                  Best Regards

                  jagad
                • mzukowski@yci.com
                  See that parser.expr()? That s where you are calling the expr rule at the top level. Sounds like you really want to be calling parser.goal(). Good catch,
                  Message 8 of 11 , Oct 1, 2003
                    See that parser.expr()? That's where you are calling the expr rule at the
                    top level. Sounds like you really want to be calling parser.goal().

                    Good catch, Ric.

                    Monty

                    -----Original Message-----
                    From: jagad [mailto:jagad@...]
                    Sent: Wednesday, October 01, 2003 7:25 AM
                    To: ANTLR Milis
                    Subject: Re: [antlr-interest] stuck expr

                    Hi Ric,

                    Yes, I call MyParser.expr() and No, I don't cut out, the whole result
                    it's just like I sent.

                    Here my snippet:

                    #include "parser/MyParserLexer.hpp"
                    #include "parser/MyParserParser.hpp"
                    #include <iostream>
                    #include <sstream>

                    int main()
                    {
                    ANTLR_USING_NAMESPACE(std)
                    ANTLR_USING_NAMESPACE(antlr)

                    try{
                    MyParserLexer lexer(cin);
                    MyParserParser parser(lexer);

                    parser.expr();
                    }
                    catch(exception& e){
                    cout << "exception: " << e.what() << endl;
                    }

                    return (0);
                    }

                    ---------------

                    The snippet just like the ANTLR example :)
                    I have read the generated code (as adviced by Monty) and it's strange
                    that goal() not called at the first time. Could you give me info where
                    actually the first ANTLR C++ call ?

                    Best Regards

                    jagad

                    P.S: Is it possible that sleepless affecting my code? :) just joke,
                    ANTLR is great and your works at ANTLR C++ is great. Great Tools with a
                    newbie hand like me could be a problem :)


                    On Wed, 2003-10-01 at 20:57, Ric Klaren wrote:
                    > On Wed, Oct 01, 2003 at 09:05:07PM +0700, jagad wrote:
                    > > I use -parserTrace and try input:
                    > >
                    > > (1+2),(1+3);
                    > >
                    > > The Output:
                    > > ------------------------------------
                    > > > expr; LA(1)==(1+2),(1+3);
                    >
                    > Hmmm you are calling the goal rule I hope? And not MyParser.expr() ? Or
                    did
                    > you cut out the traces for goal and exprList ?
                    >
                    > Cheers,
                    >
                    > Ric




                    Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
                  • jagad
                    Hi Ric, Yes, I call MyParser.expr() and No, I don t cut out, the whole result it s just like I sent. Here my snippet: #include parser/MyParserLexer.hpp
                    Message 9 of 11 , Oct 1, 2003
                      Hi Ric,

                      Yes, I call MyParser.expr() and No, I don't cut out, the whole result
                      it's just like I sent.

                      Here my snippet:

                      #include "parser/MyParserLexer.hpp"
                      #include "parser/MyParserParser.hpp"
                      #include <iostream>
                      #include <sstream>

                      int main()
                      {
                      ANTLR_USING_NAMESPACE(std)
                      ANTLR_USING_NAMESPACE(antlr)

                      try{
                      MyParserLexer lexer(cin);
                      MyParserParser parser(lexer);

                      parser.expr();
                      }
                      catch(exception& e){
                      cout << "exception: " << e.what() << endl;
                      }

                      return (0);
                      }

                      ---------------

                      The snippet just like the ANTLR example :)
                      I have read the generated code (as adviced by Monty) and it's strange
                      that goal() not called at the first time. Could you give me info where
                      actually the first ANTLR C++ call ?

                      Best Regards

                      jagad

                      P.S: Is it possible that sleepless affecting my code? :) just joke,
                      ANTLR is great and your works at ANTLR C++ is great. Great Tools with a
                      newbie hand like me could be a problem :)


                      On Wed, 2003-10-01 at 20:57, Ric Klaren wrote:
                      > On Wed, Oct 01, 2003 at 09:05:07PM +0700, jagad wrote:
                      > > I use -parserTrace and try input:
                      > >
                      > > (1+2),(1+3);
                      > >
                      > > The Output:
                      > > ------------------------------------
                      > > > expr; LA(1)==(1+2),(1+3);
                      >
                      > Hmmm you are calling the goal rule I hope? And not MyParser.expr() ? Or did
                      > you cut out the traces for goal and exprList ?
                      >
                      > Cheers,
                      >
                      > Ric
                    • jagad
                      Gotcha! :) I use expr at my xxx.g file! Thanks Monty, I ll fixed it and see how it goes Best Regards jagad
                      Message 10 of 11 , Oct 1, 2003
                        Gotcha! :)
                        I use "expr" at my xxx.g file!

                        Thanks Monty, I'll fixed it and see how it goes

                        Best Regards

                        jagad


                        On Wed, 2003-10-01 at 21:16, mzukowski@... wrote:
                        > See that parser.expr()? That's where you are calling the expr rule at the
                        > top level. Sounds like you really want to be calling parser.goal().
                        >
                        > Good catch, Ric.
                        >
                        > Monty
                        >
                        > -----Original Message-----
                        > From: jagad [mailto:jagad@...]
                        > Sent: Wednesday, October 01, 2003 7:25 AM
                        > To: ANTLR Milis
                        > Subject: Re: [antlr-interest] stuck expr
                        >
                        > Hi Ric,
                        >
                        > Yes, I call MyParser.expr() and No, I don't cut out, the whole result
                        > it's just like I sent.
                        >
                        > Here my snippet:
                        >
                        > #include "parser/MyParserLexer.hpp"
                        > #include "parser/MyParserParser.hpp"
                        > #include <iostream>
                        > #include <sstream>
                        >
                        > int main()
                        > {
                        > ANTLR_USING_NAMESPACE(std)
                        > ANTLR_USING_NAMESPACE(antlr)
                        >
                        > try{
                        > MyParserLexer lexer(cin);
                        > MyParserParser parser(lexer);
                        >
                        > parser.expr();
                        > }
                        > catch(exception& e){
                        > cout << "exception: " << e.what() << endl;
                        > }
                        >
                        > return (0);
                        > }
                        >
                        > ---------------
                        >
                        > The snippet just like the ANTLR example :)
                        > I have read the generated code (as adviced by Monty) and it's strange
                        > that goal() not called at the first time. Could you give me info where
                        > actually the first ANTLR C++ call ?
                        >
                        > Best Regards
                        >
                        > jagad
                        >
                        > P.S: Is it possible that sleepless affecting my code? :) just joke,
                        > ANTLR is great and your works at ANTLR C++ is great. Great Tools with a
                        > newbie hand like me could be a problem :)
                        >
                        >
                        > On Wed, 2003-10-01 at 20:57, Ric Klaren wrote:
                        > > On Wed, Oct 01, 2003 at 09:05:07PM +0700, jagad wrote:
                        > > > I use -parserTrace and try input:
                        > > >
                        > > > (1+2),(1+3);
                        > > >
                        > > > The Output:
                        > > > ------------------------------------
                        > > > > expr; LA(1)==(1+2),(1+3);
                        > >
                        > > Hmmm you are calling the goal rule I hope? And not MyParser.expr() ? Or
                        > did
                        > > you cut out the traces for goal and exprList ?
                        > >
                        > > Cheers,
                        > >
                        > > Ric
                        >
                        >
                        >
                        >
                        > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
                        >
                        >
                        >
                        >
                        > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
                        >
                      • jagad
                        Hi Monty and Ric, Thanks, now I realize that I should call goal() :) The problem is gone :) everything is works. Best Kindest Regards jagad
                        Message 11 of 11 , Oct 1, 2003
                          Hi Monty and Ric,

                          Thanks, now I realize that I should call goal() :)
                          The problem is gone :) everything is works.

                          Best Kindest Regards

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