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_string
;
95 static char tok_pattern
[] = "[" RED
" %9s " CLRC
"][" CYAN
" %-12i " CLRC
"]";
96 for (i
= 0; i
< PASSES
; i
++)
97 { switch (tok
= lexer())
101 #define TOK_CASE(T,C) \
104 tok_pattern[LOFFS] = C; \
113 TOK_CASE(CLOPEN
,'i');
114 TOK_CASE(CLCLOSE
,'i');
117 tok_pattern
[LOFFS
] = 'i';
122 if (tok_string
== NULL
)
123 { tok_pattern
[TOFFS
] = 'i';
124 printf(tok_pattern
, tok
, yylval
.val
);
127 { tok_pattern
[TOFFS
] = 's';
128 printf(tok_pattern
, tok_string
, yylval
.val
);
130 if (i
% 4 == 0 || yylval
.val
== 0)
134 printf(";\n" GREEN
"Done" CLRC
".\n");
137 printf(";\n" RED
"FAILED" CLRC
".\n");