3 \details This driver does what APC does, but in staggered stages with
4 additional debugging information
7 ----------------------------------------------------------------------------*/
9 #include <stdio.h> //print
10 #include <errno.h> //errors
11 #include <string.h> //strnlen
13 #include <stdlib.h> //exit
14 #include <unistd.h> //getopt
16 #include <apc/parser.tab.h> //bison
17 #include <apc/ir.h> //ir
19 /* Import apc.c but redefine its primary symbols for jumping */
21 #define yyparse testapc_yyparse
22 #include <bin/tools/apc.c>
26 int main(int, char*[]);
27 int testapc_yyparse(void);
28 int test_yyparse(void);
35 const char* cargs
['Z'];
37 extern //apc/parser.tab.c
42 /* Ansi Term Colors */
43 #define RED "\x1b[31m"
44 #define GREEN "\x1b[32m"
45 #define YELLOW "\x1b[33m"
46 #define BLUE "\x1b[34m"
47 #define MAGENTA "\x1b[35m"
48 #define CYAN "\x1b[36m"
49 #define CLRC "\x1b[0m" //clear current color
51 /* Main entry from terminal
52 parses debugging options for testing apc, and calls apc_main
58 { apc_main(argc
, argv
);
59 printf(GREEN
"PASS" CLRC
"\n");
64 char tok_lval
[MAX_TOK
];
67 tests yyparse internally, then resets the scanner and runs bison's 'yyparse'
68 implementation after validating it with 'test_yyparse'.
75 { static char bPassedTest
= 'f';
76 if (bPassedTest
== 'f')
78 { printf("Parse test aborted\n");
88 runs 'lexer' 'PASSES' times, or until finished
94 static char tok_pattern
[] = "[" RED
" %5i " CLRC
"][" CYAN
" %-12i " CLRC
"]";
95 for (i
= 0; i
< PASSES
; i
++)
96 { switch (tok
= lexer())
100 tok_pattern
[OFFS
] = 's';
104 tok_pattern
[OFFS
] = 'x';
109 tok_pattern
[OFFS
] = 'i';
123 tok_pattern
[OFFS
] = 'i';
128 printf(YELLOW
"test_yyparse" CLRC
", unknown token [" RED
" %5i " CLRC
"]",tok
);
131 printf(tok_pattern
, tok
, yylval
.val
);
132 if (i
% 4 == 0 || yylval
.val
== 1)
136 printf(";\n" GREEN
"Done" CLRC
".\n");
139 printf(";\n" RED
"FAILED" CLRC
".\n");