Rework how tag/symbol lists from the parser are handled, collect precedence and assoc...
authorNick Downing <downing.nick@gmail.com>
Tue, 17 Jul 2018 02:14:50 +0000 (12:14 +1000)
committerNick Downing <downing.nick@gmail.com>
Tue, 17 Jul 2018 02:14:50 +0000 (12:14 +1000)
ast.py
bison_lr1dfa.py

diff --git a/ast.py b/ast.py
index 26e3a1f..26b7a6f 100644 (file)
--- a/ast.py
+++ b/ast.py
@@ -32,6 +32,7 @@ class Item(element.Element):
     self,
     pyacc,
     section,
+    character_to_symbol,
     name_to_symbol
   ):
     raise NotImplementedException
@@ -39,7 +40,7 @@ class Item(element.Element):
 class PYACC(element.Element):
   # internal classes
   class Symbol(element.Element):
-    # GENERATE ELEMENT(str name, list(int) character_set) BEGIN
+    # GENERATE ELEMENT(str name, list(int) character_set, int precedence, int associativity) BEGIN
     def __init__(
       self,
       tag = 'PYACC_Symbol',
@@ -47,7 +48,9 @@ class PYACC(element.Element):
       text = '',
       children = [],
       name = '',
-      character_set = []
+      character_set = [],
+      precedence = -1,
+      associativity = -1
     ):
       element.Element.__init__(
         self,
@@ -62,6 +65,16 @@ class PYACC(element.Element):
       if isinstance(character_set, str) else
         character_set
       )
+      self.precedence = (
+        element.deserialize_int(precedence)
+      if isinstance(precedence, str) else
+        precedence
+      )
+      self.associativity = (
+        element.deserialize_int(associativity)
+      if isinstance(associativity, str) else
+        associativity
+      )
     def serialize(self, ref_list, indent = 0):
       element.Element.serialize(self, ref_list, indent)
       self.set('name', element.serialize_str(self.name))
@@ -69,6 +82,8 @@ class PYACC(element.Element):
         'character_set',
         ' '.join([element.serialize_int(i) for i in self.character_set])
       )
+      self.set('precedence', element.serialize_int(self.precedence))
+      self.set('associativity', element.serialize_int(self.associativity))
     def deserialize(self, ref_list):
       element.Element.deserialize(self, ref_list)
       self.name = element.deserialize_str(self.get('name', ''))
@@ -76,6 +91,8 @@ class PYACC(element.Element):
         element.deserialize_int(i)
         for i in self.get('character_set', '').split()
       ]
+      self.precedence = element.deserialize_int(self.get('precedence', '-1'))
+      self.associativity = element.deserialize_int(self.get('associativity', '-1'))
     def copy(self, factory = None):
       result = element.Element.copy(
         self,
@@ -83,6 +100,8 @@ class PYACC(element.Element):
       )
       result.name = self.name
       result.character_set = self.character_set
+      result.precedence = self.precedence
+      result.associativity = self.associativity
       return result
     def repr_serialize(self, params):
       element.Element.repr_serialize(self, params)
@@ -96,6 +115,14 @@ class PYACC(element.Element):
             ', '.join([repr(i) for i in self.character_set])
           )
         )
+      if self.precedence != -1:
+        params.append(
+          'precedence = {0:s}'.format(repr(self.precedence))
+        )
+      if self.associativity != -1:
+        params.append(
+          'associativity = {0:s}'.format(repr(self.associativity))
+        )
     def __repr__(self):
       params = []
       self.repr_serialize(params)
@@ -402,6 +429,7 @@ class PYACC(element.Element):
     def post_process(
       self,
       pyacc,
+      character_to_symbol,
       name_to_symbol
     ):
       raise NotImplementedException
@@ -539,62 +567,6 @@ class PYACC(element.Element):
         ]
       )
 
