[Mumps2Py:] [45] added an is_var method to Token and a VarToken subclass of Token for variable tokens .

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


Revision: 45
Author:   pgallot
Date:     2008-01-23 21:15:57 +0000 (Wed, 23 Jan 2008)

Log Message:
-----------
added an is_var method to Token and a VarToken subclass of Token for variable tokens.

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


Modified: trunk/mumps2py/tokens.py
===================================================================
--- trunk/mumps2py/tokens.py	2008-01-23 21:11:26 UTC (rev 44)
+++ trunk/mumps2py/tokens.py	2008-01-23 21:15:57 UTC (rev 45)
@@ -426,6 +426,10 @@
         """returns true if the token is an expression"""
         return (self.toktype == EXPR)
 
+    def is_var(self):
+        """returns true if the token is a variable"""
+        return (self.toktype in (LOCALVAR, GLOBALVAR))
+
     def is_unaryop(self):
         """returns true if the token is a unary operator"""
         
@@ -446,3 +450,19 @@
     def extract_subtokens(self, extract_dict, extract_types):
         """extract the (sub)tokens of the given types."""
         return extract_subtokens(extract_dict, extract_types, self)
+
+
+class VarToken(Token):
+    """Token subclass specifically for variables"""
+    def __init__(self, tok_type, startpos):
+        """ initializes a Token object of a variable Token type."""
+        Token.__init__(self, tok_type, startpos)
+
+    def is_indexed(self):
+        """ returns true if this variable is ever indexed (after the prepass)"""
+        return self.__dict__.has_key('indices')
+
+    def has_index(self):
+        """if this instance of the variable has an index, returns it"""
+        if self.is_indexed():
+            return self.indices


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