Ejemplo n.º 1
0
void print_ast_list ( ast_list* r ) {
  if (r == null)
     return;
  printf(" ");
  print_ast_internal(r->elem);
  print_ast_list(r->next);
};
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
0
void print_ast(ast* x, int offset) {
    if (offset) {
        print_offset(offset);
        rstack[offset] = rstack[offset]->next;
    }
    switch (x->tag) {
        case int_ast: fprintf(tree_file, "Integer(%d)\n", x->info.integer); break;
        case real_ast: fprintf(tree_file, "Real(%f)\n", x->info.real); break;
        case var_ast: fprintf(tree_file, "Var(%s)\n", x->info.variable); break;
        case str_ast: fprintf(tree_file, "String(%s)\n", x->info.string); break;
        case node_ast: {
            fprintf(tree_file, "%s [%d:%d-%d:%d]\n", ast_names[x->info.node.tag], x->first_line, x->first_column, x->last_line, x->last_column);
            rstack[offset + 1] = x->info.node.arguments;
            print_ast_list(x->info.node.arguments, offset + 1);
            break;
        };
    };
};
Ejemplo n.º 4
0
void print_ast_internal ( ast* x ) 
{
    if(x)
    {
        switch (x->tag) 
        {
            case int_ast: printf("%ld",x->info.integer); break;
            case real_ast: printf("%lf",x->info.real); break;
            case var_ast: printf("%s",x->info.variable); break;
            case str_ast: printf("\"%s\"",x->info.string); break;
            case node_ast: 
            {
                // deal with indent
                int dtabs = 0;

                if(lastloc && x->location.first_line > lastloc->first_line)
                    dtabs = 1;
                
                lastloc = &x->location;
                tabs += dtabs;

                if(dtabs)
                {
                    printf("\n");
                    for(int i=0; i<tabs; i++)
                        printf("\t");
                }
                
                // print ast
                printf("(%s[%d,%d:%d]",ast_names[x->info.node.tag],
                        x->location.first_line,
                        x->location.first_column, x->location.last_column);
                print_ast_list(x->info.node.arguments);
                printf(")");

                // indent(tail)
                tabs -= dtabs;
                break;
            }
        }
    }
    else printf("(null)");
}
Ejemplo n.º 5
0
void print_ast_list(ast_list* r, int offset) { // print ast use
    if (r == null)
        return;
    print_ast(r->elem, offset);
    print_ast_list(r->next, offset);
};