Exemple #1
0
        public List <FirstKEl> firstPlusOp(List <FirstKEl> set1, List <FirstKEl> set2, int k)
        {
            int      ip, jp;
            FirstKEl fel;
            var      result      = new List <FirstKEl>();
            var      resultcheck = new List <string>();

            for (var i = 0; i < set1.Count; i++)
            {
                for (var j = 0; j < set2.Count; j++)
                {
                    ip = 0; jp = 0; fel = new FirstKEl(k);
                    for (var m = 0; m < this.k; m++)
                    {
                        if (ip < set1[i].str.Count)
                        {
                            fel.addGEl(set1[i].str[ip]);
                            ip++;
                            continue;
                        }
                        if (jp < set2[j].str.Count)
                        {
                            fel.addGEl(set2[j].str[jp]);
                            jp++;
                            continue;
                        }
                        break;
                    }
                    Helpers.addToArrayFlat(fel, fel.toFlat(), result, resultcheck);
                }
            }

            return(result);
        }
Exemple #2
0
        public FirstKEl clone()
        {
            var result = new FirstKEl(this.KRemaining);

            result.K   = this.K;
            result.str = new List <string>(this.str);
            return(result);
        }
Exemple #3
0
        public List <FirstKEl> _firstOp_exp(FirstKEl el, string N)
        {
            var set = new List <FirstKEl>();

            set.Add(el.clone());
            var set2 = new List <FirstKEl>();
            var set3 = new List <FirstKEl>();

            for (var r = 0; r < this.cfg.Rules.Count; r++)
            {
                var cr = this.cfg.Rules[r];

                // skip irrelevant rules
                if (cr.Left != N)
                {
                    continue;
                }

                for (var i = 0; i < cr.Right.Count; i++)
                {
                    for (var j = 0; j < set.Count; j++)
                    {
                        // only uncomplete
                        if (set[j].KRemaining <= 0)
                        {
                            set2.Add(set[j]);
                            continue;
                        }

                        // add terminals
                        if (!cfg.IsNonTerminal(cr.Right[i]))
                        {
                            set[j].addGEl(cr.Right[i]);
                            set2.Add(set[j]);
                            continue;
                        }

                        // expand nonterminals
                        set2.AddRange(this._firstOp_exp(set[j], cr.Right[i]));
                    }
                    set  = set2;
                    set2 = new List <FirstKEl>();
                }

                set3.AddRange(set);
                set = new List <FirstKEl>();
                set.Add(el.clone());
                set2 = new List <FirstKEl>();
            }

            return(set3);
        }
Exemple #4
0
        public string convUToSiFlat(FirstKEl u)
        {
            var flat = "";

            for (var i = 0; i < u.str.Count; i++)
            {
                flat += u.str[i];
                if (i != u.str.Count - 1)
                {
                    flat += ":";
                }
            }
            return(flat);
        }
Exemple #5
0
 public LLkTRow(FirstKEl u, CfgRule grule, List <FollowEl> F)
 {
     this.u      = u;
     this.prod   = grule;
     this.follow = F;
 }