コード例 #1
0
ファイル: pretty.c プロジェクト: kungfooman/pxdscript
void prettyDECL(int indent, DECL *decl)
{
  switch(decl->kind){
  case formalK:
    prettyTYPE(decl->type);
    printf("%s",decl->val.formalD.name);
    if(decl->next != NULL)
      printf(", ");
    break;
  case variableK:
    indentprintf(indent, "");
    prettyModifierKind(decl->val.variableD.modifier);
    prettyTYPE(decl->type);
    prettyIDENTIFIER(decl->val.variableD.identifiers);
    if (decl->val.variableD.initialization != NULL) {
      printf(" = ");
      prettyEXP(decl->val.variableD.initialization);
    }
    printf(";\n");
    break;
  case simplevarK:
    prettyTYPE(decl->type);
    printf("%s",decl->val.simplevarD.name);
    if (decl->val.simplevarD.initialization != NULL) {
      printf(" = ");
      prettyEXP(decl->val.simplevarD.initialization);
    }
    if(decl->next != NULL)
      printf(", ");
    break;
  }
  
  if(decl->next != NULL)
    prettyDECL(indent, decl->next);
}
コード例 #2
0
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");
}
コード例 #3
0
ファイル: pretty.c プロジェクト: kungfooman/pxdscript
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");
}
コード例 #4
0
ファイル: pretty.c プロジェクト: kungfooman/pxdscript
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);
  }
}
コード例 #5
0
ファイル: pretty.c プロジェクト: kungfooman/pxdscript
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;
   }
}
コード例 #6
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");
		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;
	}
}