protected void Shift(int shiftState)
 {
     if (this.Trace)
     {
         object[] str = new object[1];
         str[0] = this.TerminalToString(this._next);
         ShiftReduceParser <YYSTYPE, YYLTYPE> .TraceMsg("Shifting token {0}, ", str);
     }
     this._currentState = this.states[shiftState];
     this.valueStack.Push(this._scanner.yylval);
     this._stateStack.Push(this._currentState);
     this.locationStack.Push(this._scanner.yylloc);
     if (this._recovering)
     {
         if (this._next != this.errToken)
         {
             ShiftReduceParser <YYSTYPE, YYLTYPE> shiftReduceParser = this;
             shiftReduceParser._tokensSinceLastError = shiftReduceParser._tokensSinceLastError + 1;
         }
         if (this._tokensSinceLastError > 5)
         {
             this._recovering = false;
         }
     }
     if (this._next != this.eofToken)
     {
         this._next = 0;
     }
 }
 public bool FindErrorRecoveryState()
 {
     while (this._currentState.ParserTable == null || !this._currentState.ParserTable.ContainsKey(this.errToken) || this._currentState.ParserTable[this.errToken] <= 0)
     {
         if (this.Trace)
         {
             object[] number = new object[1];
             number[0] = this._stateStack.TopElement().Number;
             ShiftReduceParser <YYSTYPE, YYLTYPE> .TraceMsg("Error: popping state {0}", number);
         }
         this._stateStack.Pop();
         this.valueStack.Pop();
         this.locationStack.Pop();
         if (this.Trace)
         {
             this.DisplayStack();
         }
         if (!this._stateStack.IsEmpty())
         {
             this._currentState = this._stateStack.TopElement();
         }
         else
         {
             if (this.Trace)
             {
                 ShiftReduceParser <YYSTYPE, YYLTYPE> .TraceMsg("Aborting: didn't find a state that accepts error token", new object[0]);
             }
             return(false);
         }
     }
     return(true);
 }
        private void DisplayRule(int rule_nr)
        {
            object[] ruleNr = new object[1];
            ruleNr[0] = rule_nr;
            ShiftReduceParser <YYSTYPE, YYLTYPE> .TraceMsg("Reducing stack by rule {0}, ", ruleNr);

            this.DisplayProduction(this.rules[rule_nr]);
        }
        private void DisplayStack()
        {
            ShiftReduceParser <YYSTYPE, YYLTYPE> .TraceMsg("State now", new object[0]);

            for (int i = 0; i < this._stateStack.Top; i++)
            {
                object[] number = new object[1];
                number[0] = this._stateStack.Elements[i].Number;
                ShiftReduceParser <YYSTYPE, YYLTYPE> .TraceMsg(" {0}", number);
            }
        }
        public void ShiftErrorToken()
        {
            int num = this._next;

            this._next = this.errToken;
            this.Shift(this._currentState.ParserTable[this._next]);
            if (this.Trace)
            {
                object[] number = new object[1];
                number[0] = this._currentState.Number;
                ShiftReduceParser <YYSTYPE, YYLTYPE> .TraceMsg("Entering state {0} ", number);
            }
            this._next = num;
        }
 private void DisplayProduction(Rule rule)
 {
     if (rule.RightSymbols.Count != 0)
     {
         foreach (int rightSymbol in rule.RightSymbols)
         {
             object[] str = new object[1];
             str[0] = this.SymbolToString(rightSymbol);
             ShiftReduceParser <YYSTYPE, YYLTYPE> .TraceMsg("{0} ", str);
         }
     }
     else
     {
         ShiftReduceParser <YYSTYPE, YYLTYPE> .TraceMsg("/* empty */ ", new object[0]);
     }
     object[] objArray = new object[1];
     objArray[0] = this.SymbolToString(rule.LeftSymbol);
     ShiftReduceParser <YYSTYPE, YYLTYPE> .TraceMsg("-> {0}", objArray);
 }
        protected void Reduce(int reduceRule)
        {
            YYLTYPE yYLTYPE;

            if (this.Trace)
            {
                this.DisplayRule(reduceRule);
            }
            Rule rule = this.rules[reduceRule];

            if (rule.RightSymbols.Count != 1)
            {
                this.yyval = default(YYSTYPE);
            }
            else
            {
                this.yyval = this.valueStack.TopElement();
            }
            if (rule.RightSymbols.Count != 1)
            {
                if (rule.RightSymbols.Count != 0)
                {
                    YYLTYPE item     = this.locationStack.Elements[this.locationStack.Top - rule.RightSymbols.Count];
                    YYLTYPE yYLTYPE1 = this.locationStack.TopElement();
                    if (item != null && yYLTYPE1 != null)
                    {
                        this.yyloc = item.Merge(yYLTYPE1);
                    }
                }
                else
                {
                    ShiftReduceParser <YYSTYPE, YYLTYPE> shiftReduceParser = this;
                    if (this._scanner.yylloc != null)
                    {
                        yYLTYPE = this._scanner.yylloc.Merge(this.lastL);
                    }
                    else
                    {
                        YYLTYPE yYLTYPE2 = default(YYLTYPE);
                        yYLTYPE = yYLTYPE2;
                    }
                    shiftReduceParser.yyloc = yYLTYPE;
                }
            }
            else
            {
                this.yyloc = this.locationStack.TopElement();
            }
            this.DoAction(reduceRule);
            for (int i = 0; i < rule.RightSymbols.Count; i++)
            {
                this._stateStack.Pop();
                this.valueStack.Pop();
                this.locationStack.Pop();
            }
            if (this.Trace)
            {
                this.DisplayStack();
            }
            this._currentState = this._stateStack.TopElement();
            if (this._currentState.GoTo.ContainsKey(rule.LeftSymbol))
            {
                this._currentState = this.states[this._currentState.GoTo[rule.LeftSymbol]];
            }
            this._stateStack.Push(this._currentState);
            this.valueStack.Push(this.yyval);
            this.locationStack.Push(this.yyloc);
        }
        public bool Parse()
        {
            int defaultAction;

            this.Initialize();
            this._next         = 0;
            this._currentState = this.states[0];
            this._stateStack.Push(this._currentState);
            this.valueStack.Push(this.yyval);
            this.locationStack.Push(this.yyloc);
            do
            {
Label0:
                if (this.Trace)
                {
                    object[] number = new object[1];
                    number[0] = this._currentState.Number;
                    ShiftReduceParser <YYSTYPE, YYLTYPE> .TraceMsg("Entering state {0} ", number);
                }
                defaultAction = this._currentState.DefaultAction;
                if (this._currentState.ParserTable != null)
                {
                    if (this._next == 0)
                    {
                        if (this.Trace)
                        {
                            ShiftReduceParser <YYSTYPE, YYLTYPE> .TraceMsg("Reading a token: ", new object[0]);
                        }
                        this.lastL = this._scanner.yylloc;
                        this._next = this._scanner.yylex();
                    }
                    if (this.Trace)
                    {
                        object[] str = new object[1];
                        str[0] = this.TerminalToString(this._next);
                        ShiftReduceParser <YYSTYPE, YYLTYPE> .TraceMsg("Next token is {0}", str);
                    }
                    if (this._currentState.ParserTable.ContainsKey(this._next))
                    {
                        defaultAction = this._currentState.ParserTable[this._next];
                    }
                }
                if (defaultAction <= 0)
                {
                    if (defaultAction >= 0)
                    {
                        continue;
                    }
                    this.Reduce(-defaultAction);
                    if (defaultAction == -1)
                    {
                        return(true);
                    }
                    else
                    {
                        goto Label0;
                    }
                }
                else
                {
                    this.Shift(defaultAction);
                    goto Label0;
                }
            }while (defaultAction != 0 || this.ErrorRecovery());
            return(false);
        }
        public bool DiscardInvalidTokens()
        {
            int defaultAction = this._currentState.DefaultAction;

            if (this._currentState.ParserTable == null)
            {
                if (!this._recovering || this._tokensSinceLastError != 0)
                {
                    return(true);
                }
                else
                {
                    if (this.Trace)
                    {
                        object[] str = new object[1];
                        str[0] = this.TerminalToString(this._next);
                        ShiftReduceParser <YYSTYPE, YYLTYPE> .TraceMsg("Error: panic discard of {0}", str);
                    }
                    this._next = 0;
                    return(true);
                }
            }
            else
            {
                while (true)
                {
                    if (this._next == 0)
                    {
                        if (this.Trace)
                        {
                            ShiftReduceParser <YYSTYPE, YYLTYPE> .TraceMsg("Reading a token: ", new object[0]);
                        }
                        this._next = this._scanner.yylex();
                    }
                    if (this.Trace)
                    {
                        object[] objArray = new object[1];
                        objArray[0] = this.TerminalToString(this._next);
                        ShiftReduceParser <YYSTYPE, YYLTYPE> .TraceMsg("Next token is {0}", objArray);
                    }
                    if (this._next == this.eofToken)
                    {
                        return(false);
                    }
                    if (this._currentState.ParserTable.ContainsKey(this._next))
                    {
                        defaultAction = this._currentState.ParserTable[this._next];
                    }
                    if (defaultAction != 0)
                    {
                        break;
                    }
                    if (this.Trace)
                    {
                        object[] str1 = new object[1];
                        str1[0] = this.TerminalToString(this._next);
                        ShiftReduceParser <YYSTYPE, YYLTYPE> .TraceMsg("Error: Discarding {0}", str1);
                    }
                    this._next = 0;
                }
                return(true);
            }
        }