[pypy-svn] r13473 - pypy/branch/pycompiler/module/recparser

adim at codespeak.net adim at codespeak.net
Thu Jun 16 14:09:26 CEST 2005


Author: adim
Date: Thu Jun 16 14:09:24 2005
New Revision: 13473

Modified:
   pypy/branch/pycompiler/module/recparser/syntaxtree.py
   pypy/branch/pycompiler/module/recparser/tuplebuilder.py
Log:
small cleanups in SYMBOL's management



Modified: pypy/branch/pycompiler/module/recparser/syntaxtree.py
==============================================================================
--- pypy/branch/pycompiler/module/recparser/syntaxtree.py	(original)
+++ pypy/branch/pycompiler/module/recparser/syntaxtree.py	Thu Jun 16 14:09:24 2005
@@ -61,12 +61,13 @@
     "|=" : token.VBAREQUAL,
     }
 NT_OFFSET = token.NT_OFFSET    
+
 SYMBOLS = {}
 # copies the numerical mapping between symbol name and symbol value
 # into SYMBOLS
-for k,v in symbol.__dict__.items():
-    if type(v)==int:
-        SYMBOLS[k] = v
+for k,v in symbol.sym_name.items():
+    SYMBOLS[v] = k
+SYMBOLS['UNKNOWN'] = -1
 
 
 class SyntaxNode(object):

Modified: pypy/branch/pycompiler/module/recparser/tuplebuilder.py
==============================================================================
--- pypy/branch/pycompiler/module/recparser/tuplebuilder.py	(original)
+++ pypy/branch/pycompiler/module/recparser/tuplebuilder.py	Thu Jun 16 14:09:24 2005
@@ -3,11 +3,13 @@
 from syntaxtree import TOKEN_MAP, SYMBOLS # , NT_OFFSET
 
 
+class 
 def _expand_nodes(nodes):
     expanded = []
     for n in nodes:
         if n[0] == -2:
-            expanded.extend(expand_nodes(n[1:]))
+            # expanded.extend(expand_nodes(n[1:]))
+            expanded.extend(n[1:])
         else:
             expanded.append(n)
     return tuple(expanded)
@@ -24,6 +26,7 @@
     def __init__(self, rules=None, debug=0, lineno=True):
         BaseGrammarBuilder.__init__(self, rules, debug )
         self.lineno = lineno
+        self._unknown = -10
 
     def alternative(self, rule, source):
         # Do nothing, keep rule on top of the stack
@@ -36,7 +39,12 @@
     def sequence(self, rule, source, elts_number):
         """ """
         if rule.is_root():
-            node = [SYMBOLS.get( rule.name, (0, rule.name) )]
+            if SYMBOLS.has_key(rule.name):
+                node = [SYMBOLS[rule.name]]
+            else:
+                node = [self._unknown]
+                SYMBOLS[rule.name] = self._unknown
+                self._unknown -= 1
         else:
             node = [-2]
         if elts_number > 0:



More information about the Pypy-commit mailing list