void prettyEVENT(int indent, EVENT *event)
{
	indentprintf(indent, "");
	//prettyTYPE(function->type);
	printf("on \"%s\"",event->name);
	indentprintf(indent, "{\n");
	if (event->stms != NULL)
		prettySTM(indent+1, event->stms);
	indentprintf(indent, "}\n");
}
void prettyFUNCTION(int indent, FUNCTION *function)
{
	indentprintf(indent, "");
	//prettyTYPE(function->type);
	printf("function %s(",function->name);
	if (function->formals != NULL)
		prettyDECL(indent, function->formals);
	printf(")\n");
	indentprintf(indent, "{\n");
	if (function->stms != NULL)
		prettySTM(indent+1, function->stms);
	indentprintf(indent, "}\n");
}
Ejemplo n.º 3
0
void prettyCOMPOUNDSTM(COMPOUNDSTM* c)
{
    if(c == NULL) return;
    /* newline(); */
    fprintf(ofile, "{");
    indent++;
    newline();
    prettyVARIABLE(c->variable);
    prettySTM(c->stm);
    indent--;
    newline();
    fprintf(ofile, "}");
}
Ejemplo n.º 4
0
void prettyPROGRAM(int indent, PROGRAM *program)
{
  indentprintf(indent, "program %s ",program->name);
  if (program->trigger != NULL)
   prettyTRIGGER(program->trigger);
  printf("\n");
 
  indentprintf(indent, "{\n");
  #if (PRINTSYMBOL)
    prettySymbolTable(indent+1, program->sym);
  #endif
  if (program->stms != NULL)
    prettySTM(indent+1, program->stms);
  indentprintf(indent, "}\n");
}
Ejemplo n.º 5
0
void prettyFUNCTION(int indent, FUNCTION *function)
{
  indentprintf(indent, "");
  prettyTYPE(function->type);
  printf("%s(",function->name);
  if (function->formals != NULL)
    prettyDECL(indent, function->formals);
  printf(")\n");
  indentprintf(indent, "{\n");
  #if (PRINTSYMBOL)
    prettySymbolTable(indent+1, function->sym);
  #endif
  if (function->stms != NULL)
    prettySTM(indent+1, function->stms);
  indentprintf(indent, "}\n");
}
void prettyTOPLEVEL(int indent, TOPLEVEL *toplevel)
{
	
	switch(toplevel->kind){
	case functionK:
		prettyFUNCTION(indent, toplevel->val.functionT);
		break;
	case eventK:
		prettyEVENT(indent, toplevel->val.eventT);
		break;
	case stmsK:
		prettySTM(indent, toplevel->val.stms);
		break;
	}
	
	if(toplevel->next != NULL) {
		indentprintf(indent, "\n");
		prettyTOPLEVEL(indent, toplevel->next);
	}
}
Ejemplo n.º 7
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;
	}
}
Ejemplo n.º 9
0
void prettySTM(STM* s)
{
    int myindent;
    if(s == NULL) return;
    if(s->next != NULL)
    {
        prettySTM(s->next);
        newline();
    }
    myindent = indent;
    
    switch(s->kind) {
        case semicolonK:
            fprintf(ofile, ";");
            /* newline(); */
            break;
        case showK:
            fprintf(ofile, "show ");
            prettyDOCUMENT(s->val.showE.doc);
            if(s->val.showE.rec != NULL)
            {
                prettyRECEIVE(s->val.showE.rec);
            }
            fprintf(ofile, ";");
            /* newline(); */
            break;
        case exitK:
            fprintf(ofile, "exit ");
            prettyDOCUMENT(s->val.doc);
            fprintf(ofile, ";");
            /* newline(); */
            break;
        case returnK:
            fprintf(ofile, "return;");
            /* newline(); */
            break;
        case returnexprK:
            fprintf(ofile, "return ");
            prettyEXP(s->val.expr);
            fprintf(ofile, ";");
            /* newline(); */
            break;
        case ifK:
            fprintf(ofile, "if(");
            prettyEXP(s->val.ifE.expr);
            fprintf(ofile, ")");
            if(s->val.ifE.stm != NULL && s->val.ifE.stm->kind != compoundK)
                indent++;
            newline();
            prettySTM(s->val.ifE.stm);
            break;
        case ifelseK:
            fprintf(ofile, "if(");
            prettyEXP(s->val.ifelseE.expr);
            fprintf(ofile, ")");
            if(s->val.ifelseE.stm1 != NULL && s->val.ifelseE.stm1->kind != compoundK)
                indent++;
            newline();
            prettySTM(s->val.ifelseE.stm1);
            indent = myindent;
            newline();
            fprintf(ofile, "else");
            if(s->val.ifelseE.stm2 != NULL)
            {
                if(s->val.ifelseE.stm2->kind == ifK || s->val.ifelseE.stm2->kind == ifelseK)
                    fprintf(ofile, " ");
                else if(s->val.ifelseE.stm2->kind != compoundK)
                {
                    indent++;
                    newline();
                }
            }
            prettySTM(s->val.ifelseE.stm2);
            break;
        case whileK:
            fprintf(ofile, "while(");
            prettyEXP(s->val.whileE.expr);
            fprintf(ofile, ")");
            if(s->val.whileE.stm != NULL && s->val.whileE.stm->kind != compoundK)
                indent++;
            newline();
            prettySTM(s->val.whileE.stm);
            break;
        case compoundK:
            prettyCOMPOUNDSTM(s->val.compoundstm);
            break;
        case exprK:
            prettyEXP(s->val.expr);
            fprintf(ofile, ";");
            /* newline(); */
            break;
    }
    indent = myindent;
}