Esempio n. 1
0
void prettyFORINIT(int indent, FORINIT *forinit)
{
  switch (forinit->kind) {
  case declforinitK:
    prettyDECL(indent, forinit->val.declforinitF);
    break;
  case expforinitK:
    prettyEXP(forinit->val.expforinitF);
    break;
  }
  
  if (forinit->next != NULL) {
    printf(",");
    prettyFORINIT(indent, forinit->next);
  }
}
Esempio n. 2
0
void prettySTM(int indent, STM *stm)
{
  switch (stm->kind) {
    case skipK:
      indentprintf(indent, ";\n");
      break;
    case expK:
      indentprintf(indent, "");
      prettyEXP(stm->val.expS);
      printf(";\n");
      break;
     case declstmK:
      prettyDECL(indent, stm->val.declstmS);
      break;
    case returnK:
      indentprintf(indent, "return ");
      if (stm->val.returnS.exp != NULL)
        prettyEXP(stm->val.returnS.exp);
      printf(";\n");
      break;
    case ifK:
      indentprintf(indent, "if (");
      prettyEXP(stm->val.ifS.condition);
      printf(")");
      prettySTM(indent, stm->val.ifS.body);
      break;
    case ifelseK:
      indentprintf(indent, "if (");
      prettyEXP(stm->val.ifelseS.condition);
      printf(")");
      prettySTM(indent, stm->val.ifelseS.thenpart);
      indentprintf(indent, " else ");
      prettySTM(indent, stm->val.ifelseS.elsepart);
      break;
    case whileK:
      indentprintf(indent, "while (");
      prettyEXP(stm->val.whileS.condition);
      printf(") ");
      prettySTM(indent, stm->val.whileS.body);
      break;
    case forK:
      indentprintf(indent, "for (");
      prettyFORINIT(indent, stm->val.forS.inits);
      printf("; ");
      prettyEXP(stm->val.forS.condition);
      printf("; ");
      prettyEXP(stm->val.forS.updates);
      printf(") ");
      prettySTM(indent, stm->val.forS.body);
      break;
  case sequenceK:
      prettySTM(indent, stm->val.sequenceS.first);
      prettySTM(indent, stm->val.sequenceS.second);
      break;
  case scopeK:
      printf("\n");
      indentprintf(indent, "{ /* new scope */\n");
      #if (PRINTSYMBOL)
        prettySymbolTable(indent+2, stm->val.scopeS.sym);
      #endif
      prettySTM(indent+1, stm->val.scopeS.stm);
      indentprintf(indent, "}\n");
      break;
  case setintK:
      indentprintf(indent,"setint(");
      prettyEntity(stm->val.setintS.kind);
      printf(", ");
      prettyEXP(stm->val.setintS.modelname);
      printf(",");      
      prettyEXP(stm->val.setintS.nr);
      printf(",");
      prettyEXP(stm->val.setintS.val);
      printf(")");
      break;
  case sleepK:
      indentprintf(indent,"sleep(");
      prettyEXP(stm->val.sleepS.time);
      printf(")"); 
      break;
   }
}
void prettySTM(int indent, STM *stm)
{
	switch (stm->kind) {
    case skipK:
		indentprintf(indent, ";\n");
		break;
    case expK:
		indentprintf(indent, "");
		prettyEXP(stm->val.expS);
		printf(";\n");
		break;
	case declstmK:
		prettyDECL(indent, stm->val.declstmS);
		break;
    case returnK:
		indentprintf(indent, "return ");
		if (stm->val.returnS.exp != NULL)
			prettyEXP(stm->val.returnS.exp);
		printf(";\n");
		break;
    case ifK:
		indentprintf(indent, "if (");
		prettyEXP(stm->val.ifS.condition);
		printf(")");
		prettySTM(indent, stm->val.ifS.body);
		break;
    case ifelseK:
		indentprintf(indent, "if (");
		prettyEXP(stm->val.ifelseS.condition);
		printf(")");
		prettySTM(indent, stm->val.ifelseS.thenpart);
		indentprintf(indent, " else ");
		prettySTM(indent, stm->val.ifelseS.elsepart);
		break;
    case whileK:
		indentprintf(indent, "while (");
		prettyEXP(stm->val.whileS.condition);
		printf(") ");
		prettySTM(indent, stm->val.whileS.body);
		break;
    case forK:
		indentprintf(indent, "for (");
		prettyFORINIT(indent, stm->val.forS.inits);
		printf("; ");
		prettyEXP(stm->val.forS.condition);
		printf("; ");
		prettyEXP(stm->val.forS.updates);
		printf(") ");
		prettySTM(indent, stm->val.forS.body);
		break;
	case sequenceK:
		prettySTM(indent, stm->val.sequenceS.first);
		prettySTM(indent, stm->val.sequenceS.second);
		break;
	case scopeK:
		printf("\n");
		indentprintf(indent, "{ /* new scope */\n");
		prettySTM(indent+1, stm->val.scopeS.stm);
		indentprintf(indent, "}\n");
		break;
	case sleepK:
		indentprintf(indent,"sleep(");
		prettyEXP(stm->val.sleepS.time);
		printf(")"); 
		break;
	case breakK:
		indentprintf(indent,"break;\n");
		break;
	case continueK:
		indentprintf(indent,"continue;\n");
		break;
	}
}