Remove PYACC.Section base class and make PYACC.Section1Or2 the direct parent
authorNick Downing <downing.nick@gmail.com>
Fri, 20 Jul 2018 04:33:37 +0000 (14:33 +1000)
committerNick Downing <downing.nick@gmail.com>
Fri, 20 Jul 2018 04:33:37 +0000 (14:33 +1000)
ast.py

diff --git a/ast.py b/ast.py
index 7e494cf..f2e9919 100644 (file)
--- a/ast.py
+++ b/ast.py
@@ -722,653 +722,7 @@ class PYACC(element.Element):
         _lr1.precedences[2].append(len(_lr1.productions))
         _lr1.precedences[3].append(precedence)
 
-  class Section(element.Element):
-    # GENERATE ELEMENT() BEGIN
-    def __init__(
-      self,
-      tag = 'PYACC_Section',
-      attrib = {},
-      text = '',
-      children = []
-    ):
-      element.Element.__init__(
-        self,
-        tag,
-        attrib,
-        text,
-        children
-      )
-    def copy(self, factory = None):
-      result = element.Element.copy(
-        self,
-        Section if factory is None else factory
-      )
-      return result
-    def __repr__(self):
-      params = []
-      self.repr_serialize(params)
-      return 'ast.PYACC.Section({0:s})'.format(', '.join(params))
-    # GENERATE END
-    def post_process(
-      self,
-      pyacc,
-      character_to_symbol,
-      name_to_symbol
-    ):
-      raise NotImplementedException
-
-  class String(element.Element):
-    # GENERATE ELEMENT() BEGIN
-    def __init__(
-      self,
-      tag = 'PYACC_String',
-      attrib = {},
-      text = '',
-      children = []
-    ):
-      element.Element.__init__(
-        self,
-        tag,
-        attrib,
-        text,
-        children
-      )
-    def copy(self, factory = None):
-      result = element.Element.copy(
-        self,
-        String if factory is None else factory
-      )
-      return result
-    def __repr__(self):
-      params = []
-      self.repr_serialize(params)
-      return 'ast.PYACC.String({0:s})'.format(', '.join(params))
-    # GENERATE END
-
-  class TagOrSymbolRef(element.Element):
-    # GENERATE ELEMENT() BEGIN
-    def __init__(
-      self,
-      tag = 'PYACC_TagOrSymbolRef',
-      attrib = {},
-      text = '',
-      children = []
-    ):
-      element.Element.__init__(
-        self,
-        tag,
-        attrib,
-        text,
-        children
-      )
-    def copy(self, factory = None):
-      result = element.Element.copy(
-        self,
-        TagOrSymbolRef if factory is None else factory
-      )
-      return result
-    def __repr__(self):
-      params = []
-      self.repr_serialize(params)
-      return 'ast.PYACC.TagOrSymbolRef({0:s})'.format(', '.join(params))
-    # GENERATE END
-    def post_process(
-      self,
-      pyacc,
-      section,
-      character_to_symbol,
-      name_to_symbol,
-      precedence,
-      tag
-    ):
-      raise NotImplementedException
-
-  class Tag(TagOrSymbolRef):
-    # GENERATE ELEMENT(int type) BEGIN
-    def __init__(
-      self,
-      tag = 'PYACC_Tag',
-      attrib = {},
-      text = '',
-      children = [],
-      type = -1
-    ):
-      PYACC.TagOrSymbolRef.__init__(
-        self,
-        tag,
-        attrib,
-        text,
-        children
-      )
-      self.type = (
-        element.deserialize_int(type)
-      if isinstance(type, str) else
-        type
-      )
-    def serialize(self, ref_list):
-      PYACC.TagOrSymbolRef.serialize(self, ref_list)
-      self.set('type', element.serialize_int(self.type))
-    def deserialize(self, ref_list):
-      PYACC.TagOrSymbolRef.deserialize(self, ref_list)
-      self.type = element.deserialize_int(self.get('type', '-1'))
-    def copy(self, factory = None):
-      result = PYACC.TagOrSymbolRef.copy(
-        self,
-        Tag if factory is None else factory
-      )
-      result.type = self.type
-      return result
-    def repr_serialize(self, params):
-      PYACC.TagOrSymbolRef.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.Tag({0:s})'.format(', '.join(params))
-    # GENERATE END
-    def post_process(
-      self,
-      pyacc,
-      section,
-      character_to_symbol,
-      name_to_symbol,
-      precedence,
-      tag
-    ):
-      return self
-
-  class TerminalRef(TagOrSymbolRef):
-    # GENERATE ELEMENT(int terminal, int user_token) BEGIN
-    def __init__(
-      self,
-      tag = 'PYACC_TerminalRef',
-      attrib = {},
-      text = '',
-      children = [],
-      terminal = -1,
-      user_token = -1
-    ):
-      PYACC.TagOrSymbolRef.__init__(
-        self,
-        tag,
-        attrib,
-        text,
-        children
-      )
-      self.terminal = (
-        element.deserialize_int(terminal)
-      if isinstance(terminal, str) else
-        terminal
-      )
-      self.user_token = (
-        element.deserialize_int(user_token)
-      if isinstance(user_token, str) else
-        user_token
-      )
-    def serialize(self, ref_list):
-      PYACC.TagOrSymbolRef.serialize(self, ref_list)
-      self.set('terminal', element.serialize_int(self.terminal))
-      self.set('user_token', element.serialize_int(self.user_token))
-    def deserialize(self, ref_list):
-      PYACC.TagOrSymbolRef.deserialize(self, ref_list)
-      self.terminal = element.deserialize_int(self.get('terminal', '-1'))
-      self.user_token = element.deserialize_int(self.get('user_token', '-1'))
-    def copy(self, factory = None):
-      result = PYACC.TagOrSymbolRef.copy(
-        self,
-        TerminalRef if factory is None else factory
-      )
-      result.terminal = self.terminal
-      result.user_token = self.user_token
-      return result
-    def repr_serialize(self, params):
-      PYACC.TagOrSymbolRef.repr_serialize(self, params)
-      if self.terminal != -1:
-        params.append(
-          'terminal = {0:s}'.format(repr(self.terminal))
-        )
-      if self.user_token != -1:
-        params.append(
-          'user_token = {0:s}'.format(repr(self.user_token))
-        )
-    def __repr__(self):
-      params = []
-      self.repr_serialize(params)
-      return 'ast.PYACC.TerminalRef({0:s})'.format(', '.join(params))
-    # GENERATE END
-    def post_process(
-      self,
-      pyacc,
-      section,
-      character_to_symbol,
-      name_to_symbol,
-      precedence,
-      tag
-    ):
-      if isinstance(self[0], PYACC.Char):
-        character = ord(self[0][0].get_text())
-        assert character != 0 # would conflict with YYEOF
-        if character in character_to_symbol:
-          self.terminal = character_to_symbol[character]
-          assert self.terminal >= 0
-        else:
-          self.terminal = len(pyacc.terminals)
-          character_to_symbol[character] = self.terminal
-          pyacc.terminals.append(
-            PYACC.Terminal(character_set = [character, character + 1])
-          )
-      elif isinstance(self[0], PYACC.ID):
-        name = self[0].get_text()
-        if name in name_to_symbol:
-          self.terminal = name_to_symbol[name]
-          assert self.terminal >= 0
-        else:
-          self.terminal = len(pyacc.terminals)
-          name_to_symbol[name] = self.terminal
-          pyacc.terminals.append(
-            PYACC.Terminal(name = name)
-          )
-      else:
-        assert False
-      if self.user_token != -1:
-        assert len(pyacc.terminals[self.terminal].character_set) == 0
-        pyacc.terminals[self.terminal].character_set = (
-          [self.user_token, self.user_token + 1]
-        )
-      if precedence != -1:
-        assert pyacc.terminals[self.terminal].precedence == -1
-        pyacc.terminals[self.terminal].precedence = precedence
-      return tag
-
-  class NonterminalRef(TagOrSymbolRef):
-    # GENERATE ELEMENT(int nonterminal, int user_token) BEGIN
-    def __init__(
-      self,
-      tag = 'PYACC_NonterminalRef',
-      attrib = {},
-      text = '',
-      children = [],
-      nonterminal = -1,
-      user_token = -1
-    ):
-      PYACC.TagOrSymbolRef.__init__(
-        self,
-        tag,
-        attrib,
-        text,
-        children
-      )
-      self.nonterminal = (
-        element.deserialize_int(nonterminal)
-      if isinstance(nonterminal, str) else
-        nonterminal
-      )
-      self.user_token = (
-        element.deserialize_int(user_token)
-      if isinstance(user_token, str) else
-        user_token
-      )
-    def serialize(self, ref_list):
-      PYACC.TagOrSymbolRef.serialize(self, ref_list)
-      self.set('nonterminal', element.serialize_int(self.nonterminal))
-      self.set('user_token', element.serialize_int(self.user_token))
-    def deserialize(self, ref_list):
-      PYACC.TagOrSymbolRef.deserialize(self, ref_list)
-      self.nonterminal = element.deserialize_int(self.get('nonterminal', '-1'))
-      self.user_token = element.deserialize_int(self.get('user_token', '-1'))
-    def copy(self, factory = None):
-      result = PYACC.TagOrSymbolRef.copy(
-        self,
-        NonterminalRef if factory is None else factory
-      )
-      result.nonterminal = self.nonterminal
-      result.user_token = self.user_token
-      return result
-    def repr_serialize(self, params):
-      PYACC.TagOrSymbolRef.repr_serialize(self, params)
-      if self.nonterminal != -1:
-        params.append(
-          'nonterminal = {0:s}'.format(repr(self.nonterminal))
-        )
-      if self.user_token != -1:
-        params.append(
-          'user_token = {0:s}'.format(repr(self.user_token))
-        )
-    def __repr__(self):
-      params = []
-      self.repr_serialize(params)
-      return 'ast.PYACC.NonterminalRef({0:s})'.format(', '.join(params))
-    # GENERATE END
-    def post_process(
-      self,
-      pyacc,
-      section,
-      character_to_symbol,
-      name_to_symbol,
-      precedence,
-      tag
-    ):
-      if isinstance(self[0], PYACC.ID):
-        name = self[0].get_text()
-        if name in name_to_symbol:
-          i = name_to_symbol[name]
-          assert i < 0
-          self.nonterminal = ~i
-        else:
-          self.nonterminal = len(pyacc.nonterminals)
-          name_to_symbol[name] = ~self.nonterminal
-          pyacc.nonterminals.append(
-            PYACC.Nonterminal(name = name, character_set = [])
-          )
-      else:
-        assert False
-      assert self.user_token == -1
-      assert precedence == -1
-      return tag
-
-  class Text(element.Element):
-    class Escape(element.Element):
-      # GENERATE ELEMENT(int character) BEGIN
-      def __init__(
-        self,
-        tag = 'PYACC_Text_Escape',
-        attrib = {},
-        text = '',
-        children = [],
-        character = -1
-      ):
-        element.Element.__init__(
-          self,
-          tag,
-          attrib,
-          text,
-          children
-        )
-        self.character = (
-          element.deserialize_int(character)
-        if isinstance(character, str) else
-          character
-        )
-      def serialize(self, ref_list):
-        element.Element.serialize(self, ref_list)
-        self.set('character', element.serialize_int(self.character))
-      def deserialize(self, ref_list):
-        element.Element.deserialize(self, ref_list)
-        self.character = element.deserialize_int(self.get('character', '-1'))
-      def copy(self, factory = None):
-        result = element.Element.copy(
-          self,
-          Escape if factory is None else factory
-        )
-        result.character = self.character
-        return result
-      def repr_serialize(self, params):
-        element.Element.repr_serialize(self, params)
-        if self.character != -1:
-          params.append(
-            'character = {0:s}'.format(repr(self.character))
-          )
-      def __repr__(self):
-        params = []
-        self.repr_serialize(params)
-        return 'ast.PYACC.Text.Escape({0:s})'.format(', '.join(params))
-      # GENERATE END
-
-    class StackLocation(element.Element):
-      # GENERATE ELEMENT(int index) BEGIN
-      def __init__(
-        self,
-        tag = 'PYACC_Text_StackLocation',
-        attrib = {},
-        text = '',
-        children = [],
-        index = -1
-      ):
-        element.Element.__init__(
-          self,
-          tag,
-          attrib,
-          text,
-          children
-        )
-        self.index = (
-          element.deserialize_int(index)
-        if isinstance(index, str) else
-          index
-        )
-      def serialize(self, ref_list):
-        element.Element.serialize(self, ref_list)
-        self.set('index', element.serialize_int(self.index))
-      def deserialize(self, ref_list):
-        element.Element.deserialize(self, ref_list)
-        self.index = element.deserialize_int(self.get('index', '-1'))
-      def copy(self, factory = None):
-        result = element.Element.copy(
-          self,
-          StackLocation if factory is None else factory
-        )
-        result.index = self.index
-        return result
-      def repr_serialize(self, params):
-        element.Element.repr_serialize(self, params)
-        if self.index != -1:
-          params.append(
-            'index = {0:s}'.format(repr(self.index))
-          )
-      def __repr__(self):
-        params = []
-        self.repr_serialize(params)
-        return 'ast.PYACC.Text.StackLocation({0:s})'.format(', '.join(params))
-      # GENERATE END
-
-    class StackReference(element.Element):
-      # GENERATE ELEMENT(int index) BEGIN
-      def __init__(
-        self,
-        tag = 'PYACC_Text_StackReference',
-        attrib = {},
-        text = '',
-        children = [],
-        index = -1
-      ):
-        element.Element.__init__(
-          self,
-          tag,
-          attrib,
-          text,
-          children
-        )
-        self.index = (
-          element.deserialize_int(index)
-        if isinstance(index, str) else
-          index
-        )
-      def serialize(self, ref_list):
-        element.Element.serialize(self, ref_list)
-        self.set('index', element.serialize_int(self.index))
-      def deserialize(self, ref_list):
-        element.Element.deserialize(self, ref_list)
-        self.index = element.deserialize_int(self.get('index', '-1'))
-      def copy(self, factory = None):
-        result = element.Element.copy(
-          self,
-          StackReference if factory is None else factory
-        )
-        result.index = self.index
-        return result
-      def repr_serialize(self, params):
-        element.Element.repr_serialize(self, params)
-        if self.index != -1:
-          params.append(
-            'index = {0:s}'.format(repr(self.index))
-          )
-      def __repr__(self):
-        params = []
-        self.repr_serialize(params)
-        return 'ast.PYACC.Text.StackReference({0:s})'.format(', '.join(params))
-      # GENERATE END
-
-    class ValueLocation(element.Element):
-      # GENERATE ELEMENT() BEGIN
-      def __init__(
-        self,
-        tag = 'PYACC_Text_ValueLocation',
-        attrib = {},
-        text = '',
-        children = []
-      ):
-        element.Element.__init__(
-          self,
-          tag,
-          attrib,
-          text,
-          children
-        )
-      def copy(self, factory = None):
-        result = element.Element.copy(
-          self,
-          ValueLocation if factory is None else factory
-        )
-        return result
-      def __repr__(self):
-        params = []
-        self.repr_serialize(params)
-        return 'ast.PYACC.Text.ValueLocation({0:s})'.format(', '.join(params))
-      # GENERATE END
-
-    class ValueReference(element.Element):
-      # GENERATE ELEMENT() BEGIN
-      def __init__(
-        self,
-        tag = 'PYACC_Text_ValueReference',
-        attrib = {},
-        text = '',
-        children = []
-      ):
-        element.Element.__init__(
-          self,
-          tag,
-          attrib,
-          text,
-          children
-        )
-      def copy(self, factory = None):
-        result = element.Element.copy(
-          self,
-          ValueReference if factory is None else factory
-        )
-        return result
-      def __repr__(self):
-        params = []
-        self.repr_serialize(params)
-        return 'ast.PYACC.Text.ValueReference({0:s})'.format(', '.join(params))
-      # GENERATE END
-
-    # GENERATE ELEMENT() BEGIN
-    def __init__(
-      self,
-      tag = 'PYACC_Text',
-      attrib = {},
-      text = '',
-      children = []
-    ):
-      element.Element.__init__(
-        self,
-        tag,
-        attrib,
-        text,
-        children
-      )
-    def copy(self, factory = None):
-      result = element.Element.copy(
-        self,
-        Text if factory is None else factory
-      )
-      return result
-    def __repr__(self):
-      params = []
-      self.repr_serialize(params)
-      return 'ast.PYACC.Text({0:s})'.format(', '.join(params))
-    # GENERATE END
-    def get_text(self, len_production = 0):
-      return ''.join(
-        [
-          j
-          for i in range(len(self))
-          for j in [
-            element.get_text(self, i),
-            (
-              '(yyvsp[{0:d}])'.format(self[i].index - len_production)
-            if isinstance(self[i], PYACC.Text.StackReference) else
-              '(yyval)'
-            if isinstance(self[i], PYACC.Text.ValueReference) else
-              chr(self[i].character)
-            )
-          ]
-        ] +
-        [element.get_text(self, len(self))]
-      )
-
-  class BracedCode(Text):
-    # GENERATE ELEMENT() BEGIN
-    def __init__(
-      self,
-      tag = 'PYACC_BracedCode',
-      attrib = {},
-      text = '',
-      children = []
-    ):
-      PYACC.Text.__init__(
-        self,
-        tag,
-        attrib,
-        text,
-        children
-      )
-    def copy(self, factory = None):
-      result = PYACC.Text.copy(
-        self,
-        BracedCode if factory is None else factory
-      )
-      return result
-    def __repr__(self):
-      params = []
-      self.repr_serialize(params)
-      return 'ast.PYACC.BracedCode({0:s})'.format(', '.join(params))
-    # GENERATE END
-
-  class ID(Text):
-    # GENERATE ELEMENT() BEGIN
-    def __init__(
-      self,
-      tag = 'PYACC_ID',
-      attrib = {},
-      text = '',
-      children = []
-    ):
-      PYACC.Text.__init__(
-        self,
-        tag,
-        attrib,
-        text,
-        children
-      )
-    def copy(self, factory = None):
-      result = PYACC.Text.copy(
-        self,
-        ID if factory is None else factory
-      )
-      return result
-    def __repr__(self):
-      params = []
-      self.repr_serialize(params)
-      return 'ast.PYACC.ID({0:s})'.format(', '.join(params))
-    # GENERATE END
-
-  class Section1Or2(Section):
+  class Section1Or2(element.Element):
     class Code(Item):
       # GENERATE ELEMENT() BEGIN
       def __init__(
@@ -1738,7 +1092,7 @@ class PYACC(element.Element):
       text = '',
       children = []
     ):
