/// <summary> /// Initializes a new instance of the <see cref="CASTElement"/> class. /// </summary> /// <param name="nodeType">Type of the node.</param> public CASTElement(NodeType nodeType, CASTElement parent, NodeType nodeCategory) { m_nodeType = nodeType; m_nodeCategory = nodeCategory; m_parent = parent; m_serialNumber = m_serialNumberCounter++; m_label = nodeType.ToString() + "_" + m_serialNumber; }
/// <summary> /// Adds the child to the specified context. /// </summary> /// <param name="context">The context.</param> /// <param name="child">The child.</param> /// <param name="pos">The position.</param> public virtual void AddChild(CASTElement child, ContextType context = ContextType.CT_NA, int pos = -1) { if (context == ContextType.CT_NA) { throw new Exception("ERROR!!! Invalid context type"); } int contextIndex = CConfigurationSettings.m_contextTypeConfiguration[context].M_ContextIndex; AddChild(child, contextIndex, pos); }
public CASTComposite(NodeType nodeType, CASTElement parent, NodeType nodeCategory = NodeType.CAT_NA) : base(nodeType, parent, nodeCategory) { M_NumberOfContexts = CConfigurationSettings.m_nodeTypeConfiguration[nodeType].M_NumberOfContexts; // Instanciate the contextual IR m_descentands = new List <CASTElement> [M_NumberOfContexts]; for (int j = 0; j < M_NumberOfContexts; j++) { m_descentands[j] = new List <CASTElement>(); } }
/// <summary> /// AddChild method inserts a child at the given context to the specified location /// The location given by the pos parameter can take one of the following values /// 1) -1 to indicate the last element of the list /// 2) a positive integer indicating any position in the list where if it equals to /// m_descentands[context].Count, it is placed at the end of the list as in option 1 /// </summary> /// <param name="context">The context.</param> /// <param name="child">The child.</param> /// <param name="pos">The position.</param> /// <exception cref="IndexOutOfRangeException"> /// Error! Negative index in array reference /// or /// Error! Negative index in array reference /// </exception> protected override void AddChild(CASTElement child, int context, int pos = -1 /*insert last by default*/) { if (pos == -1) { m_descentands[context].Add(child); } else if (pos > -1) { if (pos <= m_descentands[context].Count) { m_descentands[context].Insert(pos, child); } else { throw new IndexOutOfRangeException("Error! Negative index in array reference"); } } else { throw new IndexOutOfRangeException("Error! Negative index in array reference"); } }
protected abstract void AddChild(CASTElement child, int context, int pos = -1 /*insert last by default*/);
public CASTLeaf(string literal, NodeType nodetype, CASTElement parent, NodeType nodeCategory = NodeType.CAT_NA) : base(nodetype, parent, nodeCategory) { m_TokenLiteral = literal; m_label += "< " + m_TokenLiteral + " >"; }