public string convSiSTRToFiFlat(PTSecondIn sel) { return(":" + sel.str[0]); }
public void fillPT() { string fiv, siv; PTEl el; var PT = this.PT; //(1) expand LLkT tabi; LLkTRow rowj; string gelk; int nontl; string gelnew; for (var i = 0; i < this.LLks.Count; i++) { tabi = this.LLks[i]; for (var j = 0; j < tabi.rows.Count; j++) { rowj = tabi.rows[j]; el = new PTEl(PTEType.EXPAND, new List <string>(), rowj.prod); // convert the right side of a rule nontl = 0; for (var k = 0; k < rowj.prod.Right.Count; k++) { gelk = rowj.prod.Right[k]; if (!cfg.IsNonTerminal(gelk)) { el.str.Add(gelk); } else { gelnew = this.convNToTableName(gelk, rowj.follow[nontl].sets); el.str.Add(gelnew); nontl++; } } fiv = tabi.name; siv = PT.convUToSiFlat(rowj.u); PT.addEl(fiv, siv, el); } } //(2) pop PTSecondIn sii; for (var i = 0; i < PT.si.Count; i++) { sii = PT.si[i]; if (sii.type != PTSIType.STR) { continue; } el = new PTEl(PTEType.POP, null, null); fiv = PT.convSiSTRToFiFlat(sii); siv = sii.toFlat(); PT.addEl(fiv, siv, el); } //(3) accept PTFirstIn fie; PTSecondIn sie; el = new PTEl(PTEType.ACCEPT, null, null); fie = new PTFirstIn(PTFIType.BOT, null); sie = new PTSecondIn(PTSIType.END, null); fiv = fie.toFlat(); siv = sie.toFlat(); PT.addEl(fiv, siv, el); //(4)(5) //nothing }
public void init(IList <string> T, int Tcounter, int k) { // the first index PTFirstIn nfi; for (var i = 0; i < Tcounter; i++) { nfi = new PTFirstIn(PTFIType.N, "T" + i); this.fi.Add(nfi); this.fif.Add(nfi.toFlat()); } for (var i = 0; i < T.Count; i++) { nfi = new PTFirstIn(PTFIType.T, T[i]); this.fi.Add(nfi); this.fif.Add(nfi.toFlat()); } nfi = new PTFirstIn(PTFIType.BOT, null); this.fi.Add(nfi); this.fif.Add(nfi.toFlat()); // the second index PTSecondIn nsi; var ins = new List <int>(); for (var ki = 0; ki < k; ki++) { ins.Add(0); } while (T.Count > ins[0]) { nsi = new PTSecondIn(PTSIType.STR, new List <string>()); for (var ki = 0; ki < k; ++ki) { if (ins[ki] < T.Count) { nsi.str.Add(T[ins[ki]]); } } ++ins[k - 1]; for (var ki = k - 1; ki >= 0; ki--) { if (ins[ki] > T.Count) { ++ins[ki - 1]; ins[ki] = 0; } } Helpers.addToArrayFlat(nsi, nsi.toFlat(), this.si, this.sif); } nsi = new PTSecondIn(PTSIType.END, null); this.si.Add(nsi); this.sif.Add(nsi.toFlat()); // fields for (var i = 0; i < this.fi.Count; i++) { this.field.Add(new List <List <PTEl> >()); for (var j = 0; j < this.si.Count; j++) { this.field[i].Add(new List <PTEl>()); } } }