public InstructionsTreeNode(InstructionsTreeNode parent) { this.parent = parent; this.phraseIndex=-1; this.childs=new ArrayList(); this.command=null; if (parent == null) this.level = 0; else this.level = parent.Level + 1; }
public InstructionsTreeNode(int phraseIndex,InstructionsTreeNode parent,Command command=null) { this.phraseIndex = phraseIndex; this.parent = parent; this.command = null; this.childs = new ArrayList(); if (parent == null) this.level = 0; else this.level = parent.Level + 1; }
public InstructionsTree(int rootPhraseIndex=-1, Command rootCommand = null) { root = new InstructionsTreeNode(rootPhraseIndex, null, rootCommand); }
public void GenerateBranch(PreCompiledInstruction instruction) { int i=0; InstructionsTreeNode child; bool searching = true; this.phraseIndex = instruction.phraseIndices[this.level]; if (this.level < instruction.Length - 1) { if (childs.Count > 0) { while (i < childs.Count && searching) { child = ((InstructionsTreeNode)childs[i]); if (instruction.phraseIndices[level + 1] == child.phraseIndex) { child.GenerateBranch(instruction); searching = false; } else ++i; } if (searching) { childs.Add(new InstructionsTreeNode(this)); ((InstructionsTreeNode)childs[childs.Count - 1]).GenerateBranch(instruction); } } else { childs.Add(new InstructionsTreeNode(this)); ((InstructionsTreeNode)childs[childs.Count - 1]).GenerateBranch(instruction); } } else this.command = instruction.command; }