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
12 #include <setjmp.h> //non-local jumps
14 #include <stdlib.h> //exit
15 #include <unistd.h> //getopt
17 #include "parser.tab.h" //bison
20 /* Import apc.c but redefine its primary symbols for jumping */
22 #define yyparse testapc_yyparse
27 int main(int, char*[]);
28 int testapc_yyparse(void);
29 int test_yyparse(void);
36 int scanner_init(void);
38 const char* cargs
['Z'];
40 extern //apc/parser.tab.c
48 /* Ansi Term Colors */
49 #define RED "\x1b[31m"
50 #define GREEN "\x1b[32m"
51 #define YELLOW "\x1b[33m"
52 #define BLUE "\x1b[34m"
53 #define MAGENTA "\x1b[35m"
54 #define CYAN "\x1b[36m"
55 #define CLRC "\x1b[0m" //clear current color
57 /* Main entry from terminal
58 parses debugging options for testing apc, and calls apc_main
64 { setjmp(testapc_jump
);
66 printf(GREEN
"PASS" CLRC
"\n");
71 char tok_lval
[MAX_TOK
];
74 tests yyparse internally, then resets the scanner and runs bison's 'yyparse'
75 implementation after validating it with 'test_yyparse'.
82 { static char bPassedTest
= 'f';
83 if (bPassedTest
== 'f')
85 { printf("Parse test aborted\n");
89 longjmp(testapc_jump
,0);
95 runs 'lexer' 'PASSES' times, or until finished
101 static char* tok_string
;
102 static char tok_pattern
[] = "[" RED
" %9s " CLRC
"][" CYAN
" %-12i " CLRC
"]";
103 for (i
= 0; i
< PASSES
; i
++)
104 { switch (tok
= lexer())
108 #define TOK_CASE(T,C) \
111 tok_pattern[LOFFS] = C; \
113 { TOK_CASE(NAME
,'s');
117 TOK_CASE(CLOPEN
,'i');
118 TOK_CASE(CLCLOSE
,'i');
121 tok_pattern
[LOFFS
] = 'i';
126 if (tok_string
== NULL
)
127 { tok_pattern
[TOFFS
] = 'i';
128 printf(tok_pattern
, tok
, yylval
.val
);
131 { tok_pattern
[TOFFS
] = 's';
132 printf(tok_pattern
, tok_string
, yylval
.val
);
134 if (i
% 4 == 0 || yylval
.val
== 0)
138 printf(";\n" GREEN
"Done" CLRC
".\n");
142 printf(";\n" RED
"FAILED" CLRC
".\n");