Exemplo n.º 1
0
ATerm normalize_and_generate_table(const char *name, PT_ParseTree sdf2term) {
  ATerm pt = NULL;
  PT_Tree ksdf;

  if (PGEN_getStatsFlag) { STATS_Timer(); } 

  if (PGEN_getGenerationModeFlag()) {
    ksdf = PT_getParseTreeTree(sdf2term);
  } else {
    ksdf = normalizeGrammar(name, sdf2term); 
  }

  PGEN_STATS_setCount(PGEN_STATS_normalizationTime, STATS_Timer());

  if (PGEN_getNormalizationModeFlag()) {
    return PT_ParseTreeToTerm(PT_makeValidParseTreeFromTree(ksdf));
  }

  if (ksdf)  {
    pt = sdf_generate_table(ksdf);
  }

  PGEN_STATS_setCount(PGEN_STATS_generationTime, STATS_Timer());
  
  return (ATerm)pt;
}
Exemplo n.º 2
0
ATerm pretty_print(int cid, ATerm input) 
{
  PT_ParseTree parsetree = NULL;
  BOX_Start box = NULL;
  PT_Tree result = NULL;

  ERR_resetErrorManager();

  parsetree = PT_ParseTreeFromTerm(ATBunpack(input));

  if (parsetree != NULL) {
    box = pandora(parsetree);
  }

  if (box != NULL) {
    result = toText(PT_ParseTreeFromTerm(BOX_StartToTerm(box)));
  }

  if (result != NULL) {
    PT_ParseTree presult = PT_makeValidParseTreeFromTree(result);
    ATerm value = ATBpack(PT_ParseTreeToTerm(presult));
    return ATmake("snd-value(pretty-printed(<term>))", value);
  }
  else {
    ERR_Summary summary = ERR_getManagerSummary();
    return ATmake("snd-value(pretty-print-error(<term>))", summary);
  }
}
Exemplo n.º 3
0
static ATerm addEqsSyntax(const char *name, ATerm term)
{
  PT_ParseTree parseTree = PT_ParseTreeFromTerm(term);
  PT_Tree ptApplied = addEqsSyntaxFunction(name, parseTree);
  ATerm reduct = innermost(ptApplied);
  PT_Tree asfix = toasfix(reduct);
  
  return PT_ParseTreeToTerm(PT_makeValidParseTreeFromTree(asfix));
}
Exemplo n.º 4
0
static PT_Tree implode_tree(PT_Tree tree) 
{
  PT_ParseTree pt = PT_makeValidParseTreeFromTree(tree);
  return (PT_Tree)PTPT_liftATerm(PT_implodeParseTree(pt,
						     ATtrue,
						     ATtrue,
						     ATtrue,
						     ATtrue,
						     ATtrue,
						     ATtrue,
						     ATfalse,
						     ATtrue,
						     ATtrue,
						     ATtrue,
						     ATtrue));
}
Exemplo n.º 5
0
int main(int argc, char *argv[]) 
{
  ATerm bottomOfStack;
  ATerm at_tree;
  char *ATlibArgv[] = {"pandora", "-at-termtable", "21"};
  PT_ParseTree tree; 
  PT_Tree ptText;
  BOX_Start box;
  char *input = "-";
  char *output = "-";
  ATbool boxOutput = ATfalse;
  ATbool bytesOutput = ATfalse;
  int c;
  int i;
  ATbool useToolbus = ATfalse;

  ATinit(3, ATlibArgv, &bottomOfStack); 
  ASC_initRunTime(INITIAL_TABLE_SIZE);
  PT_initMEPTApi(); 
  PTPT_initPTMEPTApi();
  BOX_initBoxApi();
  ERR_initErrorManager("pandora", "all");

  register_Box_to_Text();
  resolve_Box_to_Text();
  init_Box_to_Text();


  for (i=1; !useToolbus && i < argc; i++) {
    useToolbus = !strcmp(argv[i], "-TB_TOOL_NAME");
  }

  if (useToolbus) {
    int cid;
    ATBinit(argc, argv, &bottomOfStack);
    cid = ATBconnect(NULL, NULL, -1, pandora_handler);
    ATBeventloop();
  }
  else {
    while ((c = getopt(argc, argv, myarguments)) != -1) {
      switch (c) {
	case 'b':  boxOutput=ATtrue; break;
	case 'B':  bytesOutput=ATtrue; break;
	case 'i':  input=optarg; break;
	case 'o':  output=optarg; break;
	case 'v':  run_verbose = ATtrue; break;
	case 'V':  version(); exit(0);
	case 'h':  usage(); exit(0);
	default:   usage(); exit(1); 
      }
    }

    at_tree = ATreadFromNamedFile(input);

    if (at_tree != NULL) {
      tree = PT_ParseTreeFromTerm(at_tree);

      if (run_verbose) {
	ATwarning("pandora: mapping parse trees to "
		  "BOX using default rules\n");
      }

      box = pandora(tree);

      if (!boxOutput) {      
	if (run_verbose) {
	  ATwarning("pandora: rendering BOX to list of characters\n");
	}

	ptText = toText(PT_ParseTreeFromTerm(BOX_StartToTerm(box)));


	if (run_verbose) {
	  ATwarning("pandora: yielding characters to output\n");
	}

	if (!strcmp(output, "-")) {
	  if (!bytesOutput) {
	    PT_yieldTreeToFile(ptText, stdout, ATfalse);
	  }
	  else {
	    ATwriteToNamedBinaryFile((ATerm) 
				     PT_makeValidParseTreeFromTree(ptText), 
				     "-");
	  }
	}
	else {
	  if (!bytesOutput) {
	    FILE *fp = fopen(output, "wb");
	    if (fp != NULL) {
	      PT_yieldTreeToFile(ptText, fp, ATfalse);
	    }
	    else {
	      ATerror("Could not open %s for writing.\n", output);
	    }
	  }
	  else {
	    ATwriteToNamedBinaryFile((ATerm) 
				     PT_makeValidParseTreeFromTree(ptText), 
				     output);
	  }
	}
      }
      else {
	PT_ParseTree ptBox = PT_ParseTreeFromTerm(BOX_StartToTerm(box));
	ATwriteToNamedSharedTextFile((ATerm) ptBox, output);
      }
    }
    else {
      ATwarning("Failed to read ATerm from file: %s\n", input); 
      return 1; 
    }
  }

  return 0;
}