[antlr-interest] regarding substring error

J.R Karthikeyan jrk1987 at yahoo.co.in
Mon Aug 23 11:28:09 PDT 2010


Hi,

  I have used the token STRING whose definition is 

fragment
QUOTE    :    '\"'
    ;
    
STRING    :    QUOTE (options {greedy=false;} : .)* QUOTE { 
setText(getText().substring(0, getText().length())); }
    ;

I generated the C code and I tried to compile with visual studio. Without this 
STRING token definition it is working fine. But when I include this token 
definition it is giving the compilation error as below

Error    7    error C2224: left of '.substring' must have struct/union type    
c:\documents and settings\kjambura\my documents\visual studio 
2005\projects\wrap\wrap\project1lexer.c    3210    


Error    8    error C2224: left of '.length' must have struct/union type    
c:\documents and settings\kjambura\my documents\visual studio 
2005\projects\wrap\wrap\project1lexer.c    3210    


those lines are in Lexer file (highlighted in red)

void mSTRING(pproject1Lexer ctx)
{
    ANTLR3_UINT32    _type;

    _type        = STRING;
       
    
    // C:\\Documents and Settings\\kjambura\\My 
Documents\\parser\\project1.g:243:8: ( QUOTE ( options {greedy=false; } : . )* 
QUOTE )
    // C:\\Documents and Settings\\kjambura\\My 
Documents\\parser\\project1.g:243:10: QUOTE ( options {greedy=false; } : . )* 
QUOTE
    {
        /* 243:10: QUOTE ( options {greedy=false; } : . )* QUOTE */
        mQUOTE(ctx ); 
        if  (HASEXCEPTION())
        {
            goto ruleSTRINGEx;
        }


        // C:\\Documents and Settings\\kjambura\\My 
Documents\\parser\\project1.g:243:16: ( options {greedy=false; } : . )*

        for (;;)
        {
            int alt10=2;
            {
               /* 
dfaLoopbackState(k,edges,eotPredictsAlt,description,stateNumber,semPredState)
                */
                int LA10_0 = LA(1);
                if ( (LA10_0 == '"') ) 
                {
                    alt10=2;
                }
                else if ( (((LA10_0 >= 0x0000) && (LA10_0 <= '!')) || ((LA10_0 
>= '#') && (LA10_0 <= 0xFFFF))) ) 

                {
                    alt10=1;
                }

            }
            switch (alt10) 
            {
            case 1:
                // C:\\Documents and Settings\\kjambura\\My 
Documents\\parser\\project1.g:243:43: .
                {
                    MATCHANY(); 
                    if  (HASEXCEPTION())
                    {
                        goto ruleSTRINGEx;
                    }


                }
                break;

            default:
                goto loop10;    /* break out of the loop */
                break;
            }
        }
        loop10: ; /* Jump out to here if this rule does not match */

        /* 243:10: QUOTE ( options {greedy=false; } : . )* QUOTE */
        mQUOTE(ctx ); 
        if  (HASEXCEPTION())
        {
            goto ruleSTRINGEx;
        }

        {
            
             setText(getText().substring(0, getText().length())); 
        }

    }

    LEXSTATE->type = _type;

    // This is where rules clean up and exit
    //
    goto ruleSTRINGEx; /* Prevent compiler warnings */
    ruleSTRINGEx: ;

}

Can you please suggest me how to deal with this error.


Thanks,
Jrk




More information about the antlr-interest mailing list