// Takes a list of tokens from a Racket program, and returns a pointer to a // parse tree representing that program. Value *parse(Value *tokens){ Value *tree = makeNull(); int depth = 0; Value *current = tokens; assert(current != NULL && "Error (parse): null pointer"); //loop through all tokens while (current->type != NULL_TYPE) { Value *token = car(current); tree = addToParseTree(tree,&depth,token); current = cdr(current); } if (depth != 0) { printf("Syntax error: not enough close parentheses.\n"); texit(EXIT_FAILURE); } //tree is backwards at this point, so reverse here tree = reverse(tree); return tree; }
// Takes a list of tokens from a Racket program, and returns a pointer to a // parse tree representing that program. Value *parse(Value *tokens) { Value *tree = makeNull(); int depth = 0; // loop over the tokens and pass them to addToParseTree which handles // them correctly depending on what they are. Value *current = tokens; assert(current != NULL && "Error (parse): null pointer"); while (current->type != NULL_TYPE) { Value *token = car(current); tree = addToParseTree(tree, &depth, token); current = cdr(current); } // make sure there were enough parentheses. if (depth != 0) { printf("Syntax error: not enough close parentheses.\n"); texit(1); } tree = reverse(tree); return tree; }