#include <stdio.h> //print
#include <errno.h> //errors
#include <string.h> //strnlen
+#include <setjmp.h> //non-local jumps
/* Posix */
#include <stdlib.h> //exit
#include <unistd.h> //getopt
int test_yyparse(void);
extern //bison
-int yyparse(void);
+int yyparse(void);
extern //lexer.c
int lexer_init(void);
+extern //scanner.c
+int scanner_init(void);
extern //apc.c
const char* cargs['Z'];
extern //lexer.c
int lexer(void);
+static
+jmp_buf testapc_jump;
+
/* Ansi Term Colors */
#define RED "\x1b[31m"
#define GREEN "\x1b[32m"
( int argc,
char* argv[]
)
-{ apc_main(argc, argv);
+{ setjmp(testapc_jump);
+ apc_main(argc, argv);
printf(GREEN "PASS" CLRC "\n");
exit(EXIT_SUCCESS);
}
return YYABORT;
}
bPassedTest = 't';
- apc_main(0,NULL);
+ longjmp(testapc_jump,0);
}
return yyparse();
}
#define PASSES 1000
()
{ int i, tok;
- static char tok_pattern[] = "[" RED " %5i " CLRC "][" CYAN " %-12i " CLRC "]";
+ static char* tok_string;
+ static char tok_pattern[] = "[" RED " %9s " 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';
+ #define TOFFS 9
+ #define LOFFS 27
+ #define $($)#$
+ #define TOK_CASE(T,C) \
+ case T: \
+ tok_string = $(T); \
+ tok_pattern[LOFFS] = C; \
+ break
+ { TOK_CASE(STR,'s');
+ TOK_CASE(NAME,'s');
+ TOK_CASE(REF,'x');
+ TOK_CASE(FPTR,'x');
+ TOK_CASE(NUM,'i');
+ TOK_CASE(SS,'i');
+ TOK_CASE(SSD,'i');
+ TOK_CASE(CLOPEN,'i');
+ TOK_CASE(CLCLOSE,'i');
+ default:
+ tok_string = 0;
+ tok_pattern[LOFFS] = '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)
+ if (tok_string == NULL)
+ { tok_pattern[TOFFS] = 'i';
+ printf(tok_pattern, tok, yylval.val);
+ }
+ else
+ { tok_pattern[TOFFS] = 's';
+ printf(tok_pattern, tok_string, yylval.val);
+ }
+ if (i % 4 == 0 || yylval.val == 0)
printf(";\n");
}
done: