Пример #1
0
        /// <summary>
        /// Used to predict the next correct tokens
        /// </summary>
        /// <returns>A list of predictions</returns>
        public List<string> Predict(Chart chart)
        {
            List<string> tokens = new List<string>();
            foreach(ActiveItem ai in this.Value)
            {
                if (ai.Seq.Count > ai.Dot)
                {
                    Symbol s = ai.Seq[ai.Dot];
                    if (s is SymbolKS)
                    {
                        SymbolKS sks = (SymbolKS)s;
                        if (sks.Tokens.Length > 0)
                        {
                            tokens.Add(sks.Tokens[0]);
                        }
                    }
                    else if (s is SymbolKP)
                    {
                        SymbolKP skp = (SymbolKP)s;
                        if (skp.Tokens.Length > 0)
                        {
                            // TODO check if correct, before [0]

                            foreach (Symbol newSymbol in skp.Tokens)
                            {
                                if (newSymbol is SymbolKS)
                                {
                                    // TODO is this correct?
                                    tokens.AddRange(((SymbolKS)newSymbol).Tokens);
                                }
                                else if (newSymbol is SymbolBind)
                                {
                                    tokens.Add("&+");
                                }
                                else if (newSymbol is SymbolSoftBind)
                                {

                                }
                                else if (newSymbol is SymbolSoftSpace)
                                {

                                }
                                else if (newSymbol is SymbolCapit)
                                {
                                    tokens.Add("&|");
                                }
                                else if (newSymbol is SymbolAllCapit)
                                {
                                    tokens.Add("&|");
                                }
                                else
                                {

                                }
                            }
                        }
                    }
                    else if (s is SymbolLit)
                    {
                        SymbolLit slit = (SymbolLit)s;
                        int arg = ai.Args[slit.Arg];
                        if (arg == -1)
                        {
                            // String
                            tokens.Add("\"STRING\"");
                        }
                        else if (arg == -2)
                        {
                            // Int
                            tokens.Add("123");
                        }
                        else if (arg == -3)
                        {
                            // Float
                            tokens.Add("3.14");
                        }
                        else if (arg == -4)
                        {
                            // Var
                            tokens.Add("\"VARIABLE\"");
                        }
                    }
                    else if (s is SymbolCat)
                    {
                        SymbolCat scat = (SymbolCat)s;
                        int fid = ai.Args[scat.Arg];
                        List<Production> prods = chart.ExpandForest(fid);
                        foreach(Production p in prods)
                        {
                            if (p is ProductionApply)
                            {
                                var papp = (ProductionApply)p;

                            }
                        }
                    }
                }
            }

            return tokens;
        }
Пример #2
0
        public List<string> Predict2(Chart chart)
        {
            List<string> tokens = new List<string>();

            foreach(ActiveItem ai in this.Value)
            {
                foreach(int arg in ai.Args)
                {
                    // Get all the arguments
                    foreach(Production p in chart.ExpandForest(arg))
                    {
                        // TODO
                    }
                }

            }

            return tokens;
        }
Пример #3
0
        /// <summary>
        /// Makes a list of trees for a certain category with help of the current chart.
        /// </summary>
        /// <param name="cat">The category.</param>
        /// <param name="chart">The current chart.</param>
        /// <returns>A list of trees.</returns>
        public List<Tree> MkTreesForCat(int cat, Chart chart)
        {
            List<Tree> temp = new List<Tree>();
            foreach (Production p in chart.ExpandForest(cat))
            {
                temp.AddRange(this.MkTreesForProduction(p, chart));
            }

            return temp;
        }