+ struct ctf_ast *ast;
+
+ ast = malloc(sizeof(*ast));
+ if (!ast)
+ return NULL;
+ memset(ast, 0, sizeof(*ast));
+ return ast;
+}
+
+static void ctf_ast_free(struct ctf_ast *ast)
+{
+}
+
+int ctf_scanner_append_ast(struct ctf_scanner *scanner)
+{
+ return yyparse(scanner);
+}
+
+struct ctf_scanner *ctf_scanner_alloc(FILE *input)
+{
+ struct ctf_scanner *scanner;
+ int ret;
+
+ scanner = malloc(sizeof(*scanner));
+ if (!scanner)
+ return NULL;
+ memset(scanner, 0, sizeof(*scanner));
+
+ ret = yylex_init_extra(scanner, &scanner->scanner);
+ if (ret) {
+ fprintf(stderr, "yylex_init error\n");
+ goto cleanup_scanner;
+ }
+ yyset_in(input, scanner);
+
+ scanner->ast = ctf_ast_alloc();
+ if (!scanner->ast)
+ goto cleanup_lexer;
+ init_scope(&scanner->root_scope, NULL);
+ CDS_INIT_LIST_HEAD(&scanner->allocated_strings);
+
+ return scanner;
+
+cleanup_lexer:
+ ret = yylex_destroy(scanner->scanner);
+ if (!ret)
+ fprintf(stderr, "yylex_destroy error\n");
+cleanup_scanner:
+ free(scanner);
+ return NULL;
+}
+
+void ctf_scanner_free(struct ctf_scanner *scanner)
+{
+ int ret;
+
+ finalize_scope(&scanner->root_scope);
+ free_strings(&scanner->allocated_strings);
+ ctf_ast_free(scanner->ast);
+ ret = yylex_destroy(scanner->scanner);
+ if (ret)
+ fprintf(stderr, "yylex_destroy error\n");
+ free(scanner);
+}