int main(int argc, char *argv[]) { ATerm bottomOfStack; ATerm t1 = NULL, t2 = NULL; int i; int result = 0; ATinit(argc, argv, &bottomOfStack); PT_initMEPTApi(); if (argc < 3 || argc > 7) { usage(argv[0]); } for (i=1; i < argc; i++) { if (strcmp(argv[i], "-h") == 0) { usage(argv[0]); } else if (strcmp(argv[i], "-V") == 0) { fprintf(stderr, "%s v%s\n", argv[0], version); } else if (strcmp(argv[i], "-l") == 0) { modLayout = !modLayout; } else { if (t1 == NULL) { t1 = ATreadFromNamedFile(argv[i]); if (t1 == NULL) { ATerror("Failed to read from %s\n", argv[i]); } } else if (t2 == NULL) { t2 = ATreadFromNamedFile(argv[i]); if (t2 == NULL) { ATerror("Failed to read from %s\n", argv[i]); } } else { usage(argv[0]); } } } result = PT_compareTree(PT_getParseTreeTop(PT_ParseTreeFromTerm(t1)), PT_getParseTreeTop(PT_ParseTreeFromTerm(t2)), modLayout); if (result < 0) { return -1; } if (result > 0) { return 1; } return 0; }
PT_ParseTree flattenAgain(PT_ParseTree input) { PT_Tree top = PT_getParseTreeTop(input); top = flattenTreeAgain(top); return PT_setParseTreeTop(input, top); }
PT_ParseTree PT_renameInParseTree(PT_ParseTree parsetree, PT_Symbol formalParam, PT_Symbol actualParam) { PT_Tree tree = PT_getParseTreeTop(parsetree); tree = PT_renameInTree(tree, formalParam, actualParam); return PT_setParseTreeTop(parsetree, tree); }
int asc_support_main(ATerm *bottomOfStack, int argc, char *argv[], void (*register_all)(), void (*resolve_all)(), void (*init_all)(), unsigned const char* tableBaf, size_t tableSize, ATbool parseInput, ATBhandler handler) { PT_ParseTree pt = NULL; PT_Tree asfix; PT_Tree trm; PT_ParseTree rpt = NULL; ATerm reduct; const char *outputFilename; int numberOfInputs; ATinit(argc, argv, bottomOfStack); initApis(); register_all(); resolve_all(); init_all(); initParsetable(tableBaf, tableSize); SGLR_initialize(); OPT_initialize(); ASC_initializeDefaultOptions(); /* Check whether we're a ToolBus process */ if (toolbusMode(argc, argv)) { ATBinit(argc, argv, bottomOfStack); ATBconnect(NULL, NULL, -1, asf_toolbus_handler); ATBeventloop(); } else { handleOptions(argc, argv, parseInput); numberOfInputs = ASC_getNumberOfParseTrees(); outputFilename = ASC_getOutputFilename(); if (!streq(ASC_getPrefixFunction(),"")) { pt = applyFunction((const char*) ASC_getPrefixFunction(), (const char*) ASC_getResultNonTermName(), numberOfInputs, inputs); } else { if (numberOfInputs == 0) { pt = parsetreeFromFile("-", parseInput); } else if (numberOfInputs == 1) { pt = inputs[0]; } else if (numberOfInputs != 1) { ATerror("Can only process one argument if no -f and -r option " "are supplied.\n" "Did a -s argument eat up your -f or -r option?\n"); return 1; } } if (PT_isValidParseTree(pt)) { trm = PT_getParseTreeTop(pt); if (ASC_getVerboseFlag()) { ATfprintf(stderr,"Reducing ...\n"); } reduct = innermost(trm); if (ASC_getVerboseFlag()) { ATfprintf(stderr,"Reducing finished.\n"); } if (ASC_getStatsFlag()) { printStats(); } if (ASC_getOutputFlag()) { asfix = toasfix(reduct); rpt = PT_makeParseTreeTop(asfix, 0); if (parseInput) { FILE *fp = NULL; if (!strcmp(outputFilename, "-")) { fp = stdout; } else { fp = fopen(outputFilename, "wb"); } if (fp != NULL) { PT_yieldParseTreeToFile(rpt, fp, ATfalse); } else { ATerror("asc-main: unable to open %s for writing\n", outputFilename); } } else { if (ASC_getBafmodeFlag()) { ATwriteToNamedBinaryFile(PT_ParseTreeToTerm(rpt),outputFilename); } else { ATwriteToNamedTextFile(PT_ParseTreeToTerm(rpt),outputFilename); } } } } } return 0; }