From: <fwi...@us...> - 2008-01-02 01:50:56
|
Revision: 3945 http://jython.svn.sourceforge.net/jython/?rev=3945&view=rev Author: fwierzbicki Date: 2008-01-01 17:50:54 -0800 (Tue, 01 Jan 2008) Log Message: ----------- start of complex and float support Modified Paths: -------------- trunk/sandbox/ast/grammar/PythonWalker.g trunk/sandbox/ast/jastlib.py Modified: trunk/sandbox/ast/grammar/PythonWalker.g =================================================================== --- trunk/sandbox/ast/grammar/PythonWalker.g 2008-01-02 00:18:13 UTC (rev 3944) +++ trunk/sandbox/ast/grammar/PythonWalker.g 2008-01-02 01:50:54 UTC (rev 3945) @@ -196,8 +196,18 @@ return str.substring(start, end); } + Num makeFloat(PythonTree t) { + debug("makeFloat matched " + t.getText()); + return new Num(t, Double.valueOf(t.getText())); + } - Num makeNum(PythonTree t) { + Num makeComplex(PythonTree t) { + String s = t.getText(); + s = s.substring(0, s.length() - 1); + return new Num(t, Double.valueOf(s)); + } + + Num makeInt(PythonTree t) { debug("Num matched " + t.getText()); String s = t.getText(); int radix = 10; @@ -294,12 +304,14 @@ return new For(t, target, iter, b, o); } - //FIXME: only handling Num for now. + //FIXME: only handling Num + BigInteger for now. private exprType negate(exprType o) { if (o instanceof Num) { Num num = (Num)o; - BigInteger b = (BigInteger)num.n; - num.n = b.negate(); + if (num.n instanceof BigInteger) { + BigInteger b = (BigInteger)num.n; + num.n = b.negate(); + } return num; } return o; @@ -1023,12 +1035,15 @@ $etype = new Subscript($SubscriptList, $test.etype, s, ctype); } | ^(Num INT) { - $etype = makeNum($INT); - debug("makeNum output: " + $etype); + $etype = makeInt($INT); + debug("makeInt output: " + $etype); } - | ^(Num LONGINT) {$etype = makeNum($LONGINT);} - | ^(Num FLOAT) - | ^(Num COMPLEX) + | ^(Num LONGINT) {$etype = makeInt($LONGINT);} + | ^(Num FLOAT) { + $etype = makeFloat($FLOAT); + debug("float matched" + $etype); + } + | ^(Num COMPLEX) {$etype = makeComplex($COMPLEX);} | stringlist { $etype = new Str($stringlist.start, extractStrings($stringlist.strings)); } Modified: trunk/sandbox/ast/jastlib.py =================================================================== --- trunk/sandbox/ast/jastlib.py 2008-01-02 00:18:13 UTC (rev 3944) +++ trunk/sandbox/ast/jastlib.py 2008-01-02 01:50:54 UTC (rev 3945) @@ -13,6 +13,8 @@ from types import ArrayType +from java.math import BigInteger + def lispify_ast(node): return tuple(lispify_ast2(node)) @@ -43,8 +45,13 @@ if fname in ("ctx", "ops", "op"): yield tuple([str(node)]) elif fname == "n": - #assuming n is BigInteger -- valid for now. - yield node.intValue() + try: + if isinstance(node, BigInteger): + yield node.intValue() + elif isinstance(node, float): + yield node + except Exception, why: + print "error processing n: %s" % why else: yield node This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |