Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ast.h"
- #include <stdio.h>
- void print_spaces( int n ) {
- printf("\n");
- for(int i = 0; i < n; ++i) {
- printf(" ");
- }
- }
- static void print_native_type( enum native_types type ) {
- switch( type ) {
- case INT:
- printf("INT");
- case CHAR:
- printf("CHAR");
- case FLOAT:
- printf("FLOAT");
- case BOOL:
- printf("BOOL");
- }
- }
- static void print_type( struct type* type) {
- if( type->tag == SINGLE ) {
- print_native_type( type->single.type );
- }
- else {
- printf("[");
- print_type( type->seq.next );
- printf("]");
- }
- }
- void print_var( int n_spaces, struct var *v ) {
- print_spaces( n_spaces );
- print_type( v->type );
- printf(" %s\n", v->name );
- if( v->next != NULL ) {
- print_var( n_spaces, v->next );
- }
- }
- void print_params( struct param* param ) {
- print_type( param->type );
- if( param->next != NULL ) {
- printf(", ");
- print_params( param->next );
- }
- }
- void print_func( int n_spaces, struct func* f ) {
- print_spaces( n_spaces );
- printf("FUNC< ");
- print_type( f->type );
- printf(" > ");
- printf(" %s, ", f->name );
- printf("PARAMS = {");
- print_params( f->param );
- printf("}\n");
- if( f->next != NULL ) {
- print_func( n_spaces, f->next );
- }
- }
- void print_tree() {
- print_var( GLOBAL_TREE->vars );
- print_func( GLOBAL_TREE->funcs );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement