📄 main.c
字号:
#include "declaration.h"#include "error.h"#include "expression.h"#include "list.h"#include "io.h"#include "scope.h"#include <stdlib.h>static const char *input_file = 0;static void read_command_line(int argc, char **argv){ int i; for (i = 1; i < argc; i++) { if (argv [i][0] == '-') { switch (argv [i][1]) { case 'I' : list_append(search_path, argv [i] + 2); break; default : error(0, "unknown option -%c", argv [i][1]); exit(1); } } else if (input_file != 0) { error(0, "multiple input files specified"); exit(1); } else input_file = argv [i]; }}static void init(int argc, char **argv){ search_path = new_list(); string_list = new_list(); read_command_line(argc, argv); open_input_file(input_file); open_output_files();}static void semantic_analyses(void){ type_check_declaration_list(global_declarations);}static void code_generation(void){ generate_declaration_list(global_declarations); generate_string_list();}static void terminate(void){ delete_declaration_list(global_declarations); delete_scope(global_scope); close_files(); delete_list(string_list); delete_list(search_path);}/* -------------- PROCESSING STARTS HERE! -------------- */int main(int argc, char **argv){ int yyparse(void); /* Open in- and output files */ init(argc, argv); /* Parse the source file * Build the AST using yacc (which in turn uses flex). * This also sets up the scopes. The global scope is created in the * yacc rule 'program', the scopes for subprogrammes are created in * name_and_argument_list, and those for compound statement in * compound_statement. */ yyparse(); /* Now we have an AST, stored in the global variable global_declarations. * Next, we invoke the type checking phase on that list. */ semantic_analyses(); /* If type checking didn't produce any errors (error_seen is set by * the error() function (see error.h), start the code generation phase, * again using the global_declarations list. */ if (!error_seen) code_generation(); /* Finally, clean up by deleting the global variables (AST, scopes, * string list, etc.) and close all open files. */ terminate(); /* If a error occurred, return 1 so a programme calling the compiler * knows about it (make for instance). */ return error_seen ? 1 : 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -