void print_ast(node* start_node) { printf("NT: %i\n", start_node->type); if (start_node->left > 0) { puts("left"); print_ast(start_node->left); } if (start_node->right > 0) { puts("right"); print_ast(start_node->right); } }
static void print_dec(ast_node *n) { printf("<ul>\n"); printf("<li>dec</li>\n"); printf("<li>var:\n"); print_ast(n->dec.var); printf("</li>\n"); printf("<li>init:\n"); print_ast(n->dec.init); printf("</li>\n"); printf("</ul>\n"); }
static void print_compound_stmt(ast_node *n) { printf("<ul>\n"); printf("<li>compound_stmt</li>\n"); printf("<li>defs:\n"); print_ast(n->compound_stmt.defs); printf("</li>\n"); printf("<li>stmts:\n"); print_ast(n->compound_stmt.stmts); printf("</li>\n"); printf("</ul>\n"); }
static void print_indexing(ast_node *n) { printf("<ul>\n"); printf("<li>indexing</li>\n"); printf("<li>postfix:\n"); print_ast(n->indexing.postfix); printf("</li>\n"); printf("<li>expr:\n"); print_ast(n->indexing.expr); printf("</li>\n"); printf("</ul>\n"); }
static void print_func_call(ast_node *n) { printf("<ul>\n"); printf("<li>func_call</li>\n"); printf("<li>postfix:\n"); print_ast(n->func_call.postfix); printf("</li>\n"); printf("<li>args:\n"); print_ast(n->func_call.args); printf("</li>\n"); printf("</ul>\n"); }
static void print_binop(ast_node *n) { printf("<ul>\n"); printf("<li>binop</li>\n"); printf("<li>op: %d</li>\n", n->binop.op); printf("<li>lhs:\n"); print_ast(n->binop.lhs); printf("</li>\n"); printf("<li>rhs:\n"); print_ast(n->binop.rhs); printf("</li>\n"); printf("</ul>\n"); }
static void print_funcdef(ast_node *n) { printf("<ul>\n"); printf("<li>funcdef</li>\n"); printf("<li>ret_type: %d</li>\n", n->funcdef.ret_type); printf("<li>funchead:\n"); print_ast(n->funcdef.funchead); printf("</li>\n"); printf("<li>funcbody:\n"); print_ast(n->funcdef.funcbody); printf("</li>\n"); printf("</ul>\n"); }
/* ========================================= * * This function uses print_ast to print the * * a triangle with n as height. * * ========================================= */ void print_triangle(int n) { int i; for(i = 0; i < n; i++) { print_ast(i); print_char('\n'); } for(i = n; i > 0; i--) { print_ast(i); print_char('\n'); } print_char('\n'); }
static void print_if_stmt(ast_node *n) { printf("<ul>\n"); printf("<li>if_stmt</li>\n"); printf("<li>cond:\n"); print_ast(n->if_stmt.cond); printf("</li>\n"); printf("<li>then:\n"); print_ast(n->if_stmt.then); printf("</li>\n"); printf("<li>els:\n"); print_ast(n->if_stmt.els); printf("</li>\n"); printf("</ul>\n"); }
int main() { int noRoot = 0; /* 0 means we will have a root */ symboltable_t *symtab; list = NULL; /* Build the tree */ error_out = stderr; noRoot = yyparse(); if (parseError && (!noRoot)) fprintf(stderr, "WARNING: There were %d parse errors.\nParse tree may be ill-formed.\n", parseError); if (noRoot) fprintf(stderr, "Parsing reached fatal error. No AST was constructed\n"); /* Set up the symbol tree */ symtab = create_symboltable(); symtab = build_symboltable(symtab, root, root); print_symtab(symtab); print_ast(stdout, root, 0); code_gen(root, symtab); print_quad_list(stdout, list); return 0; }
int main(int argc, char** argv) { if (argc < 2){ printf("usage: scan filename\n"); return -1; } FILE* in = fopen(argv[1], "r"); if (in == NULL){ printf("file not found\n"); return -1; } g_type = (char*)malloc(10); yyset_in(in); int ret = yyparse(); if (ret == 0){ printf("succeeded parsing input.\n"); if (strcmp(argv[2], "1")==0) print_ast(root, 0); } else printf("failed parsing input: error at line %d\n", lineNumber); return 0; }
static int ast(const char *fname, const char *buf, int len, const char *outfile, const MOJOSHADER_preprocessorDefine *defs, unsigned int defcount, FILE *io) { const MOJOSHADER_astData *ad; int retval = 0; ad = MOJOSHADER_parseAst(MOJOSHADER_SRC_PROFILE_HLSL_PS_1_1, // !!! FIXME fname, buf, len, defs, defcount, open_include, close_include, Malloc, Free, NULL); if (ad->error_count > 0) { int i; for (i = 0; i < ad->error_count; i++) { fprintf(stderr, "%s:%d: ERROR: %s\n", ad->errors[i].filename ? ad->errors[i].filename : "???", ad->errors[i].error_position, ad->errors[i].error); } // for } // if else { print_ast(io, 0, ad->ast); if ((outfile != NULL) && (fclose(io) == EOF)) printf(" ... fclose('%s') failed.\n", outfile); else retval = 1; } // else MOJOSHADER_freeAstData(ad); return retval; } // ast
int main() { FILE *ys = fopen("./sample.ys", "w"); int noRoot = 0; /* 0 means we will have a root */ symboltable_t *symtab; list = NULL; /* Build the tree */ error_out = stderr; noRoot = yyparse(); if (parseError && (!noRoot)) fprintf(stderr, "WARNING: There were %d parse errors.\nParse tree may be ill-formed.\n", parseError); if (noRoot) fprintf(stderr, "Parsing reached fatal error. No AST was constructed\n"); /* Set up the symbol tree */ symtab = create_symboltable(); symtab = build_symboltable(symtab, root, root); typecheck_ast(symtab, root); int retval = typecheck_ast(symtab, root); print_checked_ast(stdout, root, 0); if (retval != 0) { fprintf(stderr, "There were %d errors encountered in the parse tree. Aborting.\n", retval); return 1; } print_ast(stdout, root, 0); print_symtab(symtab); code_gen(root, symtab); print_symtab(symtab); print_quad_list(stdout, list); generate_assembly(ys, list, symtab); return 0; }
void calc_parser::print_ast () { if (n_nodes > 1) print_ast (root); else fprintf (outputdesc, "AST is empty.\n\n"); }
void calc_parser::term () { print_symtab (term_symb); // Print the symbol table contents. print_ast (); // Print the AST, if ast option indicates. traverse (); // Traverse the AST, calling the AST actions. term_ast (); term_symtab (); }
static void print_for_stmt(ast_node *n) { printf("<ul>\n"); printf("<li>for_stmt</li>\n"); printf("<li>init:\n"); print_ast(n->for_stmt.init); printf("</li>\n"); printf("<li>cond:\n"); print_ast(n->for_stmt.cond); printf("</li>\n"); printf("<li>incr:\n"); print_ast(n->for_stmt.incr); printf("</li>\n"); printf("<li>body:\n"); print_ast(n->for_stmt.body); printf("</li>\n"); printf("</ul>\n"); }
static void print_expr_stmt(ast_node *n) { printf("<ul>\n"); printf("<li>expr_stmt</li>\n"); printf("<li>expr:\n"); print_ast(n->expr_stmt.expr); printf("</li>\n"); printf("</ul>\n"); }
static void print_return_stmt(ast_node *n) { printf("<ul>\n"); printf("<li>return_stmt</li>\n"); printf("<li>retval:\n"); print_ast(n->return_stmt.retval); printf("</li>\n"); printf("</ul>\n"); }
static void print_subvar(ast_node *n) { printf("<ul>\n"); printf("<li>subvar</li>\n"); printf("<li>index: %d</li>\n", n->subvar.index); printf("<li>var:\n"); print_ast(n->subvar.var); printf("</li>\n"); printf("</ul>\n"); }
static void print_stdef(ast_node *n) { printf("<ul>\n"); printf("<li>stdef</li>\n"); printf("<li>sym_name: %d</li>\n", n->stdef.sym_name); printf("<li>defs:\n"); print_ast(n->stdef.defs); printf("</li>\n"); printf("</ul>\n"); }
static void print_para(ast_node *n) { printf("<ul>\n"); printf("<li>para</li>\n"); printf("<li>para_type: %d</li>\n", n->para.para_type); printf("<li>var:\n"); print_ast(n->para.var); printf("</li>\n"); printf("</ul>\n"); }
static void print_member(ast_node *n) { printf("<ul>\n"); printf("<li>member</li>\n"); printf("<li>sym_name: %d</li>\n", n->member.sym_name); printf("<li>postfix:\n"); print_ast(n->member.postfix); printf("</li>\n"); printf("</ul>\n"); }
static void print_def(ast_node *n) { printf("<ul>\n"); printf("<li>def</li>\n"); printf("<li>def_type: %d</li>\n", n->def.def_type); printf("<li>decs:\n"); print_ast(n->def.decs); printf("</li>\n"); printf("</ul>\n"); }
static void print_postfix(ast_node *n) { printf("<ul>\n"); printf("<li>postfix</li>\n"); printf("<li>op: %d</li>\n", n->postfix.op); printf("<li>unary:\n"); print_ast(n->postfix.unary); printf("</li>\n"); printf("</ul>\n"); }
static void print_funchead(ast_node *n) { printf("<ul>\n"); printf("<li>funchead</li>\n"); printf("<li>sym_name: %d</li>\n", n->funchead.sym_name); printf("<li>paras:\n"); print_ast(n->funchead.paras); printf("</li>\n"); printf("</ul>\n"); }
void print_list(struct list_node* args) { printf("("); struct list_node* aux = args; while (aux != NULL) { print_ast(aux->arg); aux = aux->next; if (aux != NULL) { printf(", "); }; }; printf(")\n"); };
static void print_list(ast_node *n) { printf("<ul>\n"); for (; n; n = n->list.tail) { printf("<li>\n"); print_ast(n->list.head); printf("</li>\n"); } printf("</ul>\n"); }
int main(int argc, char **argv) { ast_node *tree = NULL; VM vm; CTX ctx; char *bytecode; size_t len; IP ip; VALUE closure, result; int parse_ok; char *bootstrap_file_name; char *source_file_name; METHOD_RESULT mr; // Silence GCC -Wunused-function if(0) { yymatchDot(NULL); yyAccept(NULL, 0); } NGS_GC_INIT(); // (causes warning) // NGS_GC_THR_INIT(); yycontext yyctx; memset(&yyctx, 0, sizeof(yycontext)); yyctx.fail_pos = -1; yyctx.fail_rule = "(unknown)"; yyctx.lines = 0; yyctx.lines_postions[0] = 0; bootstrap_file_name = find_bootstrap_file(); if(!bootstrap_file_name) { fprintf(stderr, "Cold not find bootstrap file\n"); exit(100); } if(!strcmp(bootstrap_file_name, "-")) { source_file_name = ngs_strdup("<stdin>"); yyctx.input_file = stdin; } else { source_file_name = bootstrap_file_name; yyctx.input_file = fopen(bootstrap_file_name, "r"); } if(!yyctx.input_file) { fprintf(stderr, "Error while opening bootstrap file '%s': %d - %s\n", bootstrap_file_name, errno, strerror(errno)); exit(101); } parse_ok = yyparse(&yyctx); // printf("parse_ok %d\n", parse_ok); if(!parse_ok) { fprintf(stderr, "NGS: Failed to parse at position %d (%s), rule %s. Exiting.\n", yyctx.fail_pos, sprintf_position(&yyctx, yyctx.fail_pos), yyctx.fail_rule); exit(2); } tree = yyctx.__; IF_DEBUG(COMPILER, print_ast(tree, 0);)
int main() { ast* a = mk_int(123); ast* b = mk_str("ha"); ast_list* lst = conslist(2, a, b); ast* node = mk_node(body_node, lst); print_ast_list(lst); print_ast(node); return 0; }
/* Print the contents of a subtree of an abstract syntax tree, given the root of the subtree and the depth of the subtree root. */ void print_ast(ast_node root, int depth) { /* Print two spaces for every level of depth. */ int i; for (i = 0; i < depth; i++) printf(" "); print_ast_node(root); printf("\n"); /* Recurse on each child of the subtree root, with a depth one greater than the root's depth. */ ast_node child; for (child = root->left_child; child != NULL; child = child->right_sibling) print_ast(child, depth + 1); }