trick/docs/not_referenced/S_sie.resource-Parsing-Algorithm.md
2019-11-20 11:04:58 -06:00

1.5 KiB

Data Structures

Classes

  • MemberInfo
    a class that encapsulates the data contained in a <top_level_object> or <member> xml element
  • EnumInfo
    a class that encapsulates the data contained in an <enumeration> xml element

Lists

  • allInstances
    a list of MemberInfos
  • rootInstances
    another list of MemberInfos

Hash Maps

  • typeHashMap
    a hash map whose keys are strings and whose values are lists of MemberInfos
  • enumHashMap
    a hash map whose keys are strings and whose values are EnumInfos

Logic Pseudo-Code

for each topLevelObject in (xml elements of type <top_level_object>):
    info = new MemberInfo(topLevelObject)
    allInstances.add(info)
    rootInstances.add(info)

for each clazz in (xml elements of type <class>):
    memberList = new List()
    typeHashMap[clazz.name] = memberList
    for each member in (xml element of type <member>):
        info = new MemberInfo(member)
        allInstances.add(info)
        memberList.add(info)

for each enum in (xml elements of type <enumeration>):
    enumHashMap[enum.name] = new EnumInfo(enum)

for each instance in allInstances:
    instance.children = typeHashMap[instance.type]       // one of these
    instance.enumeration = enumHashMap[instance.type]    // will be NULL

Walking the Tree

The entire variable hierarchy can be obtained via a pre-order depth-first traversal of rootInstances. The other data structures are now redundant and can be discarded.