Exemplo n.º 1
0
        public void addEl(string fiFlat, string siFlat, PTEl ptel)
        {
            int fi, si;

            fi = Helpers.indexOf(fiFlat, this.fif);
            si = Helpers.indexOf(siFlat, this.sif);
            this.field[fi][si].Add(ptel);
        }
Exemplo n.º 2
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
        }