2 * Example trivial client program that uses the sparse library
3 * to tokenize, pre-process and parse a C file, and prints out
6 * Copyright (C) 2003 Transmeta Corp.
9 * Licensed under the Open Software License version 1.1
23 #include "expression.h"
25 static void clean_up_symbols(struct symbol_list
*list
)
29 FOR_EACH_PTR(list
, sym
) {
31 } END_FOR_EACH_PTR(sym
);
34 int main(int argc
, char **argv
)
37 char *filename
= NULL
, **args
;
39 struct symbol_list
*list
;
41 // Initialize symbol stream first, so that we can add defines etc
44 create_builtin_stream();
52 args
= handle_switch(arg
+ 1, args
);
58 // Initialize type system
61 fd
= open(filename
, O_RDONLY
);
63 die("No such file: %s", filename
);
65 // Tokenize the input stream
66 token
= tokenize(filename
, fd
, NULL
, includepath
);
69 // Prepend the initial built-in stream
70 token
= tokenize_buffer(pre_buffer
, pre_buffer_size
, token
);
72 // Pre-process the stream
73 token
= preprocess(token
);
75 // Parse the resulting C code
76 list
= translation_unit(token
);
79 clean_up_symbols(list
);
82 // Show the end result.
83 show_symbol_list(list
, "\n\n");
88 // And show the allocation statistics
92 show_expression_alloc();
93 show_statement_alloc();