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

7908RE: [antlr-interest] Treewalking : non-determinism error

Expand Messages
  • Anthony Youngman
    Apr 1, 2003
      Message
      Okay, I've tried this. It has no effect, and looking at the treewalker source, it seems like I'm misunderstanding things.
       
      It seems to be looking for the next token at the SAME LEVEL as the PRINT to decide which alternative which seems weird (although that's probably my lack of Java skills). I need to choose my route based on whether COLONPRINT is there or not, and can't see how to make it unambiguous. Or can I put a type-change where it recognises COLONPRINT in the main parser?
      "printst : (pr:"PRINT"^ expr (COLONPRINT {_ttype = PRINTNL})? {System.out.println(pr+" print ");} );"
       
      Cheers,
      Wol
      -----Original Message-----
      From: Anthony Youngman
      Sent: 01 April 2003 11:56
      To: 'antlr-interest@yahoogroups.com'
      Subject: [antlr-interest] Treewalking : non-determinism error

      I think I know what the problem is, I just don't know how to fix it ...

      In my main parser, I have the following two rules:

      printst : (pr:"PRINT"^ expr (COLONPRINT)? {System.out.println(pr+" print ");} );
      expr : ( catexpr | logicexpr ) ;

      This seems to be fine - the traces are printing what I expect.

      In my treewalker I then have the rule:

      printst
              : #(PRINT expr COLONPRINT) {System.out.println("PRNT");}
              | #(PRINT expr) {System.out.println("OUTP");}
              ;

      which is giving me a non-determinism error. What I think is happening is that "expr" is being expanded, thus confusing the parser. What I think I need to do is to declare a token "EXPR", and make this the root of an "expr" AST in my main parser, so my two options in the treewalker become "PRINT EXPR COLONPRINT" and "PRINT EXPR".

      So. Am I right? And if so, what should my syntax for the "expr" rule in the main parser become? I've looked at the Tree Construction man page, and Ashley Mills tutorial, and I can't quite get to grips with it. I presume I need something like

      expr! : ( catexpr | logicexpr ) {#expr = #([EXPR], #expr); } ;

      Will this create a root of EXPR with a daughter of catexpr or logicexpr?

      Cheers,
      Wol


      This transmission is intended for the named recipient only. It may contain private and confidential information. If this has come to you in error you must not act on anything disclosed in it, nor must you copy it, modify it, disseminate it in any way, or show it to anyone. Please e-mail the sender to inform us of the transmission error or telephone ECA International immediately and delete the e-mail from your information system.

      Telephone numbers for ECA International offices are: Sydney +61 (0)2 9911 7799, Hong Kong + 852 2121 2388, London +44 (0)20 7351 5000 and New York +1 212 582 2333.


      Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.


      This transmission is intended for the named recipient only. It may contain private and confidential information. If this has come to you in error you must not act on anything disclosed in it, nor must you copy it, modify it, disseminate it in any way, or show it to anyone. Please e-mail the sender to inform us of the transmission error or telephone ECA International immediately and delete the e-mail from your information system.

      Telephone numbers for ECA International offices are: Sydney +61 (0)2 9911 7799, Hong Kong + 852 2121 2388, London +44 (0)20 7351 5000 and New York +1 212 582 2333.


    • Show all 7 messages in this topic