void STRSGLR_ensure_init(void) { ATerm foo; static ATbool STRSGLR_init = ATfalse; if(STRSGLR_init) return; STRSGLR_init = ATtrue; ATregisterBlobDestructor(parse_table_blob_destructor); PT_initMEPTApi(); PT_initAsFix2Api(); initErrorApi(); SG_TOOLBUS_OFF(); SG_OUTPUT_ON(); foo = STRSGLR_set_default_config(); none_term = (ATerm) ATmakeAppl(ATmakeAFun("None", 0, ATfalse)); active_parse_tables = ATmakeList(0); inactive_parse_tables = malloc(sizeof(ATerm*) * MAX_INACTIVE_PARSE_TABLES); num_inactive_parse_tables = 0; ATprotect(&none_term); ATprotect(&parse_error_term); ATprotectList(&active_parse_tables); }
static void initApis() { PT_initMEPTApi(); ASF_initASFMEApi(); ASC_initRunTime(INITIAL_TABLE_SIZE); PT_initAsFix2Api(); PRS_initParsedRStoreApi(); RS_initRStoreApi(); }
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; }
int main(int argc, char *argv[]) { ATerm bottomOfStack; ATinit(argc, argv, &bottomOfStack); PT_initMEPTApi(); SDF_initSDFMEApi(); return testPT2SDF(); }
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; }
int main(int argc, char *argv[]) { ATerm bottomOfStack; ATinit(argc, argv, &bottomOfStack); PT_initMEPTApi(); init_terms_dict(); testCompare(); return 0; }
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; }
int main(int argc, char *argv[]) { ATerm bottomOfStack; int i, cid; for (i=1; i<argc; i++) { if (strcmp(argv[i], "-h") == 0) { usage(argv[0], ATfalse); } else if (strcmp(argv[i], "-V") == 0) { version(argv[0]); } } ATBinit(argc, argv, &bottomOfStack); SDF_initSDFMEApi(); PT_initMEPTApi(); cid = ATBconnect(NULL, NULL, -1, sdf_modules_handler); ATBeventloop(); return 0; }
int main (int argc, char *argv[]) { int c; /* option character */ ATerm bottomOfStack; ATerm tree; Graph graph; char *input_file_name = "-"; char *output_file_name = "-"; ATbool characters = ATfalse; ATbool productions = ATfalse; ATbool layout = ATfalse; ATbool literals = ATtrue; ATbool binary = ATtrue; ATbool sharing = ATfalse; #ifndef WITHOUT_TOOLBUS ATbool use_toolbus = ATfalse; int i; for (i=1; !use_toolbus && i < argc; i++) { use_toolbus = !strcmp(argv[i], "-TB_TOOL_NAME"); } if (use_toolbus) { int cid; ATBinit(argc, argv, &bottomOfStack); PT_initMEPTApi(); initGraphApi(); cid = ATBconnect(NULL, NULL, -1, graph_converter_handler); ATBeventloop(); } else #endif { while ((c = getopt(argc, argv, myarguments)) != EOF) switch (c) { case 'b': binary = ATtrue; break; case 'c': characters = ATtrue; break; case 'h': usage(); exit(0); case 'i': input_file_name = optarg; break; case 'l': layout = ATtrue; break; case 'm': literals = ATfalse; break; case 'o': output_file_name = optarg; break; case 'p': productions = ATtrue; break; case 't': binary = ATfalse; break; case 's': sharing = ATtrue; break; case 'V': fprintf(stderr, "%s %s\n", myname, myversion); exit(0); default : usage(); exit(1); } ATinit(argc, argv, &bottomOfStack); PT_initMEPTApi(); initGraphApi(); tree = ATreadFromNamedFile(input_file_name); if(tree == NULL) { ATerror("%s: could not read term from input file %s\n", myname, input_file_name); } graph = PT_printAnyToGraph(tree, characters, productions, layout, literals, sharing); if (!strcmp(output_file_name,"-")) { if (binary) { ATwriteToBinaryFile(GraphToTerm(graph), stdout); } else { ATwriteToTextFile(GraphToTerm(graph), stdout); } } else { if (binary) { ATwriteToNamedBinaryFile(GraphToTerm(graph), output_file_name); } else { ATwriteToNamedTextFile(GraphToTerm(graph), output_file_name); } } } return 0; }
int main (int argc, char **argv) { int c; /* option character */ ATerm bottomOfStack; char *inputs[MAX_MODULES] = { "-" }; int nInputs = 0; char *output = "-"; ATbool module = ATfalse; ATermList list; ASF_ASFConditionalEquationList alleqs; int i; if(argc == 1) { /* no arguments */ usage(); exit(1); } while ((c = getopt(argc, argv, myarguments)) != EOF) { switch (c) { case 'h': usage(); exit(0); case 'm': module = ATtrue; break; case 'o': output = strdup(optarg); break; case 'V': fprintf(stderr, "%s %s\n", myname, myversion); exit(0); default: usage(); exit(1); } } /* The optind variable indicates where getopt has stopped */ for(i = optind; i < argc; i++) { if (nInputs < MAX_MODULES) { inputs[nInputs++] = strdup(argv[i]); } else { ATerror("Maximum number of %d modules exceeded.\n", MAX_MODULES); exit(1); } } if (nInputs == 0) { nInputs = 1; inputs[0] = strdup("-"); } ATinit(argc, argv, &bottomOfStack); PT_initMEPTApi(); ASF_initASFMEApi(); list = ATempty; for (--nInputs; nInputs >= 0; nInputs--) { ATerm p = ATreadFromNamedFile(inputs[nInputs]); if (p == NULL) { ATwarning("concat-asf: Unable to read anything from %s\n", inputs[nInputs]); } else { list = ATinsert(list, p); } free(inputs[nInputs]); } alleqs = ASF_makeASFConditionalEquationListEmpty(); for(;!ATisEmpty(list); list = ATgetNext(list)) { ATerm head = ATgetFirst(list); ASF_ASFConditionalEquationList list; if (ATgetType(head) == AT_LIST) { list = ASF_ASFConditionalEquationListFromTerm(head); } else { ASF_ASFModule module = ASF_getStartTopASFModule(ASF_StartFromTerm(head)); list = ASF_getASFModuleEquationList(module); } ATwarning("Adding %d equations\n", ASF_getASFConditionalEquationListLength(list)); alleqs = ASF_unionASFConditionalEquationList(alleqs, ASF_makeLayoutNewline(), list); } if (module) { ASF_OptLayout l = ASF_makeLayoutNewline(); ASF_ASFSection sec = ASF_makeASFSectionEquations(l, alleqs); ASF_ASFModule mod = ASF_makeASFModuleDefault(ASF_makeASFSectionListSingle(sec)); /*PT_ParseTree pt = PT_makeValidParseTreeFromTree((PT_Tree) mod);*/ ATwriteToNamedBinaryFile((ATerm) mod, output); } else { ATwriteToNamedBinaryFile(ASF_ASFConditionalEquationListToTerm(alleqs), output); } return 0; }
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; }
int asc_support_main(ATerm *bottomOfStack, int argc, char *argv[], void (*register_all)(), void (*resolve_all)(), void (*init_all)() #ifdef TOOLBUS , ATBhandler handler #endif ) { PT_ParseTree pt; PT_ParseTree asfix; PT_Tree trm; ATerm t; ATerm reduct; #ifdef TOOLBUS ATbool toolbus_mode = ATfalse; #endif ATbool produce_output = ATtrue; ATbool run_verbose = ATfalse; ATbool printstats = ATfalse; ATbool bafmode = ATtrue; char *inputs[MAX_ARGS] = { "-" }; int nInputs = 0; char *output = "-"; char *function = ""; char *result = ""; int i; ATinit(argc, argv, bottomOfStack); PT_initMEPTApi(); ASF_initASFMEApi(); ASC_initRunTime(INITIAL_TABLE_SIZE); register_all(); resolve_all(); init_all(); #ifdef TOOLBUS /* Check whether we're a ToolBus process */ for(i=1; !toolbus_mode && i<argc; i++) { if(!strcmp(argv[i], "-TB_TOOL_NAME")) { toolbus_mode = ATtrue; } } if (toolbus_mode) { ATBinit(argc, argv, bottomOfStack); ATBconnect(NULL, NULL, -1, handler); ATBeventloop(); } else { #endif for(i=1; i<argc; i++) { if(streq(argv[i], "-v")) { run_verbose = ATtrue; } else if(streq(argv[i], "-h")) { usage(argv[0]); } else if(streq(argv[i], "-f")) { function = argv[++i]; } else if(streq(argv[i], "-i")) { if (nInputs <= MAX_ARGS) { inputs[nInputs++] = strdup(argv[++i]); } else { ATerror("%s: Maximum number of %d \'-i\' arguments exceeded.\n", argv[0], MAX_ARGS); } } else if(streq(argv[i], "-o")) { output = argv[++i]; } else if(streq(argv[i], "-r")) { result = argv[++i]; } else if(streq(argv[i], "-s")) { printstats = ATtrue; } else if(streq(argv[i], "-t")) { bafmode = ATfalse; } else if(streq(argv[i], "-m")) { produce_output = ATfalse; } } if (!streq(function,"")) { PT_Args args = PT_makeArgsEmpty(); if (streq(inputs[0],"-")) { nInputs++; } for (--nInputs; nInputs >= 0; nInputs--) { PT_ParseTree parseTree = PT_makeParseTreeFromTerm( ATreadFromNamedFile(inputs[nInputs])); if (parseTree == NULL) { ATerror("Unable to read in %s\n", inputs[nInputs]); exit(1); } args = PT_makeArgsList(PT_getParseTreeTree(parseTree), args); } pt = PT_applyFunctionToArgsParseTree(function, result, args); } else { if (nInputs != 1 && (!streq(inputs[0], "-"))) { ATerror("Can only process one argument if no -f and -r option " "are supplied.\n"); return 1; } t = ATreadFromNamedFile(inputs[0]); pt = PT_makeParseTreeFromTerm(t); } if (PT_isValidParseTree(pt)) { trm = PT_getParseTreeTree(pt); if(run_verbose) { ATfprintf(stderr,"Reducing ...\n"); } reduct = innermost(trm); if(run_verbose) { ATfprintf(stderr,"Reducing finished.\n"); } if (printstats) { struct rusage usage; FILE *file; char buf[BUFSIZ]; int size, resident, shared, trs, lrs, drs, dt; sprintf(buf, "/proc/%d/statm", getpid()); file = fopen(buf, "r"); if (file) { fscanf(file, "%d %d %d %d %d %d %d", &size, &resident, &shared, &trs, &lrs, &drs, &dt); /* fprintf(stderr, "size = %d kb\n", size*4); fprintf(stderr, "resident = %d kb\n", resident*4); fprintf(stderr, "shared = %d kb\n", shared*4); fprintf(stderr, "trs = %d kb\n", trs*4); fprintf(stderr, "lrs = %d kb\n", lrs*4); */ fprintf(stderr, "memory used : %d kb\n", drs*4); /*fprintf(stderr, "dt = %d kb\n", dt*4);*/ } else { fprintf(stderr, "could not open %s\n", buf); perror(""); } if (getrusage(RUSAGE_SELF, &usage) == -1) { perror("rusage"); } else { /*fprintf(stderr, "rusage statistics (see 'man getrusage')\n");*/ fprintf(stderr, "utime : %ld.%06d sec.\n", (long)usage.ru_utime.tv_sec, (int)usage.ru_utime.tv_usec); fprintf(stderr, "stime : %ld.%06d sec.\n", (long)usage.ru_stime.tv_sec, (int)usage.ru_stime.tv_usec); #if 0 /* The following rusage stats do not work yet */ fprintf(stderr, "maxrss : %ld\n", usage.ru_maxrss); fprintf(stderr, "ixrss : %ld\n", usage.ru_ixrss); fprintf(stderr, "idrss : %ld\n", usage.ru_idrss); fprintf(stderr, "isrss : %ld\n", usage.ru_isrss); fprintf(stderr, "minflt : %ld\n", usage.ru_minflt); fprintf(stderr, "majflt : %ld\n", usage.ru_majflt); fprintf(stderr, "nswap : %ld\n", usage.ru_nswap); fprintf(stderr, "\n"); fprintf(stderr, "inblock : %ld\n", usage.ru_nswap); fprintf(stderr, "oublock : %ld\n", usage.ru_nswap); fprintf(stderr, "msgsnd : %ld\n", usage.ru_nswap); fprintf(stderr, "msgrcv : %ld\n", usage.ru_nswap); fprintf(stderr, "nsignals : %ld\n", usage.ru_nswap); fprintf(stderr, "nvcsw : %ld\n", usage.ru_nswap); fprintf(stderr, "nivcsw : %ld\n", usage.ru_nswap); #endif } } if (produce_output) { asfix = toasfix(reduct); if (bafmode) { ATwriteToNamedBinaryFile(PT_makeTermFromParseTree(asfix),output); } else { ATwriteToNamedTextFile(PT_makeTermFromParseTree(asfix),output); } } } #ifdef TOOLBUS } #endif return 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; }