public virtual void AddParseResult(Production result)
 {
     ParserResult.Add(result);
 }
        public void ParseTable()
        {
            init();
            // Index for current lexical Analyze result
            int  currResultTok = 0;
            bool accepted      = false;

            ParseStack.Push(Tuple.Create(0, Token.tokens[0]));
            while (!accepted)
            {
                Token nexttok;
                if (currResultTok < Analysis.ResultTable.Count)
                {
                    nexttok = StrType.Res2Token[Analysis.ResultTable[currResultTok].type];
                }
                else
                {
                    nexttok = Token.GetToken(-1);
                }
                Tuple <Ptype, int> nextact;
                Tuple <int, Token> nexttuple = Tuple.Create(ParseStack.Peek().Item1, nexttok);
                //there is no Action in next given tuple
                if (!Action.ContainsKey(nexttuple))
                {
                    Tuple <int, Token> emptyreduce = Tuple.Create(ParseStack.Peek().Item1, Token.GetToken(-1));
                    //no empty reduce
                    if (Action.ContainsKey(emptyreduce))
                    {
                        nextact = Action[emptyreduce];
                    }
                    else
                    {
                        PanicRecover(ref currResultTok);
                        break;
                    }
                }
                else
                {
                    nextact = Action[nexttuple];
                }
                switch (nextact.Item1)
                {
                case Ptype.move:
                {
                    ParseStack.Push(Tuple.Create(nextact.Item2, nexttok));
                    ShiftToken(ref currResultTok);
                    break;
                }

                case Ptype.reduce:
                {
                    Production rule   = Production.formalGrammar[nextact.Item2];
                    int        tokNum = rule.Rules().Length;
                    while (tokNum > 0)
                    {
                        ParseStack.Pop();
                        tokNum--;
                    }
                    //top equal to -1 will not be allowded
                    if (ParseStack.Peek().Item1 == -1)
                    {
                        //error handling
                        PanicRecover(ref currResultTok);
                    }
                    //next state
                    int nextsta = ParseStack.Peek().Item1;
                    ParseStack.Push(Tuple.Create(Goto[Tuple.Create(closures[nextsta], Token.tokens[rule.Nonterminal()])], Token.tokens[rule.Nonterminal()]));
                    AddParseResult(rule);
                    break;
                }

                case Ptype.accept:
                {
                    accepted = true;
                    ResultID = ParserResult.Count - 1;
                    AcceptAction();
                    break;
                }
                }
            }
            if (afterPanicRecover)
            {
                UIHelper.Log(GeneticStringClass.ITTerminate);
                Thread.CurrentThread.Abort();
            }
        }