void print_tree(const Tree * t, int offset) { if (!t) return; std::cout << t->val << std::endl; print_branch(t->left, offset); print_branch(t->right, offset); }
void cgit_print_branches(int maxcount) { struct reflist list; int i; html("<tr class='nohover'><th class='left'>Branch</th>" "<th class='left'>Commit message</th>" "<th class='left'>Author</th>" "<th class='left' colspan='2'>Age</th></tr>\n"); list.refs = NULL; list.alloc = list.count = 0; for_each_branch_ref(cgit_refs_cb, &list); if (maxcount == 0 || maxcount > list.count) maxcount = list.count; if (maxcount < list.count) { qsort(list.refs, list.count, sizeof(*list.refs), cmp_branch_age); qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name); } for(i=0; i<maxcount; i++) print_branch(list.refs[i]); if (maxcount < list.count) print_refs_link("heads"); }
int run_repl() { Stack context; Branch branch; bool displayRaw = false; push_frame(&context, &branch); while (true) { std::cout << "> "; std::string input; if (!std::getline(std::cin, input)) break; if (input == "exit" || input == "/exit") break; if (input == "") continue; if (input == "/raw") { displayRaw = !displayRaw; if (displayRaw) std::cout << "Displaying raw output" << std::endl; else std::cout << "Not displaying raw output" << std::endl; continue; } if (input == "/clear") { clear_branch(&branch); std::cout << "Cleared working area" << std::endl; continue; } if (input == "/dump") { dump(&branch); continue; } if (input == "/help") { std::cout << "Special commands: /raw, /help, /clear, /dump, /exit" << std::endl; continue; } int previousHead = branch.length(); repl_evaluate_line(&context, input, std::cout); if (displayRaw) { for (int i=previousHead; i < branch.length(); i++) { std::cout << get_term_to_string_extended(branch[i]) << std::endl; if (nested_contents(branch[i])->length() > 0) print_branch(std::cout, nested_contents(branch[i])); } } } return 0; }
void write_tree(branch *tree,char *fn) { ////// // Writes all particles in tree into file fn. // Only used for debugging FILE *fr; fr=fopen(fn,"w"); print_branch(tree,fr); fclose(fr); }
int main(int argc, char **argv) { int i, j, wordnum = 0; FILE *fwords = NULL; printf("Welcome to Crossword Generator v0.1\n"); printf("===================================\n"); if (2 != argc) { printf("Usage: %s <file with a list of words>\n", argv[0]); printf("\nMax words: %d\nMax wordlen: %d\n", MAXWORDS, MAXWORDLEN); return 1; } // Read input words to the words[] array fwords = fopen(argv[1], "r"); for (i = 0; NULL != fgets(words[i].word, MAXWORDLEN, fwords) && i < MAXWORDS; i++) { // Remove newline symbol words[i].wordlen = strlen(words[i].word) - 1; words[i].word[words[i].wordlen] = '\0'; for (j = 0; j < words[i].wordlen; j++) words[i].word[j] = tolower(words[i].word[j]); printf("Word #%d: %s, %d\n", i, words[i].word, words[i].wordlen); } wordnum = i; // Build inital word pairs that we'll be using a lot later if (build_pairs(wordnum)) { fprintf(stderr, "Error building pairs between words\n"); return 1; } // Fill the tree with all possible pairs. Scan all the words. for (i = 0; i < wordnum; i++) build_branch(wordnum, words[i].firstchild); #ifdef DEBUG for (i = 0; i < wordnum; i++) { printf("\n--------------------------------\nword[%d]=%s\n--------------------------------\n", i, words[i].word); print_strie(words[i].firstchild); } #endif // Print the best branch if any print_branch(best_branch); // Free the memory for (i = 0; i < wordnum; i++) clear_branch(words[i].firstchild); return 0; }
std::ostream& node(const ast::abstract::Node& node) { switch(node) { case ast::ExternNode: print_extern(dynamic_cast<const ast::Extern&>(node)); break; case ast::FuncNode: print_func(dynamic_cast<const ast::Func&>(node)); break; case ast::VariableNode: print_variable(dynamic_cast<const ast::Variable&>(node)); break; case ast::ConstantNode: print_constant(dynamic_cast<const ast::Constant&>(node)); break; case ast::CastNode: print_cast(dynamic_cast<const ast::Cast&>(node)); break; case ast::UnOpNode: print_un_op(dynamic_cast<const ast::UnOp&>(node)); break; case ast::BinOpNode: print_bin_op(dynamic_cast<const ast::BinOp&>(node)); break; case ast::CallNode: print_call(dynamic_cast<const ast::Call&>(node)); break; case ast::ReturnNode: print_return(dynamic_cast<const ast::Return&>(node)); break; case ast::BranchNode: print_branch(dynamic_cast<const ast::Branch&>(node)); break; case ast::AssignmentNode: print_assignment(dynamic_cast<const ast::Assignment&>(node)); break; case ast::WhileNode: print_while(dynamic_cast<const ast::While&>(node)); break; case ast::VoidContextNode: print_void_context(dynamic_cast<const ast::VoidContext&>(node)); break; default: stream << "[Unknown Node] ??"; } return stream; }
static void print_branch(branch *br,FILE *fil) { ////// // Recursive branch writer int ii; if(br->leaf) { for(ii=0;ii<br->np;ii++) { fprintf(fil,"%lf %lf %lf \n", ((double *)(br->sons))[3*ii], ((double *)(br->sons))[3*ii+1], ((double *)(br->sons))[3*ii+2]); } } else { for(ii=0;ii<8;ii++) print_branch(((branch **)(br->sons))[ii],fil); } }
int run_debugger_repl(std::string const& filename) { Branch branch; load(&branch, filename); while (true) { std::cout << "> "; std::string input; if (!std::getline(std::cin, input)) break; if (input == "exit" || input == "/exit") break; if (input == "") continue; if (input == "p") { print_branch(std::cout, &branch); continue; } if (input == "e") { Stack stack; evaluate_branch(&stack, &branch); continue; } if (input == "c") { print_static_errors_formatted(&branch, std::cout); continue; } std::cout << "unrecognized command: " << input << std::endl; } return 0; }
static int print_jne_branch(struct string *str, struct insn *insn) { print_func_name(str); return print_branch(str, &insn->operand); }
static int write_instruction(struct oport *f, instruction *i, u16 ofs) { u8 byte1, byte2; u8 op; i16 word1; int scan; instruction *old_i = i; const char *brname[] = { "", "(loop)", "(nz)", "(z)" }; const char *builtin_names[last_builtin] = { NULL, NULL, "eq", "ne", "gt", "lt", "le", "ge", "bitor", "bitxor", "bitand", "shift_left", "shift_right", "add", "sub", "multiply", "divide", "remainder", "negate", "not", "bitnot", NULL, NULL, NULL, NULL, "ref", "set", "cons", NULL }; op = insu8(); pprintf(f, "%5d: ", ofs); switch (op) { case OPhalt: pprintf(f, "halt\n"); break; case OPmreadl: pprintf(f, "recall/l %u\n", insu8()); break; case OPmreadl3 ... OPmreadl3 + 7: pprintf(f, "recall/l3 %u\n", op - OPmreadl3); break; case OPmreadc: pprintf(f, "recall/c %u\n", insu8()); break; case OPmreadc3 ... OPmreadc3 + 7: pprintf(f, "recall/c3 %u\n", op - OPmreadc3); break; case OPmreadg: pprintf(f, "recall/g %u\n", insu16()); break; case OPmwritel: pprintf(f, "assign/l %u\n", insu8()); break; case OPmwritel3 ... OPmwritel3 + 7: pprintf(f, "assign/l3 %u\n", op - OPmwritel3); break; case OPmwritec: pprintf(f, "assign/c %u\n", insu8()); break; case OPmwriteg: pprintf(f, "assign/g %u\n", insu16()); break; case OPmwritedl: pprintf(f, "assignd/l %u\n", insu8()); break; case OPmwritedl3 ... OPmwritedl3 + 7: pprintf(f, "assignd/l3 %u\n", op - OPmwritedl3); break; case OPmwritedc: pprintf(f, "assignd/c %u\n", insu8()); break; case OPmwritedg: pprintf(f, "assignd/g %u\n", insu16()); break; case OPmvcheck4 ... OPmvcheck4 + 15: pprintf(f, "vtypecheck %d /l %d\n", op - OPmvcheck4, insu8()); break; case OPmscheck4 ... OPmscheck4 + 15: pprintf(f, "stypecheck %d\n", op - OPmscheck4); break; case OPmreturn: pprintf(f, "return\n"); break; case OPmcst: pcst(f, i, "constant "); i += sizeof(value); break; case OPmint3 ... OPmint3 + 7: pprintf(f, "integer %d\n", op - OPmint3); break; case OPmundefined: pprintf(f, "undefined (42)\n"); break; case OPmclosure: { int nvars = insu8(), var; /* Must copy instructions as GC might occur */ instruction *tempi = alloca(2 + sizeof(value) + nvars); memcpy(tempi, i - 2, 2 + sizeof(value) + nvars); old_i = tempi; i = tempi + 2; pprintf(f, "closure %u\n", nvars); for (var = 0; var < nvars; var++) { u8 varspec = insu8(); u8 whichvar = varspec >> 1; pprintf(f, " %s %d\n", (varspec & 1) == local_var ? "localvar" : "closurevar", whichvar); } pcst(f, i, " code "); i += sizeof(value); break; } case OPmexec4 ... OPmexec4 + 15: pprintf(f, "execute %u\n", op - OPmexec4); break; case OPmexecg4 ... OPmexecg4 + 15: pprintf(f, "execute %u global %u\n", op - OPmexecg4, insu16()); break; case OPmexecprim6 ... OPmexecprim6 + 63: pprintf(f, "execute primitive %u\n", op - OPmexecprim6); break; case OPmpop: pprintf(f, "discard\n"); break; case OPmexitn: pprintf(f, "exit %u\n", insu8()); break; case OPmba3 ... OPmba3 + 7: i = print_branch(f, i, ofs, "ba3", op - OPmba3); break; case OPmbt3 ... OPmbt3 + 7: i = print_branch(f, i, ofs, "bt3", op - OPmbt3); break; case OPmbf3 ... OPmbf3 + 7: i = print_branch(f, i, ofs, "bf3", op - OPmbf3); break; case OPmclearl: pprintf(f, "clear/l %u\n", insu8()); break; default: for (scan = 0; scan < last_builtin; scan++) if (op == builtin_ops[scan]) { pprintf(f, "builtin_%s\n", builtin_names[scan]); goto ret; } pprintf(f, "Opcode %d\n", op); break; } ret: return i - old_i; }
void print_node(struct node *node, int level, int root) { if (node == NULL) { return; } struct node_info *info = parser_node_info(node); int i, print_type = 1; show_indents[level + 1] = 1; print_node_indent(level, root); printf("("); switch (node->type) { case NT_INT: printf("%d", ((struct int_node*)node)->value); print_type = 0; break; case NT_DOUBLE: printf("%f", ((struct double_node*)node)->value); print_type = 0; break; case NT_STRING: printf("\"%s\"", ((struct string_node*)node)->value); print_type = 0; break; case NT_IDENT: printf("ident %s", ((struct string_node*)node)->value); break; case NT_NOP: printf("nop"); print_type = 0; break; case NT_VARIABLE: printf("var %s", ((struct var_node*)node)->symbol->name); break; case NT_CAST: printf("cast to <"); print_symbol(((struct cast_node*)node)->base.type_sym, level + 1, 0); printf(">"); print_type = 0; break; default: printf("%s", info->repr); if (node->type_sym != NULL && (parser_flags_get() & PF_RESOLVE_NAMES) == PF_RESOLVE_NAMES) { print_type = 1; } break; } printf(")"); if (node->type_sym != NULL && print_type) { printf(" -> <"); int old_indent = show_indents[level + 1]; show_indents[level + 1] = 0; if (node->type_sym->type == ST_VARIABLE || node->type_sym->type == ST_GLOBAL_VARIABLE || node->type_sym->type == ST_PARAMETER) { print_symbol(node->type_sym->base_type, level + 1, 1); } else { print_symbol(node->type_sym, level + 1, 1); } show_indents[level + 1] = old_indent; printf(">"); } printf("\n"); int op_count = parser_node_subnodes_count(node); if (node->symtable != NULL && symtable_size(node->symtable) > 0) { print_indent(level); printf("[\n"); print_symtable(node->symtable, level + 1); print_indent(level); printf("]"); if (op_count == 0) { printf("\n"); } } for (i = 0; i < op_count; i++) { print_branch(parser_get_subnode(node, i), level, i == op_count - 1); } }