Esempio n. 1
0
TOKEN_T LexParser( STRM_T s )
/************************************
 * returns: next token for parser
 * remarks: possibly defines a macro
 */
{
    static BOOLEAN  atstart = TRUE;
    char            *p;

    for( ;; ) {

        if( atstart ) {
                /* atstart == TRUE if either of these succeed */
            if( isws( s ) ) {           /* cmd line */
                return( lexCmd() );
            }
            if( ismacc( s ) && checkMacro( s ) ) {  /* check if macro = body */
                s = PreGetCH();
                continue;
            }

            atstart = FALSE;
            UnGetCH( s );           /* put back our probe */
            s = STRM_MAGIC;         /* force macro expansion */
        }

        switch( s ) {
        case STRM_END:
            atstart = TRUE;
            return( TOK_END );
        case EOL:
            atstart = TRUE;
            return( TOK_EOL );
        case STRM_TMP_LEX_START:
        case STRM_MAGIC:
            p = DeMacroDoubleQuote( FALSE );  /* expand to next white space */
            if( *p == NULLCHAR ) {  /* already at ws */
                FreeSafe( p );
                s = PreGetCH();     /* eat the ws */
                while( isws( s ) ) {
                    s = PreGetCH();
                }
                if( s == EOL ) {
                    atstart = TRUE;
                    return( TOK_EOL );
                }
                if( s == STRM_END ) {
                    atstart = TRUE;
                    return( TOK_END );
                }
                UnGetCH( s );
                p = DeMacroDoubleQuote( FALSE );
            }
            UnGetCH( STRM_MAGIC );  /* mark spot we have to expand from nxt */
            InsString( p, TRUE );   /* put expansion in stream */
            break;
        case SPACE: /* fall through */
        case TAB:
            break;
        case L_CURL_PAREN:          /* could only be a sufsuf */
        case DOT:
            UnGetCH( s );
            return( lexDotName() ); /* could be a file... */
        case SEMI:                  /* treat semi-colon as {nl}{ws} */
            InsString( "\n ", FALSE );
            break;                  /* try again */
        case COLON:
            s = PreGetCH();
            if( s == COLON ) {
                return( TOK_DCOLON );
            }
            UnGetCH( s );
            return( TOK_SCOLON );
        default:
            if( isfilec( s ) || s == DOUBLEQUOTE ||
                ( (Glob.compat_nmake || Glob.compat_posix) &&  s == SPECIAL_TMP_DOL_C ) ) {
                return( lexFileName( s ) );
            }
            PrtMsg( WRN | LOC | UNKNOWN_TOKEN, s );
            break;
        }
        s = PreGetCH();             /* fetch a character */
    }
}
Esempio n. 2
0
TOKEN_T LexParser( STRM_T s )
/************************************
 * returns: next token for parser
 * remarks: possibly defines a macro
 */
{
    static bool     atstart = true;
    char            *p;

    for( ;; ) {

        if( atstart ) {
                /* atstart == true if either of these succeed */
            if( sisws( s ) ) {           /* cmd line */
                return( lexCmd() );
            }
            if( sismacc( s ) && checkMacro( s ) ) {  /* check if macro = body */
                s = PreGetCHR();
                continue;
            }

            atstart = false;
            UnGetCHR( s );           /* put back our probe */
            s = STRM_MAGIC;         /* force macro expansion */
        }

        switch( s ) {
        case STRM_END:
            atstart = true;
            return( TOK_END );
        case '\n':
            atstart = true;
            return( TOK_EOL );
        case STRM_TMP_LEX_START:
        case STRM_MAGIC:
            p = DeMacroDoubleQuote( false );  /* expand to next white space */
            if( *p == NULLCHAR ) {  /* already at ws */
                FreeSafe( p );
                s = PreGetCHR();    /* eat the ws */
                while( sisws( s ) ) {
                    s = PreGetCHR();
                }
                if( s == '\n' ) {
                    atstart = true;
                    return( TOK_EOL );
                }
                if( s == STRM_END ) {
                    atstart = true;
                    return( TOK_END );
                }
                UnGetCHR( s );
                p = DeMacroDoubleQuote( false );
            }
            UnGetCHR( STRM_MAGIC ); /* mark spot we have to expand from nxt */
            InsString( p, true );   /* put expansion in stream */
            break;
        case ' ':
        case '\t':
            break;
        case '{':                   /* could only be a sufsuf */
        case '.':
            UnGetCHR( s );
            return( lexDotName() ); /* could be a file... */
        case ';':                   /* treat semi-colon as {nl}{ws} */
            InsString( "\n ", false );
            break;                  /* try again */
        case ':':
            s = PreGetCHR();
            if( s == ':' ) {
                return( TOK_DCOLON );
            }
            UnGetCHR( s );
            return( TOK_SCOLON );
        default:
            if( sisfilec( s ) || s == '\"' || ( (Glob.compat_nmake || Glob.compat_posix) && s == SPECIAL_TMP_DOLLAR ) ) {
                return( lexFileName( s ) );
            }
            PrtMsg( WRN | LOC | UNKNOWN_TOKEN, s );
            break;
        }
        s = PreGetCHR();             /* fetch a character */
    }
}