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); } }
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; }
static int testPT2SDF(void) { ATerm contents; PT_ParseTree parseTree; PT_Tree tree; PT_Production ptProduction; SDF_Production sdfProduction; contents = ATreadFromNamedFile(TEST_PT2SDF_FILE); assert(contents != NULL); parseTree = PT_ParseTreeFromTerm(contents); tree = PT_getParseTreeTree(parseTree); assert(PT_isValidTree(tree)); assert(PT_isTreeAppl(tree)); ptProduction = PT_getTreeProd(tree); assert(PT_isValidProduction(ptProduction)); /*ATwarning("ptProduction: %t\n", ptProduction);*/ sdfProduction = PTProductionToSDFProduction(ptProduction); assert(SDF_isValidProduction(sdfProduction)); /*ATwarning("sdfProduction: %t\n", sdfProduction);*/ return 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)); }
ATerm rename_module(int cid, ATerm atImports, char *moduleName, ATerm term) { SDF_ImportList imports = SDF_ImportListFromTerm(atImports); SDF_ImportList relevant = getRelevantImports(moduleName, imports); ATermList newModules = applyImports(relevant, PT_ParseTreeFromTerm(ATBunpack(term))); return ATmake("snd-value(renamed-module(<term>))", newModules); }
int main(int argc, char **argv) { int c; ATerm bottomOfStack; PT_ParseTree tree, flatTree; /* Configuration items */ char *input="-"; char *output="-"; ATbool bafmode=ATtrue; ATbool verbose=ATfalse; ATbool proceed=ATtrue; extern char *optarg; extern int optind; /* Commandline mode */ while ((c = getopt(argc, argv, myarguments)) != -1) { switch (c) { case 'b': bafmode = ATtrue; break; case 'i': input=optarg; break; case 'o': output=optarg; break; case 't': bafmode = ATfalse; break; case 'v': verbose = ATtrue; break; case 'V': version(); proceed=ATfalse; break; case 'h': default: usage(); proceed=ATfalse; break; } } argc -= optind; argv += optind; ATinit(argc, argv, &bottomOfStack); PT_initMEPTApi(); PT_initAsFix2Api(); if(proceed) { tree = PT_ParseTreeFromTerm(ATreadFromNamedFile(input)); flatTree = flattenPT(tree); if(!flatTree) { ATerror("%s: conversion failed.", myname); } if(bafmode) { ATwriteToNamedBinaryFile(PT_ParseTreeToTerm(flatTree), output); } else { ATwriteToNamedTextFile(PT_ParseTreeToTerm(flatTree), output); } } return 0; }
static PT_ParseTree parsetreeFromATermFile(const char *filename) { ATerm term = NULL; term = ATreadFromNamedFile(filename); if (term != NULL && ATmatch(term, "parsetree(<term>,<int>)", NULL, NULL)) { return PT_ParseTreeFromTerm(term); } ATerror("asc-main: can not read parse tree from file %s\n", filename); return NULL; }
int main (int argc, char **argv) { int c; ATerm bottomOfStack; PT_ParseTree parsetree; ATerm ambiguities; ATbool atermformat = ATfalse; char *input_file_name = "-"; char *output_file_name = "-"; while ((c = getopt(argc, argv, myarguments)) != EOF) switch (c) { case 'a': atermformat = ATtrue; break; case 'h': usage(); exit(0); case 'i': input_file_name = optarg; break; case 'o': output_file_name = optarg; break; case 'V': fprintf(stderr, "%s %s\n", myname, myversion); exit(0); default : usage(); exit(1); } ATinit(argc, argv, &bottomOfStack); /* Initialize Aterm library */ PT_initMEPTApi(); parsetree = PT_ParseTreeFromTerm(ATreadFromNamedFile(input_file_name)); if(parsetree == NULL) { ATerror("%s: could not read term from input file %s\n", myname, input_file_name); } ambiguities = PT_reportParseTreeAmbiguities(parsetree); if(!atermformat) { FILE *fp = NULL; if(!strcmp(output_file_name, "") || !strcmp(output_file_name,"-")) { fp = stdout; } else if(!(fp = fopen(output_file_name, "wb"))) { ATerror("%s: could not open %s for output.\n", myname, output_file_name); return 1; } prettyPrint(ambiguities,fp); fclose(fp); } else { ATwriteToNamedTextFile(ambiguities, output_file_name); } return 0; }
ATerm STRSGLR_anno_position_info(ATerm pt_term, ATerm path_term) { PT_ParseTree pt; const char* path; if(!AT_isString(path_term)) { return NULL; } path = AT_getString(path_term); pt = PT_ParseTreeFromTerm(pt_term); pt = PT_addParseTreePosInfoSome(path, pt, -1, ATfalse, ATfalse); return PT_ParseTreeToTerm(pt); }
ATerm STRSGLR_implode_parsetree(ATerm t) { return PT_implodeParseTree( PT_ParseTreeFromTerm(t), ATtrue, /* cons */ ATtrue, /* layout */ ATtrue, /* literals */ ATtrue, /* injections */ ATtrue, /* parsetree */ ATtrue, /* implode lexicals */ ATfalse, /* don't keep annotations */ ATtrue, /* alt */ ATtrue, /* seq */ ATtrue, /* opt */ ATfalse /* layout placeholder */ ); }
int main(int argc, char **argv) { int c; ATerm bottomOfStack; char *input="-"; char *output="-"; char *argument = NULL; ATbool minimizeSort = ATfalse; ATbool maximizeSort = ATfalse; ATerm inputTerm = NULL; ATerm outputTerm = NULL; PT_ParseTree inputTree = NULL; PT_ParseTree outputTree = NULL; while ((c = getopt(argc, argv, myarguments)) != -1) { switch (c) { case 'i': input=optarg; break; case 'n': minimizeSort = ATtrue; argument = optarg; break; case 'N': maximizeSort = ATtrue; argument = optarg; break; case 'o': output=optarg; break; case 'V': version(); return 0; case 'h': usage(); return 0; default: usage(); return 1; } } ATinit(argc, argv, &bottomOfStack); PT_initMEPTApi(); inputTerm = ATreadFromNamedFile(input); inputTree = PT_ParseTreeFromTerm(inputTerm); if (inputTerm != NULL) { /* The tool will always execute one filter at a time, such that the user * can implement his own scheduling by repeatedly using this tool. * Please do not change this behavior. */ if (XOR(minimizeSort, maximizeSort) && argument != NULL) { PT_Symbol sort = PT_makeSymbolCf(PT_makeSymbolSort(argument)); outputTree = minmax(inputTree, sort, minimizeSort); } else { usage(); return 1; } if (outputTree != NULL) { outputTree = flattenAgain(outputTree); outputTerm = PT_ParseTreeToTerm(outputTree); ATwriteToNamedTextFile(outputTerm, output); } else { fprintf(stderr, "%s: filtering failed unexpectedly\n", myname); return 1; } } else { fprintf(stderr,"%s: could not open file %s\n", myname, input); return 1; } return 0; }
void testCompare() { test_assert("true > false", PT_compareTree(PT_getParseTreeTree(PT_ParseTreeFromTerm(True)), PT_getParseTreeTree(PT_ParseTreeFromTerm(False))) > 0); test_assert("false < true", PT_compareTree(PT_getParseTreeTree(PT_ParseTreeFromTerm(False)), PT_getParseTreeTree(PT_ParseTreeFromTerm(True))) < 0); test_assert("whitespace difference", PT_compareTree(PT_getParseTreeTree(PT_ParseTreeFromTerm( TrueAndFalse)), PT_getParseTreeTree(PT_ParseTreeFromTerm( OtherTrueAndFalse))) == 0); test_assert("annotations difference", PT_compareTree(PT_getParseTreeTree(PT_ParseTreeFromTerm( TrueAndFalse)), PT_getParseTreeTree(PT_ParseTreeFromTerm( AnnotatedTrueAndFalse))) == 0); test_assert("begin declare a : natural end < begin declare b : natural end", PT_compareTree(PT_getParseTreeTree(PT_ParseTreeFromTerm(DeclareA) ), PT_getParseTreeTree(PT_ParseTreeFromTerm(DeclareB) )) < 0); test_assert("2 > 10", PT_compareTree(PT_getParseTreeTree(PT_ParseTreeFromTerm(Two)), PT_getParseTreeTree(PT_ParseTreeFromTerm(Ten))) > 0); test_assert("20 > 10", PT_compareTree(PT_getParseTreeTree(PT_ParseTreeFromTerm(Twenty)), PT_getParseTreeTree(PT_ParseTreeFromTerm(Ten))) > 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; }
int main(int argc, char **argv) { ATerm bos, term; ATermTable opcodes; AIL_Definition def; AIL_Program prg; ABFBuffer buffer; ABF abf; PT_Tree tree; int size; /* Option processing */ int arg_ct = optionProcess(&ailcOptions, argc, argv); argc -= arg_ct; argv += arg_ct; if (HAVE_OPT(INPUT)) ailc_input = open_file(OPT_ARG(INPUT), "r"); else ailc_input = stdin; if (HAVE_OPT(OUTPUT)) ailc_output = open_file(OPT_ARG(OUTPUT), "w"); else ailc_output = stdout; if (HAVE_OPT(GENERATE_API)) { ailc_generate_api = 1; ailc_name = OPT_ARG(NAME); /* if (HAVE_OPT(PREFIX)) */ /* ailc_prefix = OPT_ARG(PREFIX); */ /* else */ /* ailc_prefix = default_ail_prefix; */ } if (HAVE_OPT(AIL_LIST)) ailc_def = OPT_ARG(AIL_LIST); else ailc_def = default_ail_def; if (HAVE_OPT(VERBOSE)) ail2abf_set_verbose(1); /* end option processing. */ ATinit(argc, argv, &bos); AIL_initAILApi(); PT_initMEPTApi(); abf_init_buffer(&buffer); /* Read definition. */ term = ATreadFromNamedFile(ailc_def); tree = PT_getParseTreeTree(PT_ParseTreeFromTerm(term)); def = AIL_DefinitionFromTerm(PT_TreeToTerm(tree)); /* Save api if needed. */ if (ailc_generate_api) save_opcode_api(ailc_name, def); else { AIL_ByteCode bc; term = ATreadFromBinaryFile(ailc_input); tree = PT_getParseTreeTree(PT_ParseTreeFromTerm(term)); prg = AIL_ProgramFromTerm(PT_TreeToTerm(tree)); bc = compile_ail(&buffer, def, prg); AIL_writeToFile(ailc_output, bc); } return 0; }