FictionTools/z88dk/src/sccz80/stmt.c
/*
 *      Statement parser
 *
 * called whenever syntax requires a statement.
 * this routine performs that statement
 * and returns a number telling which one
 */
Statement parser
called whenever syntax requires a statement.
this routine performs that statement
and returns a number telling which one
Statement parser called whenever syntax requires a statement . this routine performs that statement and returns a number telling which one
int statement()
{
    int st;
    int locstatic; 
    blanks();
    if (lineno != lastline) {
        lastline = lineno;
        EmitLine(lineno);
    }
    if (ch() == 0 && eof) {
        return (lastst = STEXP);
    } else {
        if (amatch("extern")) {
            dodeclare(EXTERNAL);
            return lastst;
        }
        swallow("register");
        swallow("auto");
        locstatic = amatch("static");
        if ( declare_local(locstatic) ) {
            return lastst;
        }        
        if (declared >= 0) {
            Zsp = modstk(Zsp - declared, KIND_NONE, NO, YES);
            declared = 0;
        }
        st = -1;
        switch (ch()) {
        case '{':
            inbyte();
            compound();
            st = lastst;
            break;
        case 'i':
            if (amatch("iferror")) {
                doiferror();
                st = STIF;
            } else if (amatch("if")) {
                doif();
                st = STIF;
            }
            break;
        case 'w':
            if (amatch("while")) {
                dowhile();
                st = STWHILE;
            }
            break;
        case 'd':
            if (amatch("do")) {
                dodo();
                st = STDO;
            } else if (amatch("default")) {
                dodefault();
                st = STDEF;
            }
            break;
        case 'f':
            if (amatch("for")) {
                dofor();
                st = STFOR;
            }
            break;
        case 's':
            if (amatch("switch")) {
                doswitch();
                st = STSWITCH;
            }
            break;
        case 'c':
            if (amatch("case")) {
                docase();
                st = STCASE;
            } else if (amatch("continue")) {
                docont();
                ns();
                st = STCONT;
            }
            break;
        case 'r':
            if (amatch("return")) {
                doreturn(0);
                ns();
                st = STRETURN;
            } else if (amatch("return_c")) {
                doreturn(1);
                ns();
                st = STRETURN;
            } else if (amatch("return_nc")) {
                doreturn(2);
                ns();
                st = STRETURN;
            }
            break;
        case 'b':
            if (amatch("break")) {
                dobreak();
                ns();
                st = STBREAK;
            }
            break;
        case ';':
            inbyte();
            st = lastst;
            break;
        case 'a':
            if (amatch("asm")) {
                doasmfunc(YES);
                ns();
                st = STASM;
            }
            break;
        case 'g':
            if (amatch("goto")) {
                dogoto();
                ns();
                st = STGOTO;
            }
            break;
        case '#':
            if (match("#asm")) {
                doasm();
                st = STASM;
            }
            break;
        case '_':
            if (match("_Static_assert")) {
                dostaticassert();
                st = STASSERT;
            } else if (match("__critical")) {
                docritical();
                st = STCRITICAL;
            }
        }
        if (st == -1) {
            if (dolabel() == 0) {
                doexpr();
                ns();
            }
            st = STEXP;
        }
    }
    return (lastst = st);
}
int statement ( ) { int st ; int locstatic ; blanks ( ) ; if ( lineno != lastline ) { lastline = lineno ; EmitLine ( lineno ) ; } if ( ch ( ) == 0 && eof ) { return ( lastst = STEXP ) ; } else { if ( amatch ( " " ) ) { dodeclare ( EXTERNAL ) ; return lastst ; } swallow ( " " ) ; swallow ( " " ) ; locstatic = amatch ( " " ) ; if ( declare_local ( locstatic ) ) { return lastst ; } if ( declared >= 0 ) { Zsp = modstk ( Zsp - declared , KIND_NONE , NO , YES ) ; declared = 0 ; } st = -1 ; switch ( ch ( ) ) { case ' ' : inbyte ( ) ; compound ( ) ; st = lastst ; break ; case ' ' : if ( amatch ( " " ) ) { doiferror ( ) ; st = STIF ; } else if ( amatch ( " " ) ) { doif ( ) ; st = STIF ; } break ; case ' ' : if ( amatch ( " " ) ) { dowhile ( ) ; st = STWHILE ; } break ; case ' ' : if ( amatch ( " " ) ) { dodo ( ) ; st = STDO ; } else if ( amatch ( " " ) ) { dodefault ( ) ; st = STDEF ; } break ; case ' ' : if ( amatch ( " " ) ) { dofor ( ) ; st = STFOR ; } break ; case ' ' : if ( amatch ( " " ) ) { doswitch ( ) ; st = STSWITCH ; } break ; case ' ' : if ( amatch ( " " ) ) { docase ( ) ; st = STCASE ; } else if ( amatch ( " " ) ) { docont ( ) ; ns ( ) ; st = STCONT ; } break ; case ' ' : if ( amatch ( " " ) ) { doreturn ( 0 ) ; ns ( ) ; st = STRETURN ; } else if ( amatch ( " " ) ) { doreturn ( 1 ) ; ns ( ) ; st = STRETURN ; } else if ( amatch ( " " ) ) { doreturn ( 2 ) ; ns ( ) ; st = STRETURN ; } break ; case ' ' : if ( amatch ( " " ) ) { dobreak ( ) ; ns ( ) ; st = STBREAK ; } break ; case ' ' : inbyte ( ) ; st = lastst ; break ; case ' ' : if ( amatch ( " " ) ) { doasmfunc ( YES ) ; ns ( ) ; st = STASM ; } break ; case ' ' : if ( amatch ( " " ) ) { dogoto ( ) ; ns ( ) ; st = STGOTO ; } break ; case ' ' : if ( match ( " " ) ) { doasm ( ) ; st = STASM ; } break ; case ' ' : if ( match ( " " ) ) { dostaticassert ( ) ; st = STASSERT ; } else if ( match ( " " ) ) { docritical ( ) ; st = STCRITICAL ; } } if ( st == -1 ) { if ( dolabel ( ) == 0 ) { doexpr ( ) ; ns ( ) ; } st = STEXP ; } } return ( lastst = st ) ; }
Statement parser
 called whenever syntax requires a statement.
Statement parser called whenever syntax requires a statement .
/* have we had the static keyword */ /* Ignore the register and auto keywords! */ /* Check to see if specified as static, and also for far and near */ /* not a definition */ /* if nothing else, assume it's an expression */