Exemplo n.º 1
0
/**
 * non-declaration statement
 */
do_statement () {
        if (amatch ("if", 2)) {
                doif ();
                lastst = STIF;
        } else if (amatch ("while", 5)) {
                dowhile ();
                lastst = STWHILE;
        } else if (amatch ("switch", 6)) {
                doswitch ();
                lastst = STSWITCH;
        } else if (amatch ("do", 2)) {
                dodo ();
                need_semicolon ();
                lastst = STDO;
        } else if (amatch ("for", 3)) {
                dofor ();
                lastst = STFOR;
        } else if (amatch ("return", 6)) {
                doreturn ();
                need_semicolon ();
                lastst = STRETURN;
        } else if (amatch ("break", 5)) {
                dobreak ();
                need_semicolon ();
                lastst = STBREAK;
        } else if (amatch ("continue", 8)) {
                docont ();
                need_semicolon ();
                lastst = STCONT;
        } else if (match (";"))
                ;
        else if (amatch ("case", 4)) {
                docase ();
                lastst = statement (NO);
        } else if (amatch ("default", 7)) {
                dodefault ();
                lastst = statement (NO);
        } else if (match ("__asm__")) {
                doasm ();
                lastst = STASM;
        } else if (match("#")) {
                kill();
        } else if (match ("{"))
                do_compound (NO);
        else {
                expression (YES);
/*              if (match (":")) {
                        dolabel ();
                        lastst = statement (NO);
                } else {
*/                      need_semicolon ();
                        lastst = STEXP;
/*              }
*/      }
}
Exemplo n.º 2
0
Arquivo: emit.c Projeto: a8m/c
static void
stmt(Node *n)
{
	switch(n->t){
	case NDECL:
		decl(n);
		out(".text\n");
		break;
	case NRETURN:
		ereturn(n);
		break;
	case NIF:
		eif(n);
		break;
	case NWHILE:
		ewhile(n);
		break;
	case NFOR:
		efor(n);
		break;
	case NDOWHILE:
		dowhile(n);
		break;
	case NBLOCK:
		block(n);
		break;
	case NSWITCH:
		eswitch(n);
		break;
	case NGOTO:
		outi("jmp %s\n", n->Goto.l);
		break;
	case NCASE:
		out("%s:\n", n->Case.l);
		stmt(n->Case.stmt);
		break;
	case NLABELED:
		out("%s:\n", n->Labeled.l);
		stmt(n->Labeled.stmt);
		break;
	case NEXPRSTMT:
		if(n->ExprStmt.expr)
			expr(n->ExprStmt.expr);
		break;
	default:
		errorf("unimplemented emit stmt %d\n", n->t);
	}	
}
Exemplo n.º 3
0
int stmt() { int c;
       if(istoken('{'))     {while(istoken('}')==0) stmt();}
  else if(istoken(T_IF))    doif();
  else if(istoken(T_DO))    dodo();
  else if(istoken(T_WHILE)) dowhile();
  else if(istoken(T_GOTO))  {prs("\n jmp @@");name1();prs(symbol);expect(';');}
  else if(token==T_ASM)     {prs("\n"); c=next();
    while(c != '\n') { prc(c);	c=next(); }; token=getlex(); }
  else if(istoken(T_ASMBLOCK)) {prs("\n"); expect('{'); c=next();
    while(c!= '}') { prc(c); c=next(); };   token=getlex(); }
  else if(istoken(T_EMIT))  doemit();
  else if(istoken(';'))     { }
  else if(istoken(T_RETURN)){if (token!=';') expr();
    prs("\n jmp @@retn"); nreturn++; expect(';'); }
  else if(thechar==':')     {prs("\n@@"); /*Label*/
     prs(symbol); prc(':'); expect(T_NAME); expect(':'); }
  else                      {expr(); expect(';'); } }