-  class Tag(element.Element):
-    # GENERATE ELEMENT() BEGIN
-    def __init__(
-      self,
-      tag = 'PYACC_Tag',
-      attrib = {},
-      text = '',
-      children = []
-    ):
-      element.Element.__init__(
-        self,
-        tag,
-        attrib,
-        text,
-        children
-      )
-    def copy(self, factory = None):
-      result = element.Element.copy(
-        self,
-        Tag if factory is None else factory
-      )
-      return result
-    def __repr__(self):
-      params = []
-      self.repr_serialize(params)
-      return 'ast.PYACC.Tag({0:s})'.format(', '.join(params))
-    # GENERATE END
-
-  class TagNone(element.Element):
-    # GENERATE ELEMENT() BEGIN
-    def __init__(
-      self,
-      tag = 'PYACC_TagNone',
-      attrib = {},
-      text = '',
-      children = []
-    ):
-      element.Element.__init__(
-        self,
-        tag,
-        attrib,
-        text,
-        children
-      )
-    def copy(self, factory = None):
-      result = element.Element.copy(
-        self,
-        TagNone if factory is None else factory
-      )
-      return result
-    def __repr__(self):
-      params = []
-      self.repr_serialize(params)
-      return 'ast.PYACC.TagNone({0:s})'.format(', '.join(params))
-    # GENERATE END
-
   class Text(element.Element):
     # GENERATE ELEMENT() BEGIN
     def __init__(
@@ -624,44 +596,6 @@ class PYACC(element.Element):
     # GENERATE END
 
   class Section1Or2(Section):
-    # GENERATE ELEMENT() BEGIN
-    def __init__(
-      self,
-      tag = 'PYACC_Section1Or2',
-      attrib = {},
-      text = '',
-      children = []
-    ):
-      PYACC.Section.__init__(
-        self,
-        tag,
-        attrib,
-        text,
-        children
-      )
-    def copy(self, factory = None):
-      result = PYACC.Section.copy(
-        self,
-        Section1Or2 if factory is None else factory
-      )
-      return result
-    def __repr__(self):
-      params = []
-      self.repr_serialize(params)
-      return 'ast.PYACC.Section1Or2({0:s})'.format(', '.join(params))
-    # GENERATE END
-    def post_process(
-      self,
-      pyacc,
-      name_to_symbol
-    ):
-      for i in self:
-        i.post_process(
-          pyacc,
-          self,
-          name_to_symbol
-        )
-
     class Code(Item):
       # GENERATE ELEMENT() BEGIN
       def __init__(
@@ -691,34 +625,6 @@ class PYACC(element.Element):
       # GENERATE END
 
     class CodeProps(Item):
-      class GenericSymList(element.Element):
-        # GENERATE ELEMENT() BEGIN
-        def __init__(
-          self,
-          tag = 'PYACC_Section1Or2_CodeProps_GenericSymList',
-          attrib = {},
-          text = '',
-          children = []
-        ):
-          element.Element.__init__(
-            self,
-            tag,
-            attrib,
-            text,
-            children
-          )
-        def copy(self, factory = None):
-          result = element.Element.copy(
-            self,
-            GenericSymList if factory is None else factory
-          )
-          return result
-        def __repr__(self):
-          params = []
-          self.repr_serialize(params)
-          return 'ast.PYACC.Section1Or2.CodeProps.GenericSymList({0:s})'.format(', '.join(params))
-        # GENERATE END
-
       # GENERATE ELEMENT() BEGIN
       def __init__(
         self,
@@ -803,69 +709,14 @@ class PYACC(element.Element):
       # GENERATE END
 
     class Precedence(Item):
-      class Symbols(element.Element):
-        class Symbol(element.Element):
-          # GENERATE ELEMENT() BEGIN
-          def __init__(
-            self,
-            tag = 'PYACC_Section1Or2_Precedence_Symbols_Symbol',
-            attrib = {},
-            text = '',
-            children = []
-          ):
-            element.Element.__init__(
-              self,
-              tag,
-              attrib,
-              text,
-              children
-            )
-          def copy(self, factory = None):
-            result = element.Element.copy(
-              self,
-              Symbol if factory is None else factory
-            )
-            return result
-          def __repr__(self):
-            params = []
-            self.repr_serialize(params)
-            return 'ast.PYACC.Section1Or2.Precedence.Symbols.Symbol({0:s})'.format(', '.join(params))
-          # GENERATE END
-
-        # GENERATE ELEMENT() BEGIN
-        def __init__(
-          self,
-          tag = 'PYACC_Section1Or2_Precedence_Symbols',
-          attrib = {},
-          text = '',
-          children = []
-        ):
-          element.Element.__init__(
-            self,
-            tag,
-            attrib,
-            text,
-            children
-          )
-        def copy(self, factory = None):
-          result = element.Element.copy(
-            self,
-            Symbols if factory is None else factory
-          )
-          return result
-        def __repr__(self):
-          params = []
-          self.repr_serialize(params)
-          return 'ast.PYACC.Section1Or2.Precedence.Symbols({0:s})'.format(', '.join(params))
-        # GENERATE END
-
-      # GENERATE ELEMENT() BEGIN
+      # GENERATE ELEMENT(int type) BEGIN
       def __init__(
         self,
         tag = 'PYACC_Section1Or2_Precedence',
         attrib = {},
         text = '',
-        children = []
+        children = [],
+        type = -1
       ):
         Item.__init__(
           self,
@@ -874,17 +725,51 @@ class PYACC(element.Element):
           text,
           children
         )
+        self.type = (
+          element.deserialize_int(type)
+        if isinstance(type, str) else
+          type
+        )
+      def serialize(self, ref_list, indent = 0):
+        Item.serialize(self, ref_list, indent)
+        self.set('type', element.serialize_int(self.type))
+      def deserialize(self, ref_list):
+        Item.deserialize(self, ref_list)
+        self.type = element.deserialize_int(self.get('type', '-1'))
       def copy(self, factory = None):
         result = Item.copy(
           self,
           Precedence if factory is None else factory
         )
+        result.type = self.type
         return result
+      def repr_serialize(self, params):
+        Item.repr_serialize(self, params)
+        if self.type != -1:
+          params.append(
+            'type = {0:s}'.format(repr(self.type))
+          )
       def __repr__(self):
         params = []
         self.repr_serialize(params)
         return 'ast.PYACC.Section1Or2.Precedence({0:s})'.format(', '.join(params))
       # GENERATE END
+      def post_process(
+        self,
+        pyacc,
+        section,
+        character_to_symbol,
+        name_to_symbol
+      ):
+        self[0].post_process(
+          pyacc,
+          section,
+          character_to_symbol,
+          name_to_symbol,
+          pyacc.precedences, # precedence
+          self.type # associativity
+        )
+        pyacc.precedences += 1
 
     class Start(Item):
       # GENERATE ELEMENT() BEGIN
@@ -914,16 +799,16 @@ class PYACC(element.Element):
         return 'ast.PYACC.Section1Or2.Start({0:s})'.format(', '.join(params))
       # GENERATE END
 
-    class SymbolDef(Item):
+    class TagOrSymbol(element.Element):
       # GENERATE ELEMENT() BEGIN
       def __init__(
         self,
-        tag = 'PYACC_Section1Or2_SymbolDef',
+        tag = 'PYACC_Section1Or2_TagOrSymbol',
         attrib = {},
         text = '',
         children = []
       ):
-        Item.__init__(
+        element.Element.__init__(
           self,
           tag,
           attrib,
@@ -931,16 +816,209 @@ class PYACC(element.Element):
           children
         )
       def copy(self, factory = None):
-        result = Item.copy(
+        result = element.Element.copy(
+          self,
+          TagOrSymbol if factory is None else factory
+        )
+        return result
+      def __repr__(self):
+        params = []
+        self.repr_serialize(params)
+        return 'ast.PYACC.Section1Or2.TagOrSymbol({0:s})'.format(', '.join(params))
+      # GENERATE END
+      def post_process(
+        self,
+        pyacc,
+        section,
+        character_to_symbol,
+        name_to_symbol,
+        precedence,
+        associativity,
+        tag
+      ):
+        raise NotImplementedException
+
+    class Tag(TagOrSymbol):
+      # GENERATE ELEMENT(int type) BEGIN
+      def __init__(
+        self,
+        tag = 'PYACC_Section1Or2_Tag',
+        attrib = {},
+        text = '',
+        children = [],
+        type = -1
+      ):
+        PYACC.Section1Or2.TagOrSymbol.__init__(
+          self,
+          tag,
+          attrib,
+          text,
+          children
+        )
+        self.type = (
+          element.deserialize_int(type)
+        if isinstance(type, str) else
+          type
+        )
+      def serialize(self, ref_list, indent = 0):
+        PYACC.Section1Or2.TagOrSymbol.serialize(self, ref_list, indent)
+        self.set('type', element.serialize_int(self.type))
+      def deserialize(self, ref_list):
+        PYACC.Section1Or2.TagOrSymbol.deserialize(self, ref_list)
+        self.type = element.deserialize_int(self.get('type', '-1'))
+      def copy(self, factory = None):
+        result = PYACC.Section1Or2.TagOrSymbol.copy(
+          self,
+          Tag if factory is None else factory
+        )
+        result.type = self.type
+        return result
+      def repr_serialize(self, params):
+        PYACC.Section1Or2.TagOrSymbol.repr_serialize(self, params)
+        if self.type != -1:
+          params.append(
+            'type = {0:s}'.format(repr(self.type))
+          )
+      def __repr__(self):
+        params = []
+        self.repr_serialize(params)
+        return 'ast.PYACC.Section1Or2.Tag({0:s})'.format(', '.join(params))
+      # GENERATE END
+      def post_process(
+        self,
+        pyacc,
+        section,
+        character_to_symbol,
+        name_to_symbol,
+        precedence,
+        associativity,
+        tag
+      ):
+        return self
+
+    class Symbol(TagOrSymbol):
+      # GENERATE ELEMENT() BEGIN
+      def __init__(
+        self,
+        tag = 'PYACC_Section1Or2_Symbol',
+        attrib = {},
+        text = '',
+        children = []
+      ):
+        PYACC.Section1Or2.TagOrSymbol.__init__(
+          self,
+          tag,
+          attrib,
+          text,
+          children
+        )
+      def copy(self, factory = None):
+        result = PYACC.Section1Or2.TagOrSymbol.copy(
+          self,
+          Symbol if factory is None else factory
+        )
+        return result
+      def __repr__(self):
+        params = []
+        self.repr_serialize(params)
+        return 'ast.PYACC.Section1Or2.Symbol({0:s})'.format(', '.join(params))
+      # GENERATE END
+      def post_process(
+        self,
+        pyacc,
+        section,
+        character_to_symbol,
+        name_to_symbol,
+        precedence,
+        associativity,
+        tag
+      ):
+        if isinstance(self[0], PYACC.Char):
+          character = ord(self[0].get_text())
+          assert character != 0 # would conflict with YYEOF
+          if character in character_to_symbol:
+            symbol = character_to_symbol[character]
+            assert symbol >= 0
+          else:
+            symbol = len(pyacc.terminal_symbols)
+            character_to_symbol[character] = symbol
+            pyacc.terminal_symbols.append(
+              PYACC.Symbol(
+                character_set = [character, character + 1]
+              )
+            )
+        elif isinstance(self[0], PYACC.ID):
+          name = element.get_text(self[0], 0)
+          if name in name_to_symbol:
+            symbol = name_to_symbol[name]
+            assert symbol >= 0
+          else:
+            symbol = len(pyacc.terminal_symbols)
+            name_to_symbol[name] = symbol
+            character = 0x100 + symbol # fix this later
+            pyacc.terminal_symbols.append(
+              PYACC.Symbol(
+                name = name,
+                character_set = [character, character + 1]
+              )
+            )
+        else:
+          assert False
+        if precedence >= 0:
+          assert pyacc.terminal_symbols[symbol].precedence == -1
+          pyacc.terminal_symbols[symbol].precedence = precedence
+        if associativity >= 0:
+          assert pyacc.terminal_symbols[symbol].associativity == -1
+          pyacc.terminal_symbols[symbol].associativity = associativity
+        return tag
+
+    class TaggedSymbols(element.Element):
+      # GENERATE ELEMENT() BEGIN
+      def __init__(
+        self,
+        tag = 'PYACC_Section1Or2_TaggedSymbols',
+        attrib = {},
+        text = '',
+        children = []
+      ):
+        element.Element.__init__(
+          self,
+          tag,
+          attrib,
+          text,
+          children
+        )
+      def copy(self, factory = None):
+        result = element.Element.copy(
           self,
-          SymbolDef if factory is None else factory
+          TaggedSymbols if factory is None else factory
         )
         return result
       def __repr__(self):
         params = []
         self.repr_serialize(params)
-        return 'ast.PYACC.Section1Or2.SymbolDef({0:s})'.format(', '.join(params))
+        return 'ast.PYACC.Section1Or2.TaggedSymbols({0:s})'.format(', '.join(params))
       # GENERATE END
+      def post_process(
+        self,
+        pyacc,
+        section,
+        character_to_symbol,
+        name_to_symbol,
+        precedence,
+        associativity
+      ):
+        tag = None
+        for i in self:
+          tag = i.post_process(
+            pyacc,
+            section,
+            character_to_symbol,
+            name_to_symbol,
+            precedence,
+            associativity,
+            tag
+          )
 
     class Token(Item):
       # GENERATE ELEMENT() BEGIN
@@ -973,50 +1051,19 @@ class PYACC(element.Element):
         self,
         pyacc,
         section,
+        character_to_symbol,
         name_to_symbol
       ):
-        for i in self:
-          assert isinstance(i, PYACC.ID)
-          token_name = element.get_text(i, 0)
-          assert token_name not in name_to_symbol
-          name_to_symbol[token_name] = len(pyacc.terminal_symbols)
-          character = 0x100 + len(pyacc.terminal_symbols)
-          pyacc.terminal_symbols.append(
-            PYACC.Symbol(
-              name = token_name,
-              character_set = [character, character + 1]
-            )
-          )
-    class Type(Item):
-      class Symbols(element.Element):
-        # GENERATE ELEMENT() BEGIN
-        def __init__(
-          self,
-          tag = 'PYACC_Section1Or2_Type_Symbols',
-          attrib = {},
-          text = '',
-          children = []
-        ):
-          element.Element.__init__(
-            self,
-            tag,
-            attrib,
-            text,
-            children
-          )
-        def copy(self, factory = None):
-          result = element.Element.copy(
-            self,
-            Symbols if factory is None else factory
-          )
-          return result
-        def __repr__(self):
-          params = []
-          self.repr_serialize(params)
-          return 'ast.PYACC.Section1Or2.Type.Symbols({0:s})'.format(', '.join(params))
-        # GENERATE END
+        self[0].post_process(
+          pyacc,
+          section,
+          character_to_symbol,
+          name_to_symbol,
+          -1, # precedence
+          -1 # associativity
+        )
 
+    class Type(Item):
       # GENERATE ELEMENT() BEGIN
       def __init__(
         self,
@@ -1072,6 +1119,46 @@ class PYACC(element.Element):
         return 'ast.PYACC.Section1Or2.Union({0:s})'.format(', '.join(params))
       # GENERATE END
 
+    # GENERATE ELEMENT() BEGIN
+    def __init__(
+      self,
+      tag = 'PYACC_Section1Or2',
+      attrib = {},
+      text = '',
+      children = []
+    ):
+      PYACC.Section.__init__(
+        self,
+        tag,
+        attrib,
+        text,
+        children
+      )
+    def copy(self, factory = None):
+      result = PYACC.Section.copy(
+        self,
+        Section1Or2 if factory is None else factory
+      )
+      return result
+    def __repr__(self):
+      params = []
+      self.repr_serialize(params)
+      return 'ast.PYACC.Section1Or2({0:s})'.format(', '.join(params))
+    # GENERATE END
+    def post_process(
+      self,
+      pyacc,
+      character_to_symbol,
+      name_to_symbol
+    ):
+      for i in self:
+        i.post_process(
+          pyacc,
+          self,
+          character_to_symbol,
+          name_to_symbol
+        )
   class Section1(Section1Or2):
     class Define(Item):
       # GENERATE ELEMENT() BEGIN
@@ -1496,6 +1583,7 @@ class PYACC(element.Element):
         self,
         pyacc,
         section,
+        character_to_symbol,
         name_to_symbol
       ):
         assert isinstance(self[0], PYACC.Text)
@@ -1869,6 +1957,7 @@ class PYACC(element.Element):
           self,
           pyacc,
           lhs_symbol,
+          character_to_symbol,
           name_to_symbol
         ):
           production = grammar.Grammar.Production(
@@ -1879,7 +1968,14 @@ class PYACC(element.Element):
               if isinstance(self[i][0], PYACC.Char):
                 character = ord(self[i][0].get_text())
                 assert character != 0 # would conflict with YYEOF
-                pyacc.characters_used.add(character)
+                if character not in character_to_symbol:
+                  character_to_symbol[character] = len(pyacc.terminal_symbols)
+                  pyacc.terminal_symbols.append(
+                    PYACC.Symbol(
+                      character_set = [character, character + 1]
+                    )
+                  )
+                pyacc.characters_used.add(character) # remove this later
                 production.append(
                   grammar.Grammar.Production.Symbol(
                     terminal_set = [character, character + 1]
@@ -1940,6 +2036,7 @@ class PYACC(element.Element):
         self,
         pyacc,
         section,
+        character_to_symbol,
         name_to_symbol
       ):
         assert isinstance(self[0], PYACC.ID)
@@ -1950,6 +2047,7 @@ class PYACC(element.Element):
           lhs_symbol = ~i
         else:
           lhs_symbol = len(pyacc.nonterminal_symbols)
+          character_to_symbol,
           name_to_symbol[lhs_name] = ~lhs_symbol
           pyacc.nonterminal_symbols.append(
             PYACC.Symbol(name = lhs_name, character_set = [])
@@ -1958,6 +2056,7 @@ class PYACC(element.Element):
           i.post_process(
             pyacc,
             lhs_symbol,
+            character_to_symbol,
             name_to_symbol
           )
 
@@ -2018,6 +2117,7 @@ class PYACC(element.Element):
     def post_process(
       self,
       pyacc,
+      character_to_symbol,
       name_to_symbol
     ):
       pass
@@ -2079,7 +2179,7 @@ class PYACC(element.Element):
     # GENERATE END
 
 
-  # GENERATE ELEMENT(list(ref) prologue_text, set(int) characters_used, list(ref) terminal_symbols, list(ref) nonterminal_symbols, ref grammar, list(ref) actions_braced_code) BEGIN
+  # GENERATE ELEMENT(list(ref) prologue_text, set(int) characters_used, int precedences, list(ref) terminal_symbols, list(ref) nonterminal_symbols, ref grammar, list(ref) actions_braced_code) BEGIN
   def __init__(
     self,
     tag = 'PYACC',
@@ -2088,6 +2188,7 @@ class PYACC(element.Element):
     children = [],
     prologue_text = [],
     characters_used = set(),
+    precedences = -1,
     terminal_symbols = [],
     nonterminal_symbols = [],
     grammar = None,
@@ -2106,6 +2207,11 @@ class PYACC(element.Element):
     if isinstance(characters_used, str) else
       characters_used
     )
+    self.precedences = (
+      element.deserialize_int(precedences)
+    if isinstance(precedences, str) else
+      precedences
+    )
     self.terminal_symbols = terminal_symbols
     self.nonterminal_symbols = nonterminal_symbols
     self.grammar = grammar
@@ -2120,6 +2226,7 @@ class PYACC(element.Element):
       'characters_used',
       ' '.join([element.serialize_int(i) for i in sorted(self.characters_used)])
     )
+    self.set('precedences', element.serialize_int(self.precedences))
     self.set(
       'terminal_symbols',
       ' '.join([element.serialize_ref(i, ref_list) for i in self.terminal_symbols])
@@ -2145,6 +2252,7 @@ class PYACC(element.Element):
         for i in self.get('characters_used', '').split()
       ]
     )
+    self.precedences = element.deserialize_int(self.get('precedences', '-1'))
     self.terminal_symbols = [
       element.deserialize_ref(i, ref_list)
       for i in self.get('terminal_symbols', '').split()
@@ -2165,6 +2273,7 @@ class PYACC(element.Element):
     )
     result.prologue_text = self.prologue_text
     result.characters_used = self.characters_used
+    result.precedences = self.precedences
     result.terminal_symbols = self.terminal_symbols
     result.nonterminal_symbols = self.nonterminal_symbols
     result.grammar = self.grammar
@@ -2184,6 +2293,10 @@ class PYACC(element.Element):
           ', '.join([repr(i) for i in sorted(self.characters_used)])
         )
       )
+    if self.precedences != -1:
+      params.append(
+        'precedences = {0:s}'.format(repr(self.precedences))
+      )
     if len(self.terminal_symbols):
       params.append(
         'terminal_symbols = [{0:s}]'.format(
@@ -2215,6 +2328,7 @@ class PYACC(element.Element):
     # variables that will be serialized
     self.prologue_text = []
     self.characters_used = set()
+    self.precedences = 0
     self.terminal_symbols = [
       PYACC.Symbol(name = 'error', character_set = [0x100, 0x101]),
       PYACC.Symbol(name = '$undefined', character_set = [0x101, 0x102])
@@ -2234,6 +2348,7 @@ class PYACC(element.Element):
     self.actions_braced_code = []
 
     # variables that won't be serialized
+    character_to_symbol = {} # indexed by int, always >= 0 (terminal)
     # note: in name_to_symbol, >= 0 is terminal, < 0 is ~nonterminal
     # (don't bother storing the '$undefined', it can't be looked up)
     name_to_symbol = {'error': 0}
@@ -2242,6 +2357,7 @@ class PYACC(element.Element):
     for i in self:
       i.post_process(
         self,
+        character_to_symbol,
         name_to_symbol
       )
 
@@ -2281,23 +2397,20 @@ tag_to_class = {
   'PYACC_StackLocation': PYACC.StackLocation,
   'PYACC_StackReference': PYACC.StackReference,
   'PYACC_String': PYACC.String,
-  'PYACC_Tag': PYACC.Tag,
-  'PYACC_TagNone': PYACC.TagNone,
   'PYACC_Text': PYACC.Text,
   'PYACC_Section1Or2': PYACC.Section1Or2,
   'PYACC_Section1Or2_Code': PYACC.Section1Or2.Code,
   'PYACC_Section1Or2_CodeProps': PYACC.Section1Or2.CodeProps,
-  'PYACC_Section1Or2_CodeProps_GenericSymList': PYACC.Section1Or2.CodeProps.GenericSymList,
   'PYACC_Section1Or2_DefaultPrec': PYACC.Section1Or2.DefaultPrec,
   'PYACC_Section1Or2_NTerm': PYACC.Section1Or2.NTerm,
   'PYACC_Section1Or2_Precedence': PYACC.Section1Or2.Precedence,
-  'PYACC_Section1Or2_Precedence_Symbols': PYACC.Section1Or2.Precedence.Symbols,
-  'PYACC_Section1Or2_Precedence_Symbols_Symbol': PYACC.Section1Or2.Precedence.Symbols.Symbol,
   'PYACC_Section1Or2_Start': PYACC.Section1Or2.Start,
-  'PYACC_Section1Or2_SymbolDef': PYACC.Section1Or2.SymbolDef,
+  'PYACC_Section1Or2_TagOrSymbol': PYACC.Section1Or2.TagOrSymbol,
+  'PYACC_Section1Or2_Tag': PYACC.Section1Or2.Tag,
+  'PYACC_Section1Or2_Symbol': PYACC.Section1Or2.Symbol,
+  'PYACC_Section1Or2_TaggedSymbols': PYACC.Section1Or2.TaggedSymbols,
   'PYACC_Section1Or2_Token': PYACC.Section1Or2.Token,
   'PYACC_Section1Or2_Type': PYACC.Section1Or2.Type,
-  'PYACC_Section1Or2_Type_Symbols': PYACC.Section1Or2.Type.Symbols,
   'PYACC_Section1Or2_Union': PYACC.Section1Or2.Union,
   'PYACC_Section1': PYACC.Section1,
   'PYACC_Section1_Define': PYACC.Section1.Define,
index c8c93d4..7b56710 100644 (file)
@@ -274,12 +274,13 @@ def generate(pyacc, skel_file, out_file):
   )
   translate_terminals[1:0x100] = 2 # '$undefined'
   for i in pyacc.terminal_symbols:
-    for j in range(0, len(i.character_set), 2):
-      translate_terminals[
-        i.character_set[j]:
-        i.character_set[j + 1]
-      ] = n_terminals
-    n_terminals += 1
+    if len(i.name): # fix this later
+      for j in range(0, len(i.character_set), 2):
+        translate_terminals[
+          i.character_set[j]:
+          i.character_set[j + 1]
+        ] = n_terminals
+      n_terminals += 1
   for i in sorted(pyacc.characters_used):
     translate_terminals[i] = n_terminals
     n_terminals += 1
@@ -333,6 +334,7 @@ def generate(pyacc, skel_file, out_file):
                     0x100 + i
                   )
                   for i in range(2, len(pyacc.terminal_symbols))
+                  if len(pyacc.terminal_symbols[i].name) # fix this later
                 ]
               )
             )
@@ -349,6 +351,7 @@ def generate(pyacc, skel_file, out_file):
                     0x100 + i
                   )
                   for i in range(2, len(pyacc.terminal_symbols))
+                  if len(pyacc.terminal_symbols[i].name) # fix this later
                 ]
               )
             )