int main() { GC_INIT(); // Create the input file. // Right now, this requires an actual file, but on non-mac os x // systems, there is a function fmemopen() which lets you open // an in-memory buffer as a file handle. There are shims for it on // mac os x, but its more complex than it needs to be FILE *input = fopen("example.lisp", "r"); // Create the parser state object. This could probably be moved into parse() // but for now you need to do it seperately struct p_state state = new_p_state(input); // parse the lisp code into an ast struct sexp *parsed = parse(&state); // Display the resulting ast print_ast_node(parsed[0]); printf("\n********************\n"); scm *res = run_lisp(parsed[0]); printf("RESULT: "); print_scm(res); printf("\n"); }
/* 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); }