/*!@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); int test_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" CLRC "\n"); exit(EXIT_SUCCESS); } #define MAX_TOK 1024 char tok_lval[MAX_TOK]; /* yyparse intercept tests yyparse internally, then resets the scanner and runs bison's 'yyparse' implementation after validating it with 'test_yyparse'. */ int testapc_yyparse #ifndef YYABORT #define YYABORT 1 #endif () { static char bPassedTest = 'f'; if (bPassedTest == 'f') { if (test_yyparse()) { printf("Parse test aborted\n"); return YYABORT; } bPassedTest = 't'; apc_main(0,NULL); } return yyparse(); } /* test_yyparse runs 'lexer' 'PASSES' times, or until finished */ int test_yyparse #define PASSES 1000 () { int i, tok; static char tok_pattern[] = "[" RED " %5i " CLRC "][" CYAN " %-12i " CLRC "]"; for (i = 0; i < PASSES; i++) { switch (tok = lexer()) #define OFFS 27 { case STR: case NAME: tok_pattern[OFFS] = 's'; break; case REF: case FPTR: tok_pattern[OFFS] = 'x'; break; case NUM: case SS: case SSD: tok_pattern[OFFS] = 'i'; break; case CLOPEN: case CLCLOSE: case SOPEN: case SCLOSE: case EOPEN: case ECLOSE: case VOPEN: case VCLOSE: case QOPEN: case QCLOSE: case RT: case HB: tok_pattern[OFFS] = 'i'; break; case 0: goto done; default: printf(YELLOW "test_yyparse" CLRC ", unknown token [" RED " %5i " CLRC "]",tok); goto error; } printf(tok_pattern, tok, yylval.val); if (i % 4 == 0 || yylval.val == 1) printf(";\n"); } done: printf(";\n" GREEN "Done" CLRC ".\n"); return 0; error: printf(";\n" RED "FAILED" CLRC ".\n"); return -1; }