Antlr.Runtime.LegacyCommonTokenStream.LB C# (CSharp) Method

LB() protected method

Look backwards k tokens on-channel tokens
protected LB ( int k ) : IToken
k int
return IToken
        protected virtual IToken LB( int k )
        {
            //System.out.print("LB(p="+p+","+k+") ");
            if ( p == -1 )
            {
                FillBuffer();
            }
            if ( k == 0 )
            {
                return null;
            }
            if ( ( p - k ) < 0 )
            {
                return null;
            }

            int i = p;
            int n = 1;
            // find k good tokens looking backwards
            while ( n <= k )
            {
                // skip off-channel tokens
                i = SkipOffTokenChannelsReverse( i - 1 ); // leave p on valid token
                n++;
            }
            if ( i < 0 )
            {
                return null;
            }
            return (IToken)tokens[i];
        }