[antlr-interest] Inspecting return values

Johnson, Janeen JOHNSJA at intelsat.com
Tue Jan 23 10:54:32 PST 2007


All

I'm an antlr newbie using 2.7.7 with Java so forgive me (and enlighten
me) if this is a stupid question.  I've been working on this specific
problem for 3 days and am still stuck.  I created the ultra simple
sample data and tableswitch function below to use as a test-case-only
within my larger .g file.

I have a function 3-5 levels down in my parse tree that returns a String
value.  In the generated code, the return value isn't captured.  What
have I done wrong and how can I correct it?

I've snipped a lot of code away above and below these in the tree so if
what is needed to help me is not included let me know and I'll send
more.  Thank you.  Janeen

________________________________________________________________________
____
Sample input line returned by the lexer:

table-switch-input ( 101-ANT100 )
________________________________________________________________________
____
In the parser:

(snipped)

statement   : ((status)
                  | (tableswitch[#toggle])
... (snipped)
                  | (LITRL) )
                 ;
status        : ((THE) (ID) (OF) (EXTPINNAME));
tableswitch : ((TABLETSWITCHINPUT) (LPAREN) (EXTPINNAME) (RPAREN)) ;
(snipped)

________________________________________________________________________
______
In the ParseTree (.g file):

statement [String toggle]  returns [String rtnValue]
        {
          rtnValue = "";
        } : ((sttus: status [#toggle]! { /*  code snipped */} )
          | (tbs: tableswitch [#toggle]! { /* I would like to check the
return value at this level of code */ } )
          | (LITRL)
          );

tableswitch [String toggle] returns [String rtnValue]
        { rtnValue = "";
          int pinValue = 0;
          String pinName = "";
          int rtnInt = 0;
        } : (TABLETSWITCHINPUT! LPAREN! ttpin:EXTPINNAME! RPAREN!
                        {
		  (snipped)
                          rtnInt =
tableSwitchFunc.set_param("TABLE-SWITCH-INPUT", pinValue);  /*  Call to
outside function that returns the correct value */
                          rtnValue = new Integer(rtnInt).toString();
                          System.out.println("from tableswitch:
rtnValue); // Correct value prints here
                         }
           );

________________________________________________________________________
____
Q:  Where is the return value stored?  How can I inspect it?  How can I
also assign it as the return value for "statement"?

Generated code -- call from "statement" to tableswitch:
(snipped)
                                case TABLETSWITCHINPUT:
                                {
                                        {
                                        tbs = _t==ASTNULL ? null :
(AST)_t;
                                        tableswitch(_t,toggle);
/*  I thought ANTLR would save the return value here, but it doesn't
look like it */
                                        _t = _retTree;
                                        tbs_AST = (AST)returnAST;
                                        rtnValue =
tbs.getText().toString();
 
System.out.println("from statement:  tableswitch rtnValue = " + rtnValue
);

                                        }
                                        break;
                                }
 (snipped)
                        returnAST = statement_AST;
                        _retTree = _t;
                        return rtnValue;

(snipped)

Thank you in advance for any help you can give me.

Janeen
Intelsat is the world's largest provider of fixed satellite services.  Real-time, constant communications with people anywhere in the world is closer, by far.  

For more information about Intelsat, visit www.intelsat.com. 

 

This email message is for the sole use of the intended recipients and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. Any views expressed in this message are those of the individual sender, except where the sender specifically states them to be the views of Intelsat, Ltd. and its subsidiaries.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070123/d35c9bca/attachment-0001.html 


More information about the antlr-interest mailing list