Пример #1
0
SNODE    *switchstmt(void) 
/*
 * Handle the SWITCH statement
 */
{       SNODE    *snp; 
        SNODE    *head, *tail; 
				TYP *tp;
				SNODE *lst = 0;
				int ogc = goodcode,oswb=switchbreak;
	TABLE oldoldlsym;
	switchbreak = 0;
#ifdef CPLUSPLUS
	if (prm_cplusplus) {
		oldoldlsym = oldlsym;
		oldlsym = lsyms;
	}
#endif
        snp = xalloc(sizeof(SNODE)); 
				snp->next = 0;
        snp->stype = st_switch; 
        getsym(); 
        needpunc(openpa,0); 
				tp = doassign(&snp->exp,TRUE,0);
				if (tp) {
					switch  (tp->type) {
						case bt_char:
						case bt_unsignedchar:
						case bt_short:
						case bt_unsignedshort:
						case bt_long:
						case bt_unsigned:
						case bt_enum:
							break;
						default:
							generror(ERR_SWITCHINT,0,0);
					}
				}
        needpunc(closepa, skm_closepa); 
        needpunc(begin,0); 
        head = 0; 
				goodcode |= GF_UNREACH;
				goodcode &= ~GF_DEF;
				if (lastst == id)
					if (lastch == ':')
						lst = labelstmt(FALSE);
        while( lastst != end && lastst != eof) { 
								goodcode &= ~(GF_RETURN | GF_BREAK | GF_CONTINUE | GF_GOTO);
                if( head == 0 ) 
                        head = tail = casestmt(lst); 
                else    { 
                        tail->next = casestmt(lst); 
                        if( tail->next != 0 ) 
                                tail = tail->next; 
                        } 
								lst = 0;
								if (tail)
                	tail->next = 0; 
                } 
				if (!switchbreak && goodcode & GF_RETURN) {
					if ((goodcode & GF_UNREACH)  && (goodcode & GF_DEF)) 
						ogc |= GF_RETURN;
				}
				goodcode = ogc;
        snp->s1 = head; 
        getsym(); 
        checkcases(head);
				switchbreak = oswb;
#ifdef CPLUSPLUS
	if (prm_cplusplus) {
		check_funcused(&oldlsym,&lsyms);
		gather_labels(&oldlsym,&lsyms);
		cseg();
		lsyms = oldlsym;
		oldlsym.head = oldoldlsym.head;
	}
#endif
        return snp; 
} 
Пример #2
0
/* statements:
 * 		stmt ->   beginblock
 */
void
stmt (void)
{
    {printf("\t<stm.asm.list>\n");}
    
  switch (lookahead)
    {
    case BEGIN:
      beginblock ();
      break;
/* 			| ifstmt  	 */

    case IF:
      ifstmt ();
      break;
/* 			| whlstmt  	 */
    case WHILE:
      whlstmt ();
      break;
/* 			| repstmt  	 */
    case REPEAT:
      repstmt ();
      break;
/* 			| forstmt  	 */
    case FOR:
      forstmt ();
      break;
/*  			| casestmt  	 */
    case CASE:
      casestmt ();
      break;
/* 			| prccall    	 */
/*			| assgstm    	 */
    case ID:
      
      /*ação semântica*/   
      {printf("\t<idstm.asm.list>\n");}   
         
      match (ID);
      if (lookahead == '[' || lookahead == ASGNM)
	{
	  while (lookahead == '[')
	    {
	      idxsynt ();
	    }
	  /* ':=' == ASGNM */
	  match (ASGNM);
	  expr ();
	}
      else
	{
	  if (lookahead == '(')
	    {
	      match ('(');
	      exprlist ();
	      match (')');
	    }
	}
      break;
      /*                     | ""
       */
    default:
      ;
    }				/*end switch */
}