perhaps there is some value in delaying evaluation ... i'm thinking about expression trees and LINQ.

—Mohamed

On 31/12/09 05:07, Philip Cannata wrote:
Frank and Marc, thanks for your time. Let me explain a little bit 
what I'm trying to do. For teaching purposes, I like to teach my 
students to modify the grammar first before proceeding to the AST 
etc. So, with the small change to Python.g below I've gotten the 
following to be recognized:
 >>> a=111
 >>> b=a+222
 >>> SELECT * FROM emp WHERE x = b
SELECT Statement is: SELECT *  FROM emp, WHERE x = b

but, I'd like to get it to print out:
SELECT Statement is: SELECT *  FROM emp, WHERE x = 333
by getting the value of "b" which I believe has already been parsed 
and turned into a real object and therefore has a value when I'm 
parsing the SELECT line. (i.e., I need something in place of $e.text).

Here's the change to Python.g starting at line 568:
//small_stmt: (expr_stmt | print_stmt  | del_stmt | pass_stmt | flow_stmt |
//             import_stmt | global_stmt | exec_stmt | assert_stmt)
small_stmt : expr_stmt
            | print_stmt
            | del_stmt
            | pass_stmt
            | flow_stmt
            | import_stmt
            | global_stmt
            | exec_stmt
            | assert_stmt
            | query_stmt
            ;
//query_stmt: SELECT * FROM person WHERE x = value
query_stmt
     : SELECT STAR CAPSFROM n1 = NAME ( WHERE n2 = NAME ASSIGN e = expr_stmt )?
         { System.out.println("SELECT Statement is: SELECT *  FROM " 
+ $n1.text + ", WHERE " + $n2.text + " = " + $e.text); }
    -> ^(SELECT<Pass>[$SELECT])
     ;

At 03:35 PM 12/30/2009, Frank Wierzbicki wrote:
  
On Wed, Dec 30, 2009 at 4:08 PM, Philip Cannata <Phil.Cannata@sun.com> wrote:
    
Yes, but if I put it in Python.g at line 639 as follows:
      
Probably Python.g is not the place you want to be putting this, since
the x in "x = a + b" is only a symbol from the viewpoint of parsing
(which is all Python.g does).  The way you get from source to
something at runtime goes roughly:

Source --- (parse) ---> AST --- (compile) ---> Java bytecodes ---
(class loading) ---> real objects ready to run --- (interpreter) --->
actual values like x = 333

-Frank
    

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
Jython-dev mailing list
Jython-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-dev