[Mumps2Py:] [27] added handling for a couple more for-loop variants and fixed the handling of $C (a,b,c,...).

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


Revision: 27
Author:   pgallot
Date:     2008-01-18 21:01:16 +0000 (Fri, 18 Jan 2008)

Log Message:
-----------
added handling for a couple more for-loop variants and fixed the handling of $C(a,b,c,...).

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


Modified: trunk/mumps2py/tok2python.py
===================================================================
--- trunk/mumps2py/tok2python.py	2008-01-18 20:54:37 UTC (rev 26)
+++ trunk/mumps2py/tok2python.py	2008-01-18 21:01:16 UTC (rev 27)
@@ -124,10 +124,10 @@
             char_str = "chr(%s)" % \
                        translate_expr(translation, token.params[0])
         else:
-            char_str = r"''.join(map(chr, "
+            char_str = r"''.join(map(chr, ("
             for param in token.params:
                 char_str = char_str + translate_expr(translation, param) + ", "
-            char_str = char_str[:-2] + ')'
+            char_str = char_str[:-2] + ")))"
         return char_str
 
     def translate_intr_extract(translation, token):
@@ -261,7 +261,9 @@
 def translate_for(translation, token):
     """translate the Mumps For Command to Python"""
     #TODO: completely redo to use a MumpsCL iterator...
-    if len(token.for_loops) == 1 and token.for_loops[0].has_key('TermVal'):
+    if len(token.for_loops) == 0: # then we've got an infinite-loop.
+        return "%swhile 1:\n" % tab(token.indentlevel)
+    elif len(token.for_loops) == 1 and token.for_loops[0].has_key('TermVal'):
         init_tok = token.for_loops[0]['initVal']
         incr_tok = token.for_loops[0]['IncrVal']
         trm_tok = token.for_loops[0]['TermVal']
@@ -292,6 +294,19 @@
                    trm_val,
                    incr_val)
         return for_str
+    elif len(token.for_loops) > 1:
+        vals_str = ""
+        for loop in token.for_loops:
+            if loop.has_key('IncrVal'):
+                raise TranslationError(translation, token,
+                                       "idiom not implemented")
+            vals_str = "%s%s, " % (vals_str, \
+                                   translate_expr(translation, loop["initVal"]))
+        for_str = "%sfor %s in (%s):\n" % \
+                  (tab(token.indentlevel), \
+                   translate_expr(translation, token.loop_incr_var),
+                   vals_str[:-2])
+        return for_str
     else:
         raise TranslationError(translation, token, "idiom not implemented")
 


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