/// <summary> /// BoolExp_ /// </summary> /// <param name="firstBoolE"></param> /// <returns></returns> private Property_BoolE BoolExp_Gram(Property_BoolE firstBoolE) { Property_BoolE BoolE = new Property_BoolE(); bool LogicOptResult = LogicOptGram(); if (!LogicOptResult) { return(firstBoolE); } string opString = this.varTable.GetItem(this.matchIndex - 1).varValue; Property_ME ME = new Property_ME(this.globalQuad); Property_BoolE secondBoolE = BoolExpGram(); switch (opString) { case "and": BackPatch(firstBoolE.TrueList, ME.Quad); BoolE.TrueList = secondBoolE.TrueList; BoolE.FalseList = Merge(firstBoolE.FalseList, secondBoolE.FalseList); break; case "or": BackPatch(firstBoolE.FalseList, ME.Quad); BoolE.TrueList = Merge(firstBoolE.TrueList, secondBoolE.TrueList); BoolE.FalseList = secondBoolE.FalseList; break; } return(BoolExp_Gram(BoolE)); }
/// <summary> /// BoolExp /// </summary> /// <returns></returns> private Property_BoolE BoolExpGram() { if (this.varTable.GetItem(this.matchIndex).varValue.Equals("(")) { this.matchIndex++; Property_BoolE BoolE = BoolExpGram(); if (this.varTable.GetItem(this.matchIndex).varValue.Equals(")")) { this.matchIndex++; } return(BoolExp_Gram(BoolE)); } else if (this.varTable.GetItem(this.matchIndex).varValue.Equals("not")) { this.matchIndex++; Property_BoolE BoolE1 = BoolExpGram(); Property_BoolE BoolE = new Property_BoolE(); BoolE.TrueList = BoolE1.FalseList; BoolE.FalseList = BoolE1.TrueList; return(BoolE); } else { Property_BoolE BoolE = CompareEGram(); return(BoolExp_Gram(BoolE)); } }
/// <summary> /// XHSentence /// </summary> /// <returns></returns> private Property_SE XHSentenceGram() { if (this.varTable.GetItem(this.matchIndex).varValue.Equals("while")) { this.matchIndex++; } Property_ME ME1 = new Property_ME(this.globalQuad); Property_BoolE BoolE = BoolExpGram(); if (this.varTable.GetItem(this.matchIndex).varValue.Equals("do")) { this.matchIndex++; } Property_ME ME2 = new Property_ME(this.globalQuad); Property_SE SE1 = new Property_SE(); if (this.varTable.GetItem(this.matchIndex).varType == ConstTable.VariableType.Identity) { SE1 = FillSentenceGram(); } else if (this.varTable.GetItem(this.matchIndex).varValue.Equals("if")) { SE1 = FZSentenceGram(); } else if (this.varTable.GetItem(this.matchIndex).varValue.Equals("while")) { SE1 = XHSentenceGram(); } else if (this.varTable.GetItem(this.matchIndex).varValue.Equals("begin")) { SE1 = ComplexSentenceGram(); } Property_SE SE = new Property_SE(); BackPatch(SE1.NextList, ME1.Quad); BackPatch(BoolE.TrueList, ME2.Quad); SE.NextList = BoolE.FalseList; QuaternionItem item1 = new QuaternionItem(this.globalQuad, NullQuaternionElement, NullQuaternionElement, NullQuaternionElement, ME1.Quad, ConstTable.QuaternionType.WHILEEXP); this.QuaternionTb.Add(item1); this.globalQuad++; return(SE); }
/// <summary> /// 如果分析出比较语句,产生四元式,并且写出属性文法 /// </summary> /// <returns></returns> private Property_BoolE CompareEGram() { bool EntityResult = EntityGram(); string firstEntity = this.varTable.GetItem(this.matchIndex - 1).varValue; bool BoolOptResult = BoolOptGram(); string opString = this.varTable.GetItem(this.matchIndex - 1).varValue; bool EntityResult2 = EntityGram(); string secondEntity = this.varTable.GetItem(this.matchIndex - 1).varValue; Property_BoolE BoolE = new Property_BoolE(); if (EntityResult && BoolOptResult && EntityResult2) { QuaternionItem item1 = new QuaternionItem(this.globalQuad, opString, firstEntity, secondEntity, 0, ConstTable.QuaternionType.BOOLEXP); this.globalQuad++; QuaternionItem item2 = new QuaternionItem(this.globalQuad, NullQuaternionElement, NullQuaternionElement, NullQuaternionElement, 0, ConstTable.QuaternionType.BOOLEXP); this.QuaternionTb.Add(item1); this.QuaternionTb.Add(item2); BoolE = new Property_BoolE(); List <int> trueList = new List <int>(); trueList.Add(this.globalQuad - 1); BoolE.TrueList = trueList; List <int> falseList = new List <int>(); falseList.Add(this.globalQuad); BoolE.FalseList = falseList; this.globalQuad++; } return(BoolE); }
/// <summary> /// FZSentence /// </summary> /// <returns></returns> private Property_SE FZSentenceGram() { if (this.varTable.GetItem(this.matchIndex).varValue.Equals("if")) { this.matchIndex++; } Property_BoolE BoolE = BoolExpGram(); if (this.varTable.GetItem(this.matchIndex).varValue.Equals("then")) { this.matchIndex++; } Property_ME ME1 = new Property_ME(this.globalQuad); Property_SE SE1 = new Property_SE(); if (this.varTable.GetItem(this.matchIndex).varType == ConstTable.VariableType.Identity) { SE1 = FillSentenceGram(); } else if (this.varTable.GetItem(this.matchIndex).varValue.Equals("if")) { SE1 = FZSentenceGram(); } else if (this.varTable.GetItem(this.matchIndex).varValue.Equals("while")) { SE1 = XHSentenceGram(); } else if (this.varTable.GetItem(this.matchIndex).varValue.Equals("begin")) { SE1 = ComplexSentenceGram(); } Property_SE SE = new Property_SE(); if (this.varTable.GetItem(this.matchIndex).varValue.Equals("else")) { Property_NE NE = new Property_NE(); List <int> nextList = new List <int>(); nextList.Add(this.globalQuad); NE.NextList = nextList; QuaternionItem item1 = new QuaternionItem(this.globalQuad, NullQuaternionElement, NullQuaternionElement, NullQuaternionElement, 0, ConstTable.QuaternionType.NEXP); this.QuaternionTb.Add(item1); this.globalQuad++; if (this.varTable.GetItem(this.matchIndex).varValue.Equals("else")) { this.matchIndex++; } Property_ME ME2 = new Property_ME(this.globalQuad); Property_SE SE2 = new Property_SE(); if (this.varTable.GetItem(this.matchIndex).varType == ConstTable.VariableType.Identity) { SE2 = FillSentenceGram(); } else if (this.varTable.GetItem(this.matchIndex).varValue.Equals("if")) { SE2 = FZSentenceGram(); } else if (this.varTable.GetItem(this.matchIndex).varValue.Equals("while")) { SE2 = XHSentenceGram(); } else if (this.varTable.GetItem(this.matchIndex).varValue.Equals("begin")) { SE2 = ComplexSentenceGram(); } BackPatch(BoolE.TrueList, ME1.Quad); BackPatch(BoolE.FalseList, ME2.Quad); SE.NextList = Merge(Merge(SE1.NextList, NE.NextList), SE2.NextList); } else { BackPatch(BoolE.TrueList, ME1.Quad); SE.NextList = Merge(BoolE.FalseList, SE1.NextList); } return(SE); }