-      PYACC.Section.__init__(
+      element.Element.__init__(
         self,
         tag,
         attrib,
@@ -1746,7 +1100,7 @@ class PYACC(element.Element):
         children
       )
     def copy(self, factory = None):
-      result = PYACC.Section.copy(
+      result = element.Element.copy(
         self,
         Section1Or2 if factory is None else factory
       )
@@ -1967,11 +1321,244 @@ class PYACC(element.Element):
         return 'ast.PYACC.Section1.GLRParser({0:s})'.format(', '.join(params))
       # GENERATE END
 
-    class InitialAction(Item):
+    class InitialAction(Item):
+      # GENERATE ELEMENT() BEGIN
+      def __init__(
+        self,
+        tag = 'PYACC_Section1_InitialAction',
+        attrib = {},
+        text = '',
+        children = []
+      ):
+        Item.__init__(
+          self,
+          tag,
+          attrib,
+          text,
+          children
+        )
+      def copy(self, factory = None):
+        result = Item.copy(
+          self,
+          InitialAction if factory is None else factory
+        )
+        return result
+      def __repr__(self):
+        params = []
+        self.repr_serialize(params)
+        return 'ast.PYACC.Section1.InitialAction({0:s})'.format(', '.join(params))
+      # GENERATE END
+
+    class Language(Item):
+      # GENERATE ELEMENT() BEGIN
+      def __init__(
+        self,
+        tag = 'PYACC_Section1_Language',
+        attrib = {},
+        text = '',
+        children = []
+      ):
+        Item.__init__(
+          self,
+          tag,
+          attrib,
+          text,
+          children
+        )
+      def copy(self, factory = None):
+        result = Item.copy(
+          self,
+          Language if factory is None else factory
+        )
+        return result
+      def __repr__(self):
+        params = []
+        self.repr_serialize(params)
+        return 'ast.PYACC.Section1.Language({0:s})'.format(', '.join(params))
+      # GENERATE END
+
+    class Lines(Item):
+      # GENERATE ELEMENT() BEGIN
+      def __init__(
+        self,
+        tag = 'PYACC_Section1_Lines',
+        attrib = {},
+        text = '',
+        children = []
+      ):
+        Item.__init__(
+          self,
+          tag,
+          attrib,
+          text,
+          children
+        )
+      def copy(self, factory = None):
+        result = Item.copy(
+          self,
+          Lines if factory is None else factory
+        )
+        return result
+      def __repr__(self):
+        params = []
+        self.repr_serialize(params)
+        return 'ast.PYACC.Section1.Lines({0:s})'.format(', '.join(params))
+      # GENERATE END
+
+    class NamePrefix(Item):
+      # GENERATE ELEMENT() BEGIN
+      def __init__(
+        self,
+        tag = 'PYACC_Section1_NamePrefix',
+        attrib = {},
+        text = '',
+        children = []
+      ):
+        Item.__init__(
+          self,
+          tag,
+          attrib,
+          text,
+          children
+        )
+      def copy(self, factory = None):
+        result = Item.copy(
+          self,
+          NamePrefix if factory is None else factory
+        )
+        return result
+      def __repr__(self):
+        params = []
+        self.repr_serialize(params)
+        return 'ast.PYACC.Section1.NamePrefix({0:s})'.format(', '.join(params))
+      # GENERATE END
+
+    class NonDeterministicParser(Item):
+      # GENERATE ELEMENT() BEGIN
+      def __init__(
+        self,
+        tag = 'PYACC_Section1_NonDeterministicParser',
+        attrib = {},
+        text = '',
+        children = []
+      ):
+        Item.__init__(
+          self,
+          tag,
+          attrib,
+          text,
+          children
+        )
+      def copy(self, factory = None):
+        result = Item.copy(
+          self,
+          NonDeterministicParser if factory is None else factory
+        )
+        return result
+      def __repr__(self):
+        params = []
+        self.repr_serialize(params)
+        return 'ast.PYACC.Section1.NonDeterministicParser({0:s})'.format(', '.join(params))
+      # GENERATE END
+
+    class Output(Item):
+      # GENERATE ELEMENT() BEGIN
+      def __init__(
+        self,
+        tag = 'PYACC_Section1_Output',
+        attrib = {},
+        text = '',
+        children = []
+      ):
+        Item.__init__(
+          self,
+          tag,
+          attrib,
+          text,
+          children
+        )
+      def copy(self, factory = None):
+        result = Item.copy(
+          self,
+          Output if factory is None else factory
+        )
+        return result
+      def __repr__(self):
+        params = []
+        self.repr_serialize(params)
+        return 'ast.PYACC.Section1.Output({0:s})'.format(', '.join(params))
+      # GENERATE END
+
+    class Param(Item):
+      # GENERATE ELEMENT() BEGIN
+      def __init__(
+        self,
+        tag = 'PYACC_Section1_Param',
+        attrib = {},
+        text = '',
+        children = []
+      ):
+        Item.__init__(
+          self,
+          tag,
+          attrib,
+          text,
+          children
+        )
+      def copy(self, factory = None):
+        result = Item.copy(
+          self,
+          Param if factory is None else factory
+        )
+        return result
+      def __repr__(self):
+        params = []
+        self.repr_serialize(params)
+        return 'ast.PYACC.Section1.Param({0:s})'.format(', '.join(params))
+      # GENERATE END
+
+    class Prologue(Item):
+      # GENERATE ELEMENT() BEGIN
+      def __init__(
+        self,
+        tag = 'PYACC_Section1_Prologue',
+        attrib = {},
+        text = '',
+        children = []
+      ):
+        Item.__init__(
+          self,
+          tag,
+          attrib,
+          text,
+          children
+        )
+      def copy(self, factory = None):
+        result = Item.copy(
+          self,
+          Prologue if factory is None else factory
+        )
+        return result
+      def __repr__(self):
+        params = []
+        self.repr_serialize(params)
+        return 'ast.PYACC.Section1.Prologue({0:s})'.format(', '.join(params))
+      # GENERATE END
+      def post_process(
+        self,
+        pyacc,
+        section,
+        character_to_symbol,
+        name_to_symbol
+      ):
+        assert isinstance(self[0], PYACC.Text)
+        pyacc.prologue_text.append(self[0])
+
+    class Require(Item):
       # GENERATE ELEMENT() BEGIN
       def __init__(
         self,
-        tag = 'PYACC_Section1_InitialAction',
+        tag = 'PYACC_Section1_Require',
         attrib = {},
         text = '',
         children = []
@@ -1986,20 +1573,20 @@ class PYACC(element.Element):
       def copy(self, factory = None):
         result = Item.copy(
           self,
-          InitialAction if factory is None else factory
+          Require if factory is None else factory
         )
         return result
       def __repr__(self):
         params = []
         self.repr_serialize(params)
-        return 'ast.PYACC.Section1.InitialAction({0:s})'.format(', '.join(params))
+        return 'ast.PYACC.Section1.Require({0:s})'.format(', '.join(params))
       # GENERATE END
 
-    class Language(Item):
+    class Skeleton(Item):
       # GENERATE ELEMENT() BEGIN
       def __init__(
         self,
-        tag = 'PYACC_Section1_Language',
+        tag = 'PYACC_Section1_Skeleton',
         attrib = {},
         text = '',
         children = []
@@ -2014,20 +1601,20 @@ class PYACC(element.Element):
       def copy(self, factory = None):
         result = Item.copy(
           self,
-          Language if factory is None else factory
+          Skeleton if factory is None else factory
         )
         return result
       def __repr__(self):
         params = []
         self.repr_serialize(params)
-        return 'ast.PYACC.Section1.Language({0:s})'.format(', '.join(params))
+        return 'ast.PYACC.Section1.Skeleton({0:s})'.format(', '.join(params))
       # GENERATE END
 
-    class Lines(Item):
+    class TokenTable(Item):
       # GENERATE ELEMENT() BEGIN
       def __init__(
         self,
-        tag = 'PYACC_Section1_Lines',
+        tag = 'PYACC_Section1_TokenTable',
         attrib = {},
         text = '',
         children = []
@@ -2042,20 +1629,20 @@ class PYACC(element.Element):
       def copy(self, factory = None):
         result = Item.copy(
           self,
-          Lines if factory is None else factory
+          TokenTable if factory is None else factory
         )
         return result
       def __repr__(self):
         params = []
         self.repr_serialize(params)
-        return 'ast.PYACC.Section1.Lines({0:s})'.format(', '.join(params))
+        return 'ast.PYACC.Section1.TokenTable({0:s})'.format(', '.join(params))
       # GENERATE END
 
-    class NamePrefix(Item):
+    class Verbose(Item):
       # GENERATE ELEMENT() BEGIN
       def __init__(
         self,
-        tag = 'PYACC_Section1_NamePrefix',
+        tag = 'PYACC_Section1_Verbose',
         attrib = {},
         text = '',
         children = []
@@ -2070,20 +1657,20 @@ class PYACC(element.Element):
       def copy(self, factory = None):
         result = Item.copy(
           self,
-          NamePrefix if factory is None else factory
+          Verbose if factory is None else factory
         )
         return result
       def __repr__(self):
         params = []
         self.repr_serialize(params)
-        return 'ast.PYACC.Section1.NamePrefix({0:s})'.format(', '.join(params))
+        return 'ast.PYACC.Section1.Verbose({0:s})'.format(', '.join(params))
       # GENERATE END
 
-    class NonDeterministicParser(Item):
+    class YACC(Item):
       # GENERATE ELEMENT() BEGIN
       def __init__(
         self,
-        tag = 'PYACC_Section1_NonDeterministicParser',
+        tag = 'PYACC_Section1_YACC',
         attrib = {},
         text = '',
         children = []
@@ -2098,20 +1685,48 @@ class PYACC(element.Element):
       def copy(self, factory = None):
         result = Item.copy(
           self,
-          NonDeterministicParser if factory is None else factory
+          YACC if factory is None else factory
         )
         return result
       def __repr__(self):
         params = []
         self.repr_serialize(params)
-        return 'ast.PYACC.Section1.NonDeterministicParser({0:s})'.format(', '.join(params))
+        return 'ast.PYACC.Section1.YACC({0:s})'.format(', '.join(params))
       # GENERATE END
 
-    class Output(Item):
+    # GENERATE ELEMENT() BEGIN
+    def __init__(
+      self,
+      tag = 'PYACC_Section1',
+      attrib = {},
+      text = '',
+      children = []
+    ):
+      PYACC.Section1Or2.__init__(
+        self,
+        tag,
+        attrib,
+        text,
+        children
+      )
+    def copy(self, factory = None):
+      result = PYACC.Section1Or2.copy(
+        self,
+        Section1 if factory is None else factory
+      )
+      return result
+    def __repr__(self):
+      params = []
+      self.repr_serialize(params)
+      return 'ast.PYACC.Section1({0:s})'.format(', '.join(params))
+    # GENERATE END
+
+  class Section2(Section1Or2):
+    class Rules(Item):
       # GENERATE ELEMENT() BEGIN
       def __init__(
         self,
-        tag = 'PYACC_Section1_Output',
+        tag = 'PYACC_Section2_Rules',
         attrib = {},
         text = '',
         children = []
@@ -2126,174 +1741,531 @@ class PYACC(element.Element):
       def copy(self, factory = None):
         result = Item.copy(
           self,
-          Output if factory is None else factory
+          Rules if factory is None else factory
         )
         return result
       def __repr__(self):
         params = []
         self.repr_serialize(params)
-        return 'ast.PYACC.Section1.Output({0:s})'.format(', '.join(params))
+        return 'ast.PYACC.Section2.Rules({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,
+          -1, # precedence
+          None # tag
+        )
+        if pyacc.first_nonterminal == -1:
+          pyacc.first_nonterminal = self[0].nonterminal
+        for i in self[1:]:
+          i.post_process(
+            pyacc,
+            section,
+            self[0].nonterminal,
+            character_to_symbol,
+            name_to_symbol
+          )
+
+    # GENERATE ELEMENT() BEGIN
+    def __init__(
+      self,
+      tag = 'PYACC_Section2',
+      attrib = {},
+      text = '',
+      children = []
+    ):
+      PYACC.Section1Or2.__init__(
+        self,
+        tag,
+        attrib,
+        text,
+        children
+      )
+    def copy(self, factory = None):
+      result = PYACC.Section1Or2.copy(
+        self,
+        Section2 if factory is None else factory
+      )
+      return result
+    def __repr__(self):
+      params = []
+      self.repr_serialize(params)
+      return 'ast.PYACC.Section2({0:s})'.format(', '.join(params))
+    # GENERATE END
+
+  class String(element.Element):
+    # GENERATE ELEMENT() BEGIN
+    def __init__(
+      self,
+      tag = 'PYACC_String',
+      attrib = {},
+      text = '',
+      children = []
+    ):
+      element.Element.__init__(
+        self,
+        tag,
+        attrib,
+        text,
+        children
+      )
+    def copy(self, factory = None):
+      result = element.Element.copy(
+        self,
+        String if factory is None else factory
+      )
+      return result
+    def __repr__(self):
+      params = []
+      self.repr_serialize(params)
+      return 'ast.PYACC.String({0:s})'.format(', '.join(params))
+    # GENERATE END
+
+  class TagOrSymbolRef(element.Element):
+    # GENERATE ELEMENT() BEGIN
+    def __init__(
+      self,
+      tag = 'PYACC_TagOrSymbolRef',
+      attrib = {},
+      text = '',
+      children = []
+    ):
+      element.Element.__init__(
+        self,
+        tag,
+        attrib,
+        text,
+        children
+      )
+    def copy(self, factory = None):
+      result = element.Element.copy(
+        self,
+        TagOrSymbolRef if factory is None else factory
+      )
+      return result
+    def __repr__(self):
+      params = []
+      self.repr_serialize(params)
+      return 'ast.PYACC.TagOrSymbolRef({0:s})'.format(', '.join(params))
+    # GENERATE END
+    def post_process(
+      self,
+      pyacc,
+      section,
+      character_to_symbol,
+      name_to_symbol,
+      precedence,
+      tag
+    ):
+      raise NotImplementedException
+
+  class Tag(TagOrSymbolRef):
+    # GENERATE ELEMENT(int type) BEGIN
+    def __init__(
+      self,
+      tag = 'PYACC_Tag',
+      attrib = {},
+      text = '',
+      children = [],
+      type = -1
+    ):
+      PYACC.TagOrSymbolRef.__init__(
+        self,
+        tag,
+        attrib,
+        text,
+        children
+      )
+      self.type = (
+        element.deserialize_int(type)
+      if isinstance(type, str) else
+        type
+      )
+    def serialize(self, ref_list):
+      PYACC.TagOrSymbolRef.serialize(self, ref_list)
+      self.set('type', element.serialize_int(self.type))
+    def deserialize(self, ref_list):
+      PYACC.TagOrSymbolRef.deserialize(self, ref_list)
+      self.type = element.deserialize_int(self.get('type', '-1'))
+    def copy(self, factory = None):
+      result = PYACC.TagOrSymbolRef.copy(
+        self,
+        Tag if factory is None else factory
+      )
+      result.type = self.type
+      return result
+    def repr_serialize(self, params):
+      PYACC.TagOrSymbolRef.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.Tag({0:s})'.format(', '.join(params))
+    # GENERATE END
+    def post_process(
+      self,
+      pyacc,
+      section,
+      character_to_symbol,
+      name_to_symbol,
+      precedence,
+      tag
+    ):
+      return self
 
-    class Param(Item):
-      # GENERATE ELEMENT() BEGIN
-      def __init__(
+  class TerminalRef(TagOrSymbolRef):
+    # GENERATE ELEMENT(int terminal, int user_token) BEGIN
+    def __init__(
+      self,
+      tag = 'PYACC_TerminalRef',
+      attrib = {},
+      text = '',
+      children = [],
+      terminal = -1,
+      user_token = -1
+    ):
+      PYACC.TagOrSymbolRef.__init__(
         self,
-        tag = 'PYACC_Section1_Param',
-        attrib = {},
-        text = '',
-        children = []
-      ):
-        Item.__init__(
-          self,
-          tag,
-          attrib,
-          text,
-          children
+        tag,
+        attrib,
+        text,
+        children
+      )
+      self.terminal = (
+        element.deserialize_int(terminal)
+      if isinstance(terminal, str) else
+        terminal
+      )
+      self.user_token = (
+        element.deserialize_int(user_token)
+      if isinstance(user_token, str) else
+        user_token
+      )
+    def serialize(self, ref_list):
+      PYACC.TagOrSymbolRef.serialize(self, ref_list)
+      self.set('terminal', element.serialize_int(self.terminal))
+      self.set('user_token', element.serialize_int(self.user_token))
+    def deserialize(self, ref_list):
+      PYACC.TagOrSymbolRef.deserialize(self, ref_list)
+      self.terminal = element.deserialize_int(self.get('terminal', '-1'))
+      self.user_token = element.deserialize_int(self.get('user_token', '-1'))
+    def copy(self, factory = None):
+      result = PYACC.TagOrSymbolRef.copy(
+        self,
+        TerminalRef if factory is None else factory
+      )
+      result.terminal = self.terminal
+      result.user_token = self.user_token
+      return result
+    def repr_serialize(self, params):
+      PYACC.TagOrSymbolRef.repr_serialize(self, params)
+      if self.terminal != -1:
+        params.append(
+          'terminal = {0:s}'.format(repr(self.terminal))
         )
-      def copy(self, factory = None):
-        result = Item.copy(
-          self,
-          Param if factory is None else factory
+      if self.user_token != -1:
+        params.append(
+          'user_token = {0:s}'.format(repr(self.user_token))
         )
-        return result
-      def __repr__(self):
-        params = []
-        self.repr_serialize(params)
-        return 'ast.PYACC.Section1.Param({0:s})'.format(', '.join(params))
-      # GENERATE END
+    def __repr__(self):
+      params = []
+      self.repr_serialize(params)
+      return 'ast.PYACC.TerminalRef({0:s})'.format(', '.join(params))
+    # GENERATE END
+    def post_process(
+      self,
+      pyacc,
+      section,
+      character_to_symbol,
+      name_to_symbol,
+      precedence,
+      tag
+    ):
+      if isinstance(self[0], PYACC.Char):
+        character = ord(self[0][0].get_text())
+        assert character != 0 # would conflict with YYEOF
+        if character in character_to_symbol:
+          self.terminal = character_to_symbol[character]
+          assert self.terminal >= 0
+        else:
+          self.terminal = len(pyacc.terminals)
+          character_to_symbol[character] = self.terminal
+          pyacc.terminals.append(
+            PYACC.Terminal(character_set = [character, character + 1])
+          )
+      elif isinstance(self[0], PYACC.ID):
+        name = self[0].get_text()
+        if name in name_to_symbol:
+          self.terminal = name_to_symbol[name]
+          assert self.terminal >= 0
+        else:
+          self.terminal = len(pyacc.terminals)
+          name_to_symbol[name] = self.terminal
+          pyacc.terminals.append(
+            PYACC.Terminal(name = name)
+          )
+      else:
+        assert False
+      if self.user_token != -1:
+        assert len(pyacc.terminals[self.terminal].character_set) == 0
+        pyacc.terminals[self.terminal].character_set = (
+          [self.user_token, self.user_token + 1]
+        )
+      if precedence != -1:
+        assert pyacc.terminals[self.terminal].precedence == -1
+        pyacc.terminals[self.terminal].precedence = precedence
+      return tag
 
-    class Prologue(Item):
-      # GENERATE ELEMENT() BEGIN
-      def __init__(
+  class NonterminalRef(TagOrSymbolRef):
+    # GENERATE ELEMENT(int nonterminal, int user_token) BEGIN
+    def __init__(
+      self,
+      tag = 'PYACC_NonterminalRef',
+      attrib = {},
+      text = '',
+      children = [],
+      nonterminal = -1,
+      user_token = -1
+    ):
+      PYACC.TagOrSymbolRef.__init__(
         self,
-        tag = 'PYACC_Section1_Prologue',
-        attrib = {},
-        text = '',
-        children = []
-      ):
-        Item.__init__(
-          self,
-          tag,
-          attrib,
-          text,
-          children
+        tag,
+        attrib,
+        text,
+        children
+      )
+      self.nonterminal = (
+        element.deserialize_int(nonterminal)
+      if isinstance(nonterminal, str) else
+        nonterminal
+      )
+      self.user_token = (
+        element.deserialize_int(user_token)
+      if isinstance(user_token, str) else
+        user_token
+      )
+    def serialize(self, ref_list):
+      PYACC.TagOrSymbolRef.serialize(self, ref_list)
+      self.set('nonterminal', element.serialize_int(self.nonterminal))
+      self.set('user_token', element.serialize_int(self.user_token))
+    def deserialize(self, ref_list):
+      PYACC.TagOrSymbolRef.deserialize(self, ref_list)
+      self.nonterminal = element.deserialize_int(self.get('nonterminal', '-1'))
+      self.user_token = element.deserialize_int(self.get('user_token', '-1'))
+    def copy(self, factory = None):
+      result = PYACC.TagOrSymbolRef.copy(
+        self,
+        NonterminalRef if factory is None else factory
+      )
+      result.nonterminal = self.nonterminal
+      result.user_token = self.user_token
+      return result
+    def repr_serialize(self, params):
+      PYACC.TagOrSymbolRef.repr_serialize(self, params)
+      if self.nonterminal != -1:
+        params.append(
+          'nonterminal = {0:s}'.format(repr(self.nonterminal))
         )
-      def copy(self, factory = None):
-        result = Item.copy(
-          self,
-          Prologue if factory is None else factory
+      if self.user_token != -1:
+        params.append(
+          'user_token = {0:s}'.format(repr(self.user_token))
         )
-        return result
-      def __repr__(self):
-        params = []
-        self.repr_serialize(params)
-        return 'ast.PYACC.Section1.Prologue({0:s})'.format(', '.join(params))
-      # GENERATE END
-      def post_process(
-        self,
-        pyacc,
-        section,
-        character_to_symbol,
-        name_to_symbol
-      ):
-        assert isinstance(self[0], PYACC.Text)
-        pyacc.prologue_text.append(self[0])
+    def __repr__(self):
+      params = []
+      self.repr_serialize(params)
+      return 'ast.PYACC.NonterminalRef({0:s})'.format(', '.join(params))
+    # GENERATE END
+    def post_process(
+      self,
+      pyacc,
+      section,
+      character_to_symbol,
+      name_to_symbol,
+      precedence,
+      tag
+    ):
+      if isinstance(self[0], PYACC.ID):
+        name = self[0].get_text()
+        if name in name_to_symbol:
+          i = name_to_symbol[name]
+          assert i < 0
+          self.nonterminal = ~i
+        else:
+          self.nonterminal = len(pyacc.nonterminals)
+          name_to_symbol[name] = ~self.nonterminal
+          pyacc.nonterminals.append(
+            PYACC.Nonterminal(name = name, character_set = [])
+          )
+      else:
+        assert False
+      assert self.user_token == -1
+      assert precedence == -1
+      return tag
 
-    class Require(Item):
-      # GENERATE ELEMENT() BEGIN
+  class Text(element.Element):
+    class Escape(element.Element):
+      # GENERATE ELEMENT(int character) BEGIN
       def __init__(
         self,
-        tag = 'PYACC_Section1_Require',
+        tag = 'PYACC_Text_Escape',
         attrib = {},
         text = '',
-        children = []
+        children = [],
+        character = -1
       ):
-        Item.__init__(
+        element.Element.__init__(
           self,
           tag,
           attrib,
           text,
           children
         )
+        self.character = (
+          element.deserialize_int(character)
+        if isinstance(character, str) else
+          character
+        )
+      def serialize(self, ref_list):
+        element.Element.serialize(self, ref_list)
+        self.set('character', element.serialize_int(self.character))
+      def deserialize(self, ref_list):
+        element.Element.deserialize(self, ref_list)
+        self.character = element.deserialize_int(self.get('character', '-1'))
       def copy(self, factory = None):
-        result = Item.copy(
+        result = element.Element.copy(
           self,
-          Require if factory is None else factory
+          Escape if factory is None else factory
         )
+        result.character = self.character
         return result
+      def repr_serialize(self, params):
+        element.Element.repr_serialize(self, params)
+        if self.character != -1:
+          params.append(
+            'character = {0:s}'.format(repr(self.character))
+          )
       def __repr__(self):
         params = []
         self.repr_serialize(params)
-        return 'ast.PYACC.Section1.Require({0:s})'.format(', '.join(params))
+        return 'ast.PYACC.Text.Escape({0:s})'.format(', '.join(params))
       # GENERATE END
 
-    class Skeleton(Item):
-      # GENERATE ELEMENT() BEGIN
+    class StackLocation(element.Element):
+      # GENERATE ELEMENT(int index) BEGIN
       def __init__(
         self,
-        tag = 'PYACC_Section1_Skeleton',
+        tag = 'PYACC_Text_StackLocation',
         attrib = {},
         text = '',
-        children = []
+        children = [],
+        index = -1
       ):
-        Item.__init__(
+        element.Element.__init__(
           self,
           tag,
           attrib,
           text,
           children
         )
+        self.index = (
+          element.deserialize_int(index)
+        if isinstance(index, str) else
+          index
+        )
+      def serialize(self, ref_list):
+        element.Element.serialize(self, ref_list)
+        self.set('index', element.serialize_int(self.index))
+      def deserialize(self, ref_list):
+        element.Element.deserialize(self, ref_list)
+        self.index = element.deserialize_int(self.get('index', '-1'))
       def copy(self, factory = None):
-        result = Item.copy(
+        result = element.Element.copy(
           self,
-          Skeleton if factory is None else factory
+          StackLocation if factory is None else factory
         )
+        result.index = self.index
         return result
+      def repr_serialize(self, params):
+        element.Element.repr_serialize(self, params)
+        if self.index != -1:
+          params.append(
+            'index = {0:s}'.format(repr(self.index))
+          )
       def __repr__(self):
         params = []
         self.repr_serialize(params)
-        return 'ast.PYACC.Section1.Skeleton({0:s})'.format(', '.join(params))
+        return 'ast.PYACC.Text.StackLocation({0:s})'.format(', '.join(params))
       # GENERATE END
 
-    class TokenTable(Item):
-      # GENERATE ELEMENT() BEGIN
+    class StackReference(element.Element):
+      # GENERATE ELEMENT(int index) BEGIN
       def __init__(
         self,
-        tag = 'PYACC_Section1_TokenTable',
+        tag = 'PYACC_Text_StackReference',
         attrib = {},
         text = '',
-        children = []
+        children = [],
+        index = -1
       ):
-        Item.__init__(
+        element.Element.__init__(
           self,
           tag,
           attrib,
           text,
           children
         )
+        self.index = (
+          element.deserialize_int(index)
+        if isinstance(index, str) else
+          index
+        )
+      def serialize(self, ref_list):
+        element.Element.serialize(self, ref_list)
+        self.set('index', element.serialize_int(self.index))
+      def deserialize(self, ref_list):
+        element.Element.deserialize(self, ref_list)
+        self.index = element.deserialize_int(self.get('index', '-1'))
       def copy(self, factory = None):
-        result = Item.copy(
+        result = element.Element.copy(
           self,
-          TokenTable if factory is None else factory
+          StackReference if factory is None else factory
         )
+        result.index = self.index
         return result
+      def repr_serialize(self, params):
+        element.Element.repr_serialize(self, params)
+        if self.index != -1:
+          params.append(
+            'index = {0:s}'.format(repr(self.index))
+          )
       def __repr__(self):
         params = []
         self.repr_serialize(params)
-        return 'ast.PYACC.Section1.TokenTable({0:s})'.format(', '.join(params))
+        return 'ast.PYACC.Text.StackReference({0:s})'.format(', '.join(params))
       # GENERATE END
 
-    class Verbose(Item):
+    class ValueLocation(element.Element):
       # GENERATE ELEMENT() BEGIN
       def __init__(
         self,
-        tag = 'PYACC_Section1_Verbose',
+        tag = 'PYACC_Text_ValueLocation',
         attrib = {},
         text = '',
         children = []
       ):
-        Item.__init__(
+        element.Element.__init__(
           self,
           tag,
           attrib,
@@ -2301,27 +2273,27 @@ class PYACC(element.Element):
           children
         )
       def copy(self, factory = None):
-        result = Item.copy(
+        result = element.Element.copy(
           self,
-          Verbose if factory is None else factory
+          ValueLocation if factory is None else factory
         )
         return result
       def __repr__(self):
         params = []
         self.repr_serialize(params)
-        return 'ast.PYACC.Section1.Verbose({0:s})'.format(', '.join(params))
+        return 'ast.PYACC.Text.ValueLocation({0:s})'.format(', '.join(params))
       # GENERATE END
 
-    class YACC(Item):
+    class ValueReference(element.Element):
       # GENERATE ELEMENT() BEGIN
       def __init__(
         self,
-        tag = 'PYACC_Section1_YACC',
+        tag = 'PYACC_Text_ValueReference',
         attrib = {},
         text = '',
         children = []
       ):
-        Item.__init__(
+        element.Element.__init__(
           self,
           tag,
           attrib,
@@ -2329,26 +2301,26 @@ class PYACC(element.Element):
           children
         )
       def copy(self, factory = None):
-        result = Item.copy(
+        result = element.Element.copy(
           self,
-          YACC if factory is None else factory
+          ValueReference if factory is None else factory
         )
         return result
       def __repr__(self):
         params = []
         self.repr_serialize(params)
-        return 'ast.PYACC.Section1.YACC({0:s})'.format(', '.join(params))
+        return 'ast.PYACC.Text.ValueReference({0:s})'.format(', '.join(params))
       # GENERATE END
 
     # GENERATE ELEMENT() BEGIN
     def __init__(
       self,
-      tag = 'PYACC_Section1',
+      tag = 'PYACC_Text',
       attrib = {},
       text = '',
       children = []
     ):
-      PYACC.Section1Or2.__init__(
+      element.Element.__init__(
         self,
         tag,
         attrib,
@@ -2356,80 +2328,73 @@ class PYACC(element.Element):
         children
       )
     def copy(self, factory = None):
-      result = PYACC.Section1Or2.copy(
+      result = element.Element.copy(
         self,
-        Section1 if factory is None else factory
+        Text if factory is None else factory
       )
       return result
     def __repr__(self):
       params = []
       self.repr_serialize(params)
-      return 'ast.PYACC.Section1({0:s})'.format(', '.join(params))
+      return 'ast.PYACC.Text({0:s})'.format(', '.join(params))
     # GENERATE END
+    def get_text(self, len_production = 0):
+      return ''.join(
+        [
+          j
+          for i in range(len(self))
+          for j in [
+            element.get_text(self, i),
+            (
+              '(yyvsp[{0:d}])'.format(self[i].index - len_production)
+            if isinstance(self[i], PYACC.Text.StackReference) else
+              '(yyval)'
+            if isinstance(self[i], PYACC.Text.ValueReference) else
+              chr(self[i].character)
+            )
+          ]
+        ] +
+        [element.get_text(self, len(self))]
+      )
 
-  class Section2(Section1Or2):
-    class Rules(Item):
-      # GENERATE ELEMENT() BEGIN
-      def __init__(
+  class BracedCode(Text):
+    # GENERATE ELEMENT() BEGIN
+    def __init__(
+      self,
+      tag = 'PYACC_BracedCode',
+      attrib = {},
+      text = '',
+      children = []
+    ):
+      PYACC.Text.__init__(
         self,
-        tag = 'PYACC_Section2_Rules',
-        attrib = {},
-        text = '',
-        children = []
-      ):
-        Item.__init__(
-          self,
-          tag,
-          attrib,
-          text,
-          children
-        )
-      def copy(self, factory = None):
-        result = Item.copy(
-          self,
-          Rules if factory is None else factory
-        )
-        return result
-      def __repr__(self):
-        params = []
-        self.repr_serialize(params)
-        return 'ast.PYACC.Section2.Rules({0:s})'.format(', '.join(params))
-      # GENERATE END
-      def post_process(
+        tag,
+        attrib,
+        text,
+        children
+      )
+    def copy(self, factory = None):
+      result = PYACC.Text.copy(
         self,
-        pyacc,
-        section,
-        character_to_symbol,
-        name_to_symbol
-      ):
-        self[0].post_process(
-          pyacc,
-          section,
-          character_to_symbol,
-          name_to_symbol,
-          -1, # precedence
-          None # tag
-        )
-        if pyacc.first_nonterminal == -1:
-          pyacc.first_nonterminal = self[0].nonterminal
-        for i in self[1:]:
-          i.post_process(
-            pyacc,
-            section,
-            self[0].nonterminal,
-            character_to_symbol,
-            name_to_symbol
-          )
+        BracedCode if factory is None else factory
+      )
+      return result
+    def __repr__(self):
+      params = []
+      self.repr_serialize(params)
+      return 'ast.PYACC.BracedCode({0:s})'.format(', '.join(params))
+    # GENERATE END
 
+  class ID(Text):
     # GENERATE ELEMENT() BEGIN
     def __init__(
       self,
-      tag = 'PYACC_Section2',
+      tag = 'PYACC_ID',
       attrib = {},
       text = '',
       children = []
     ):
-      PYACC.Section1Or2.__init__(
+      PYACC.Text.__init__(
         self,
         tag,
         attrib,
@@ -2437,15 +2402,15 @@ class PYACC(element.Element):
         children
       )
     def copy(self, factory = None):
-      result = PYACC.Section1Or2.copy(
+      result = PYACC.Text.copy(
         self,
-        Section2 if factory is None else factory
+        ID if factory is None else factory
       )
       return result
     def __repr__(self):
       params = []
       self.repr_serialize(params)
-      return 'ast.PYACC.Section2({0:s})'.format(', '.join(params))
+      return 'ast.PYACC.ID({0:s})'.format(', '.join(params))
     # GENERATE END
 
   class Section3(Text):
@@ -2769,20 +2734,6 @@ tag_to_class = {
   'PYACC_Production_Merge': PYACC.Production.Merge,
   'PYACC_Production_Prec': PYACC.Production.Prec,
   'PYACC_Production_SymbolRef': PYACC.Production.SymbolRef,
-  'PYACC_Section': PYACC.Section,
-  'PYACC_String': PYACC.String,
-  'PYACC_TagOrSymbolRef': PYACC.TagOrSymbolRef,
-  'PYACC_Tag': PYACC.Tag,
-  'PYACC_TerminalRef': PYACC.TerminalRef,
-  'PYACC_NonterminalRef': PYACC.NonterminalRef,
-  'PYACC_Text': PYACC.Text,
-  'PYACC_Text_Escape': PYACC.Text.Escape,
-  'PYACC_Text_StackLocation': PYACC.Text.StackLocation,
-  'PYACC_Text_StackReference': PYACC.Text.StackReference,
-  'PYACC_Text_ValueLocation': PYACC.Text.ValueLocation,
-  'PYACC_Text_ValueReference': PYACC.Text.ValueReference,
-  'PYACC_BracedCode': PYACC.BracedCode,
-  'PYACC_ID': PYACC.ID,
   'PYACC_Section1Or2': PYACC.Section1Or2,
   'PYACC_Section1Or2_Code': PYACC.Section1Or2.Code,
   'PYACC_Section1Or2_CodeProps': PYACC.Section1Or2.CodeProps,
@@ -2817,6 +2768,19 @@ tag_to_class = {
   'PYACC_Section1_YACC': PYACC.Section1.YACC,
   'PYACC_Section2': PYACC.Section2,
   'PYACC_Section2_Rules': PYACC.Section2.Rules,
+  'PYACC_String': PYACC.String,
+  'PYACC_TagOrSymbolRef': PYACC.TagOrSymbolRef,
+  'PYACC_Tag': PYACC.Tag,
+  'PYACC_TerminalRef': PYACC.TerminalRef,
+  'PYACC_NonterminalRef': PYACC.NonterminalRef,
+  'PYACC_Text': PYACC.Text,
+  'PYACC_Text_Escape': PYACC.Text.Escape,
+  'PYACC_Text_StackLocation': PYACC.Text.StackLocation,
+  'PYACC_Text_StackReference': PYACC.Text.StackReference,
+  'PYACC_Text_ValueLocation': PYACC.Text.ValueLocation,
+  'PYACC_Text_ValueReference': PYACC.Text.ValueReference,
+  'PYACC_BracedCode': PYACC.BracedCode,
+  'PYACC_ID': PYACC.ID,
   'PYACC_Section3': PYACC.Section3
 }
 def factory(tag, attrib = {}, *args, **kwargs):