projects
/
henge
/
webcc.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
b2f14e9
)
testing through yyparse
author
ken
<ken@mihrtec.com>
Fri, 21 Oct 2016 17:37:06 +0000
(10:37 -0700)
committer
ken
<ken@mihrtec.com>
Fri, 21 Oct 2016 17:37:06 +0000
(10:37 -0700)
src/bin/tools/testapc.c
patch
|
blob
|
history
diff --git
a/src/bin/tools/testapc.c
b/src/bin/tools/testapc.c
index
755cf74
..
1aca9b3
100644
(file)
--- a/
src/bin/tools/testapc.c
+++ b/
src/bin/tools/testapc.c
@@
-25,6
+25,7
@@
int main(int, char*[]);
int testapc_yyparse(void);
int main(int, char*[]);
int testapc_yyparse(void);
+int test_yyparse(void);
extern //bison
int yyparse(void);
extern //bison
int yyparse(void);
@@
-55,19
+56,43
@@
int main
char* argv[]
)
{ apc_main(argc, argv);
char* argv[]
)
{ apc_main(argc, argv);
- printf(GREEN "PASS\n");
+ printf(GREEN "PASS
" CLRC "
\n");
exit(EXIT_SUCCESS);
}
#define MAX_TOK 1024
char tok_lval[MAX_TOK];
exit(EXIT_SUCCESS);
}
#define MAX_TOK 1024
char tok_lval[MAX_TOK];
-/* yyparse intercept */
+/* yyparse intercept
+ tests yyparse internally, then resets the scanner and runs bison's 'yyparse'
+ implementation after validating it with 'test_yyparse'.
+*/
int testapc_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 "]";
()
{ int i, tok;
static char tok_pattern[] = "[" RED " %5i " CLRC "][" CYAN " %-12i " CLRC "]";
- for (i = 0; i <
1000
; i++)
+ for (i = 0; i <
PASSES
; i++)
{ switch (tok = lexer())
#define OFFS 27
{ case STR:
{ switch (tok = lexer())
#define OFFS 27
{ case STR:
@@
-81,16
+106,36
@@
int testapc_yyparse
case NUM:
case SS:
case SSD:
case NUM:
case SS:
case SSD:
- default:
+ 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:
tok_pattern[OFFS] = 'i';
break;
case 0:
- printf(";\n" GREEN "Done" CLRC ".\n");
- return 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");
}
}
printf(tok_pattern, tok, yylval.val);
if (i % 4 == 0 || yylval.val == 1)
printf(";\n");
}
- printf("\n" CLRC);
+ done:
+ printf(";\n" GREEN "Done" CLRC ".\n");
+ return 0;
+ error:
+ printf(";\n" RED "FAILED" CLRC ".\n");
+ return -1;
}
}