/* Runner File - Compiles alpha Compiler */ /* The Translators - Spring 2025 */ #pragma once #define ALPHA_OFFSET 6 #define TOK_LEN 3 #define ST_LEN 2 #define ASC_LEN 3 #define IR_LEN 2 #define CG_LEN 1 #define HELP \ "HELP:\n" \ " How to run the alpha compiler:\n" \ " ./alpha [options] program\n" \ "Valid options:\n" \ " -tok output the token number, token, line number, and column number for each of the tokens to the .tok file\n" \ " -st output the symbol table for the program to the .st file\n" \ " -asc output the annotated source code for the program to the .asc file, including syntax errors\n" \ " -tc run the type checker and report type errors to the .asc file\n" \ " -ir run the intermediate representation generator, writing output to the .ir file\n" \ " -cg run the (x86 assembly) code generator, writing output to the .s file\n" \ " -debug produce debugging messages to stderr\n" \ " -help print this message and exit the alpha compiler\n" #define SET_FLAG 1 // Used to set flags for arg types #define INVALID \ "INVALID INPUT: Include a .alpha file or use -help for more inputs \n" #include #include #include #include #include #include "../tmp/flex.h" #include "../tmp/grammar.tab.h" #include "codegen.h" #include "intermediate_code.h" #include "symbol_table.h" extern int line_number; extern int column_number; extern char *yytext; extern FILE *yyin; extern bool DEBUG; SymbolTable *top; SymbolTable *cur; FILE *alpha_file; FILE *tok_flag = NULL; FILE *st_flag = NULL; FILE *asc_flag = NULL; FILE *ir_flag = NULL; FILE *cg_flag = NULL; bool tc_flag = false; bool DEBUG = false; int no_flag = 0; int arg; bool contains_errors = false; char *cg_name; char *ir_name; TableNode *funprime; TableNode *arrayprim; TableNode *integ; TableNode *addr; TableNode *chara; TableNode *stri; TableNode *boo; TableNode *recprime; TableNode *funtypeprime; TableNode *undefined; extern Instruction *begin; extern Stack *stack; extern Stack *TrueList; extern Stack *FalseList; int main(int argc, char *argv[]); int check_flag(char *arg, char *alpha); void incr(int lnum, int cnum, int tok); void print_tok(int tok); int run(FILE *alpha); bool is_help(char *input); int new_file(char *arg, char *alpha); int is_alpha_file(char *alpha, int file_len); char *COLOR_RED = "\033[0;31m"; char *COLOR_GREEN = "\033[0;32m"; char *COLOR_ORANGE = "\033[0;33m"; char *COLOR_BLUE = "\033[0;34m"; char *COLOR_PURPLE = "\033[0;35m"; char *COLOR_CYAN = "\033[0;36m"; char *COLOR_LIGHTGRAY = "\033[0;37m"; char *COLOR_DARKGRAY = "\033[1;30m"; char *COLOR_LIGHTRED = "\033[1;31m"; char *COLOR_LIGHTGREEN = "\033[1;32m"; char *COLOR_YELLOW = "\033[1;33m"; char *COLOR_LIGHTBLUE = "\033[1;34m"; char *COLOR_LIGHTPURPLE = "\033[1;35m"; char *COLOR_LIGHTCYAN = "\033[1;36m"; char *COLOR_WHITE = "\033[1;37m"; typedef struct CodeLine { char *line; int line_number; bool is_error; struct CodeLine *next; } CodeLine; CodeLine *code_head; char *file_read_line(FILE *fp); void insert_code_line(char *error_message, int line_number); void append_code_line(CodeLine *code_line); void print_code_lines();