コード例 #1
0
static pANTLR3_COMMON_TOKEN
LB(pANTLR3_COMMON_TOKEN_STREAM cts, ANTLR3_INT32 k)
{
    ANTLR3_INT32 i;
    ANTLR3_INT32 n;

    if (cts->p == -1)
    {
        fillBuffer(cts);
    }
    if (k == 0)
    {
        return NULL;
    }
    if ((cts->p - k) < 0)
    {
        return NULL;
    }

    i = cts->p;
    n = 1;

    /* Need to find k good tokens, going backwards, skipping ones that are off channel
     */
    while (n <= (ANTLR3_INT32) k)
    {
        /* Skip off-channel tokens
         */

        i = skipOffTokenChannelsReverse(cts, i - 1); /* leave p on valid token    */
        n++;
    }
    if (i < 0)
    {
        return NULL;
    }
	// Here the token must be in the input vector. Rather then incut
	// function call penalty, we jsut return the pointer directly
	// from the vector
	//
	return  (pANTLR3_COMMON_TOKEN)cts->tokens->elements[i].element;
}
コード例 #2
0
static	pANTLR3_COMMON_TOKEN
LB  (pANTLR3_COMMON_TOKEN_STREAM cts, ANTLR3_INT32 k)
{
    ANTLR3_INT32    i;
    ANTLR3_INT32    n;

    if	(cts->p == -1)
    {
	fillBuffer(cts);
    }
    if	(k == 0)
    {
	return NULL;
    }
    if	((cts->p - k) < 0)
    {
	return NULL;
    }

    i	= cts->p;
    n	= 1;

    /* Need to find k good tokens, going backwards, skipping ones that are off channel
     */
    while   (  n <= (ANTLR3_INT32)k )
    {
	/* Skip off-channel tokens 
	 */

	i = skipOffTokenChannelsReverse(cts, i-1); /* leave p on valid token    */
	n++;
    }
    if	( i <0 )
    {
	return	NULL;
    }

    return  (pANTLR3_COMMON_TOKEN)cts->tokens->get(cts->tokens, i);
}