public INode Match(Lookahead2Enumerator <Token> it, IGrammarParser parser)
        {
            if (!this.open.Equals(it.PeekNext()))
            {
                return(null);
            }
            it.Consume();
            if (this.close.Equals(it.PeekNext()))
            {
                it.Consume();
                return(this.nf.BuildOperatorNode(this.list, new INode[0]));
            }
            List <INode> list = new List <INode>();

            while (true)
            {
                INode item = parser.ParseSubExpression();
                list.Add(item);
                if (this.close.Equals(it.PeekNext()))
                {
                    it.Consume();
                    return(this.nf.BuildOperatorNode(this.list, list.ToArray()));
                }
                if (!this.comma.Equals(it.PeekNext()))
                {
                    break;
                }
                it.Consume();
            }
            throw new Colosoft.Text.Jep.ParseException("Closing bracket not found");
        }
Exemple #2
0
        public INode Match(Lookahead2Enumerator <Token> it, IGrammarParser parser)
        {
            Token token = it.PeekNext();

            if (token == null)
            {
                return(null);
            }
            if (!token.IsIdentifier())
            {
                return(null);
            }
            if (!this.open.Equals(it.PeekNextnext()))
            {
                return(null);
            }
            it.Consume();
            ArrayList list = new ArrayList(4);

            list.Add(this.nf.BuildVariableNodeCheckUndeclared(token.GetSource()));
            while (this.open.Equals(it.PeekNext()))
            {
                it.Consume();
                INode node = parser.ParseSubExpression();
                list.Add(node);
                if (!this.close.Equals(it.PeekNext()))
                {
                    throw new Colosoft.Text.Jep.ParseException("Closing bracket not found, next token is " + it.PeekNext());
                }
                it.Consume();
            }
            INode[] arguments = new INode[list.Count];
            arguments = (INode[])list.ToArray(Type.GetType("Colosoft.Text.Jep.Parser.INode"));
            return(this.nf.BuildOperatorNode(this.ot.GetOperator(0x17), arguments));
        }
Exemple #3
0
        public INode Match(Lookahead2Enumerator <Token> it, IGrammarParser parser)
        {
            Token token = it.PeekNext();

            if (token == null)
            {
                return(null);
            }
            if (!token.IsFunction())
            {
                return(null);
            }
            string source            = token.GetSource();
            IPostfixMathCommand pfmc = ((FunctionToken)token).GetPfmc();

            if (!this.open.Equals(it.PeekNextnext()))
            {
                return(null);
            }
            it.Consume();
            it.Consume();
            if (this.close.Equals(it.PeekNext()))
            {
                if (!pfmc.CheckNumberOfParameters(0))
                {
                    throw new Colosoft.Text.Jep.ParseException("Function " + pfmc + " invalid number of arguments 0");
                }
                it.Consume();
                return(this.nf.BuildFunctionNode(source, pfmc, new INode[0]));
            }
            List <INode> list = new List <INode>();

            while (true)
            {
                INode item = parser.ParseSubExpression();
                list.Add(item);
                if (this.close.Equals(it.PeekNext()))
                {
                    it.Consume();
                    if (!pfmc.CheckNumberOfParameters(list.Count))
                    {
                        throw new Colosoft.Text.Jep.ParseException(string.Concat(new object[] {
                            "Function ",
                            pfmc,
                            " invalid number of arguments ",
                            list.Count
                        }));
                    }
                    return(this.nf.BuildFunctionNode(source, pfmc, list.ToArray()));
                }
                if (!this.comma.Equals(it.PeekNext()))
                {
                    break;
                }
                it.Consume();
            }
            throw new Colosoft.Text.Jep.ParseException("Closing bracket not found. Next token is " + it.PeekNext());
        }
Exemple #4
0
        public INode Match(Lookahead2Enumerator <Token> it, IGrammarParser parser)
        {
            if (!this.open.Equals(it.PeekNext()))
            {
                return(null);
            }
            it.Consume();
            INode node = parser.ParseSubExpression();

            if (!this.close.Equals(it.PeekNext()))
            {
                throw new Colosoft.Text.Jep.ParseException("Closing bracket not found");
            }
            it.Consume();
            return(node);
        }
Exemple #5
0
        public static void Main(string[] args)
        {
            GrammarContainer grammarContainer = new GrammarContainer("EnglishGrammar.json");

            IWordDataReader reader = new English1WordDataReader("english.txt", grammarContainer.ReplaceIdentifiers);

            IDictionary dict = new DefaultDictionary();

            int i = 0;
            English1GrammarFactory factory = new English1GrammarFactory(grammarContainer, new WordIdCounter(1));

            IGrammarParser grammar = factory.CreateGrammar();

            foreach (IWordData wordCorpus in reader)
            {
                IList <IWord> words = grammar.Parse(wordCorpus);

                foreach (IWord word in words)
                {
                    dict.AddWord(word);
                }
                //PrintWordData (words);

                if (i++ == 100)
                {
                    IList <IWord> postProcessed = grammar.PostProcess();

                    //PrintWordData (postProcessed);

                    dict.Print();
                    Environment.Exit(0);
                }
            }

            Console.WriteLine("done: " + i);
        }