[Compiler-sig] Jython progres
Finn Bock
bckfnn@worldonline.dk
Sun, 14 Apr 2002 15:43:19 GMT
Hi,
I can now transform all the standard Lib .py files from CPython with the
AST tree builder I have made for jython. I have used a slightly modified
python.asdl, but most of the changes have been discussed here
previously.
A cute little detail about my approach is that I have no intermediate
parse tree structure. Instead I can create the AST nodes directly.
Obviously I can't generate java bytecode from the AST yet, that is next
phase that I will work on (and I'm sure that bugs will surface when I
start).
Below are the changes I made. I can work without the 'ifpart' change,
but the rest should IMO be committed in some form.
regards,
finn
Index: python.asdl
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/ast/python.asdl,v
retrieving revision 1.11
diff -w -u -r1.11 python.asdl
--- python.asdl 14 Apr 2002 10:10:02 -0000 1.11
+++ python.asdl 14 Apr 2002 15:28:07 -0000
@@ -6,7 +6,7 @@
stmt = FunctionDef(identifier name, arguments args, stmt* body)
| ClassDef(identifier name, expr* bases, stmt* body)
- | Return(expr value) | Yield(expr value)
+ | Return(expr? value) | Yield(expr value)
| Del(assign* targets)
| Assign(assign* targets, expr value)
@@ -19,7 +19,7 @@
-- need a better solution for that
| For(expr target, expr iter, stmt* body, stmt* orelse)
| While(expr test, stmt* body, stmt* orelse)
- | If(expr test, stmt* body, stmt* orelse)
+ | If(ifpart* tests, stmt* orelse)
-- 'type' is a bad name
| Raise(expr? type, expr? inst, expr? tback)
@@ -66,7 +66,7 @@
slice = Ellipsis | Slice(expr? lower, expr? upper)
-- maybe Slice and ExtSlice should be merged...
- | ExtSlice(expr* dims)
+ | ExtSlice(slice* dims)
boolop = And | Or
@@ -85,11 +85,17 @@
except = (expr? type, assign? name, stmt* body)
-- XXX need to handle 'def f((a, b)):'
- arguments = (identifier* args, identifier? vararg,
+ arguments = (fpdef* args, identifier? vararg,
identifier? kwarg, expr* defaults)
+ fpdef = FpList(fpdef* list)
+ | FpName(identifier id)
+
-- keyword arguments supplied to call
keyword = (identifier arg, expr value)
+
+ ifpart = (expr test, stmt* body)
+
-- import name with optional 'as' alias.
alias = (identifier name, identifier? asname)