[Mumps2Py:] [65] added support for the $random intrinsic

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


Revision: 65
Author:   pgallot
Date:     2008-01-28 21:24:46 +0000 (Mon, 28 Jan 2008)

Log Message:
-----------
added support for the $random intrinsic

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


Modified: trunk/mumps2py/tok2python.py
===================================================================
--- trunk/mumps2py/tok2python.py	2008-01-28 20:57:01 UTC (rev 64)
+++ trunk/mumps2py/tok2python.py	2008-01-28 21:24:46 UTC (rev 65)
@@ -274,6 +274,17 @@
                                        "incorrect number of parameters")
         return piece_str
     
+    def translate_intr_random(translation, token):
+        """ translates the Mumps Intrinsic function RANDOM to Python"""
+        if len(token.params) == 1:
+            translation.add_import("random")
+            random_str = "random.randint(0, %s)" % \
+                          translate_expr(translation, token.params[0])
+        else:
+            raise TranslationError(translation, token,
+                                   "incorrect number of parameters")
+        return random_str
+
     def translate_intr_reverse(translation, token):
         """ translates the Mumps Intrinsic function REVERSE to Python"""
         if len(token.params) == 1:
@@ -359,6 +370,7 @@
         F_JUSTIFY: translate_intr_justify,
         F_LENGTH: translate_intr_length,
         F_PIECE: translate_intr_piece,
+        F_RANDOM: translate_intr_random,
         F_REVERSE: translate_intr_reverse,
         EXPR: translate_expr_list}
 


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