/*!@file \brief APC test driver \details This driver does what APC does, but in staggered stages with additional debugging information \author Jordan Lavatai \date Aug 2016 ----------------------------------------------------------------------------*/ /* Standard */ #include //print #include //errors #include //strnlen /* Posix */ #include //exit #include //getopt /* Internal */ #include //bison #include //ir /* Import apc.c but redefine its primary symbols for jumping */ #define main apc_main #define yyparse testapc_yyparse #include #undef yyparse #undef main int main(int, char*[]); int testapc_yyparse(void); extern //bison int yyparse(void); extern //lexer.c int lexer_init(void); extern //apc.c const char* cargs['Z']; extern //apc/parser.tab.c YYSTYPE yylval; extern //lexer.c int lexer(void); /* Ansi Term Colors */ #define RED "\x1b[31m" #define GREEN "\x1b[32m" #define YELLOW "\x1b[33m" #define BLUE "\x1b[34m" #define MAGENTA "\x1b[35m" #define CYAN "\x1b[36m" #define CLRC "\x1b[0m" //clear current color /* Main entry from terminal parses debugging options for testing apc, and calls apc_main */ int main ( int argc, char* argv[] ) { apc_main(argc, argv); printf(GREEN "PASS\n"); exit(EXIT_SUCCESS); } #define MAX_TOK 1024 char tok_lval[MAX_TOK]; /* yyparse intercept */ int testapc_yyparse () { int i, tok; char* tok_pattern = "T[%i]L[%i]"; char* lval_type = tok_pattern + 8; //location of i tok_lval[NUM] = 'i'; tok_lval[STR] = 's'; tok_lval[SS] = 'i'; tok_lval[NAME] = 's'; tok_lval[REF] = 'x'; tok_lval[SSD] = 'i'; tok_lval[FPTR] = 'x'; //lex 10 tokens printf(YELLOW); for (i = 0; i < 10; i++) { if ((tok = lexer()) != 0) { *lval_type = tok_lval[tok] ? tok_lval[tok] : 'i'; printf(tok_pattern, tok, yylval.val); } else { printf(";"); break; } } printf("\n" CLRC); }