%{ /* * Andrea Di Biagio * Politecnico di Milano, 2007 * * Acse.y * Formal Languages & Compilers Machine, 2007/2008 * */ /************************************************************************* Compiler for the language LANCE ***************************************************************************/ #include #include #include #include "axe_struct.h" #include "axe_engine.h" #include "symbol_table.h" #include "axe_errors.h" #include "collections.h" #include "axe_expressions.h" #include "axe_gencode.h" #include "axe_utils.h" #include "axe_array.h" #include "axe_cflow_graph.h" #include "cflow_constants.h" #include "axe_transform.h" #include "axe_reg_alloc.h" #include "reg_alloc_constants.h" #include "axe_io_manager.h" #ifndef NDEBUG # include "axe_debug.h" #endif /* global variables */ int line_num; /* this variable will keep track of the * source code line number. Every time that a newline * is encountered while parsing the input file, this * value is increased by 1. This value is then used * for error tracking: if the parser returns an error * or a warning, this value is used in order to notify * in which line of code the error has been found */ int num_error; /* the number of errors found in the code. This value * is increased by 1 every time a new error is found * in the code. */ int num_warning; /* As for the `num_error' global variable, this one * keeps track of all the warning messages displayed */ /* errorcode is defined inside "axe_engine.c" */ extern int errorcode; /* this variable is used to test if an error is found * while parsing the input file. It also is set * to notify if the compiler internal state is invalid. * When the parsing process is started, the value * of `errorcode' is set to the value of the macro * `AXE_OK' defined in "axe_constants.h". * As long as everything (the parsed source code and * the internal state of the compiler) is correct, * the value of `errorcode' is set to `AXE_OK'. * When an error occurs (because the input file contains * one or more syntax errors or because something went * wrong in the machine internal state), the errorcode * is set to a value that is different from `AXE_OK'. */ extern int cflow_errorcode; /* As for `errorcode' this value is used to * test if an error occurs during the creation process of * a control flow graph. More informations can be found * analyzing the file `axe_cflow_graph.h'. */ /* program informations */ t_program_infos *program; /* The singleton instance of `program'. * An instance of `t_program_infos' holds in its * internal structure, all the useful informations * about a program. For example: the assembly * (code and directives); the symbol table; * the label manager (see axe_labels.h) etc. */ t_cflow_Graph *graph; /* An instance of a control flow graph. This instance * will be generated starting from `program' and will * be used during the register allocation process */ t_reg_allocator *RA; /* Register allocator. It implements the "Linear scan" * algorythm */ t_io_infos *file_infos; /* input and output files used by the compiler */ %} %expect 1 /*========================================================================= SEMANTIC RECORDS =========================================================================*/ %union { int intval; char *svalue; t_axe_expression expr; t_axe_declaration *decl; t_list *list; t_axe_label *label; t_while_statement while_stmt; } /*========================================================================= TOKENS =========================================================================*/ %start program %token LBRACE RBRACE LPAR RPAR LSQUARE RSQUARE %token SEMI COLON PLUS MINUS MUL_OP DIV_OP MOD_OP %token AND_OP OR_OP NOT_OP %token ASSIGN LT GT SHL_OP SHR_OP EQ NOTEQ LTEQ GTEQ %token ANDAND OROR %token COMMA %token FOR %token RETURN %token READ %token WRITE %token