Exemplo n.º 1
0
void LexTest (char *filename)
{
    ReadSourceFile (filename);

    PRINT ("LexTest start... \n");
    SetupLexer ();
    int tok = 0;

    SkipWhiteSpace ();
    while (1) {

        tok = Scanners[*CURRENT]();
        if (TK_END == tok) break;
        
            PRINT ("%-8s|(%d, %d) ", TokenString[tok], 
            TokenCoord.line, TokenCoord.col);
            if (TK_ID == tok) 
                PRINT ("%s", (char*)TokenValue.p);
            PRINT ("\n");
    }

    PRINT ("词法分析结束\n");
    PRINT ("LexTest end... \n");

    CloseSourceFile ();
}
Exemplo n.º 2
0
/* 文件扫描结束处理函数 */
static int ScanEOF (void) 
{
    Include p = POP_ITEM (InLink);

    if ( endifCnt > 0 )
        Error (&TokenCoord, "lack endif");

    if ( NULL == p ) {

        return TK_END;
    }

    if ( false == p->isDef )
        CloseSourceFile ();
    else 
        Input.base[Input.size] = 0;

    /* 处理完了include 文件 */
    Input = p->PreInput;
    TokenCoord = p->PreTokenCoord;
    endifCnt = p->endifCnt;

    if (Input.importRbrace) {
     
        if ('}' == *CURRENT) {

            CURRENT++;
            Input.importRbrace -= 1;
        } else
            ImportLoadFile ();
    }

    return GetNextToken ();
}
Exemplo n.º 3
0
/*
// LoadInclude
//
// Processes a #include command
//
// Returns 1 on success, 0 on error
*/
static int LoadInclude( SOURCEFILE *ps, char *Src )
{
    char c,term;
    char NewFileName[SOURCE_BASE_DIR];
    int  rc,idx,oldidx,srcIdx;
    SOURCEFILE *psNew;

    srcIdx=0;

    /* Remove leading white space */
    do
    {
        c = Src[srcIdx++];
    } while( c==' ' || c==0x9 );

    /* Charater must be '"' or '<' */
    if( c=='"' )
    {
        term = '"';
        strcpy( NewFileName, ps->SourceBaseDir );
        idx = strlen(NewFileName);
    }
    else if( c=='<' )
    {
        term = '>';
        idx=0;
    }
    else
        { Report(ps,REP_ERROR,"Expected \" or < after #include"); return(0); }

    /* Read in the filename to the terminating character */
    // Check for include paths that start with "/" or "\"
    // (assume an absolute path)
    if( Src[srcIdx]=='/' || Src[srcIdx]=='\\' )
        idx = 0;
    oldidx = idx;
    for(;;)
    {
        c = Src[srcIdx++];
        // Check for include paths that include a ":"
        // (assume a driver letter preceeded)
        if( c==':' && idx>0 )
        {
            NewFileName[0]=NewFileName[idx-1];
            idx = 1;
            oldidx = idx;
        }
        if( c==term )
            break;
        if( !c )
            { Report(ps,REP_ERROR,"Bad filename in #include"); return(0); }
        if( idx >= (SOURCE_BASE_DIR-1) )
            { Report(ps,REP_ERROR,"Filename too long in #include"); return(0); }
        NewFileName[idx++]=c;
    }

    /* The line should be done now */
    if( Src[srcIdx] )
        { Report(ps,REP_ERROR,"Expected EOL after '%s'",NewFileName); return(0); }

    /* Null terminate the filename and make sure something got copied */
    NewFileName[idx]=0;
    if( idx == oldidx )
        { Report(ps,REP_ERROR,"Null filename in #include"); return(0); }

    /* Open the new file */
    if( !(psNew=InitSourceFile(ps, NewFileName)) )
        return(0);

    /* Process the new file */
    rc = ProcessSourceFile( psNew );

    /* Free the file block */
    CloseSourceFile( psNew );

    if( !rc && Pass==2 )
        return(0);
    else
        return(1);
}