# GENERATE END
# syntax classes
- class BracedCode(element.Element):
- # GENERATE ELEMENT() BEGIN
- def __init__(
- self,
- tag = 'PYACC_BracedCode',
- attrib = {},
- text = '',
- children = []
- ):
- element.Element.__init__(
- self,
- tag,
- attrib,
- text,
- children
- )
- def copy(self, factory = None):
- result = element.Element.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
- def get_text(self, len_production = 0):
- return ''.join(
- [
- (
- '(yyvsp[{0:d}])'.format(i.index - len_production)
- if isinstance(i, PYACC.StackReference) else
- '(yyval)'
- if isinstance(i, PYACC.ValueReference) else
- chr(i.character)
- if isinstance(i, PYACC.Escape) else
- element.get_text(i, 0)
- )
- for i in self
- ]
- )
-
class BracedPredicate(element.Element):
# GENERATE ELEMENT() BEGIN
def __init__(
self.repr_serialize(params)
return 'ast.PYACC.Char({0:s})'.format(', '.join(params))
# GENERATE END
- def get_text(self):
- return ''.join(
- [
- (
- chr(i.character)
- if isinstance(i, PYACC.Escape) else
- element.get_text(i, 0)
- )
- for i in self
- ]
- )
-
- class Escape(element.Element):
- # GENERATE ELEMENT(int character) BEGIN
- def __init__(
- self,
- tag = 'PYACC_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.Escape({0:s})'.format(', '.join(params))
- # GENERATE END
-
- class ID(element.Element):
- # GENERATE ELEMENT() BEGIN
- def __init__(
- self,
- tag = 'PYACC_ID',
- attrib = {},
- text = '',
- children = []
- ):
- element.Element.__init__(
- self,
- tag,
- attrib,
- text,
- children
- )
- def copy(self, factory = None):
- result = element.Element.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 Int(element.Element):
# GENERATE ELEMENT() BEGIN
name_to_symbol
):
if isinstance(self[0], PYACC.Char):
- character = ord(self[0].get_text())
+ character = ord(self[0][0].get_text())
assert character != 0 # would conflict with YYEOF
if character in character_to_symbol:
self.symbol = character_to_symbol[character]
PYACC.Terminal(character_set = [character, character + 1])
)
elif isinstance(self[0], PYACC.ID):
- name = element.get_text(self[0], 0)
+ name = self[0].get_text()
if name in name_to_symbol:
self.symbol = name_to_symbol[name]
else:
):
raise NotImplementedException
- class StackLocation(element.Element):
- # GENERATE ELEMENT(int index) BEGIN
- def __init__(
- self,
- tag = 'PYACC_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.StackLocation({0:s})'.format(', '.join(params))
- # GENERATE END
-
- class StackReference(element.Element):
- # GENERATE ELEMENT(int index) BEGIN
- def __init__(
- self,
- tag = 'PYACC_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.StackReference({0:s})'.format(', '.join(params))
- # GENERATE END
-
class String(element.Element):
# GENERATE ELEMENT() BEGIN
def __init__(
self.repr_serialize(params)
return 'ast.PYACC.String({0:s})'.format(', '.join(params))
# GENERATE END
- def get_text(self):
- return ''.join(
- [
- (
- chr(i.character)
- if isinstance(i, PYACC.Escape) else
- element.get_text(i, 0)
- )
- for i in self
- ]
- )
class TagOrSymbolRef(element.Element):
# GENERATE ELEMENT() BEGIN
tag
):
if isinstance(self[0], PYACC.Char):
- character = ord(self[0].get_text())
+ 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]
PYACC.Terminal(character_set = [character, character + 1])
)
elif isinstance(self[0], PYACC.ID):
- name = element.get_text(self[0], 0)
+ name = self[0].get_text()
if name in name_to_symbol:
self.terminal = name_to_symbol[name]
assert self.terminal >= 0
tag
):
if isinstance(self[0], PYACC.ID):
- name = element.get_text(self[0], 0)
+ name = self[0].get_text()
if name in name_to_symbol:
i = name_to_symbol[name]
assert i < 0
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,
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 Code(Item):
return 'ast.PYACC.Section2({0:s})'.format(', '.join(params))
# GENERATE END
- class Section3(Section):
+ class Section3(Text):
# GENERATE ELEMENT() BEGIN
def __init__(
self,
text = '',
children = []
):
- PYACC.Section.__init__(
+ PYACC.Text.__init__(
self,
tag,
attrib,
children
)
def copy(self, factory = None):
- result = PYACC.Section.copy(
+ result = PYACC.Text.copy(
self,
Section3 if factory is None else factory
)
):
pass
- class ValueLocation(element.Element):
- # GENERATE ELEMENT() BEGIN
- def __init__(
- self,
- tag = 'PYACC_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.ValueLocation({0:s})'.format(', '.join(params))
- # GENERATE END
-
- class ValueReference(element.Element):
- # GENERATE ELEMENT() BEGIN
- def __init__(
- self,
- tag = 'PYACC_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.ValueReference({0:s})'.format(', '.join(params))
- # GENERATE END
-
# GENERATE ELEMENT(list(ref) prologue_text, list(ref) terminals, list(ref) nonterminals, list(ref) productions, int first_nonterminal, int start_nonterminal, list(int) associativities) BEGIN
def __init__(
self,
# perform the semantic analysis pass
self.first_nonterminal = -1
self.start_nonterminal = -1
- for i in self:
- i.post_process(
- self,
- character_to_symbol,
- name_to_symbol
- )
+ self[0].post_process(self, character_to_symbol, name_to_symbol)
+ self[1].post_process(self, character_to_symbol, name_to_symbol)
# fill in token numbers that are not characters or overridden by user
token = 0x100
'PYACC_Symbol': PYACC.Symbol,
'PYACC_Terminal': PYACC.Terminal,
'PYACC_Nonterminal': PYACC.Nonterminal,
- 'PYACC_BracedCode': PYACC.BracedCode,
'PYACC_BracedPredicate': PYACC.BracedPredicate,
'PYACC_Char': PYACC.Char,
- 'PYACC_Escape': PYACC.Escape,
- 'PYACC_ID': PYACC.ID,
'PYACC_Int': PYACC.Int,
'PYACC_Production': PYACC.Production,
'PYACC_Production_Item': PYACC.Production.Item,
'PYACC_Production_Prec': PYACC.Production.Prec,
'PYACC_Production_SymbolRef': PYACC.Production.SymbolRef,
'PYACC_Section': PYACC.Section,
- 'PYACC_StackLocation': PYACC.StackLocation,
- 'PYACC_StackReference': PYACC.StackReference,
'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,
'PYACC_Section1_YACC': PYACC.Section1.YACC,
'PYACC_Section2': PYACC.Section2,
'PYACC_Section2_Rules': PYACC.Section2.Rules,
- 'PYACC_Section3': PYACC.Section3,
- 'PYACC_ValueLocation': PYACC.ValueLocation,
- 'PYACC_ValueReference': PYACC.ValueReference
+ 'PYACC_Section3': PYACC.Section3
}
def factory(tag, attrib = {}, *args, **kwargs):
return tag_to_class.get(tag, element.Element)(tag, attrib, *args, **kwargs)