[Mumps2Py:] [3] use the is_not() helper function, and handle cases where the not operator is in front of the binary operator .

[ Thread Index | Date Index | More lists.mumps2py.org/discuss Archives ]


Revision: 3
Author:   pgallot
Date:     2008-01-17 15:54:57 +0000 (Thu, 17 Jan 2008)

Log Message:
-----------
use the is_not() helper function, and handle cases where the not operator is in front of the binary operator.

Modified Paths:
--------------
    trunk/tok2python.py


Modified: trunk/tok2python.py
===================================================================
--- trunk/tok2python.py	2008-01-17 15:50:37 UTC (rev 2)
+++ trunk/tok2python.py	2008-01-17 15:54:57 UTC (rev 3)
@@ -99,7 +99,7 @@
         def trans_unary_expr(left_token, right_token):
             if left_token.toktype == OPSUB:
                 return "-"+translate_expr(translation, right_token)
-            elif left_token.toktype == OPNOT:
+            elif left_token.is_not():
                 return "not "+translate_expr(translation, right_token)
             else:
                 raise TranslationError(translation, left_token,
@@ -123,13 +123,18 @@
         else:
             left_str = translate_expr(translation, first_token)
         while expr_list:
+            not_str=""
             binop_token = expr_list.pop(0)
+            if binop_token.is_not():
+                not_str = "not "
+                binop_token = expr_list.pop(0)
+                
             right_token = expr_list.pop(0)
             if right_token.is_unaryop():
                 right_str = trans_unary_expr(right_token, expr_list.pop(0))
             else:
                 right_str = translate_expr(translation, right_token)
-            left_str = "(%s %s %s)" % (left_str, trans_binary_op(binop_token),
+            left_str = "%s(%s %s %s)" % (not_str,left_str, trans_binary_op(binop_token),
                                        right_str)
         return left_str
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/