From 87cf947e512fbe2acbc8e47e177d299c419a0c98 Mon Sep 17 00:00:00 2001 From: ken Date: Sat, 8 Oct 2016 20:44:08 -0700 Subject: [PATCH] lexer testing complete --- src/apc/lexer.c | 5 +-- src/bin/tools/testapc.c | 91 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 src/bin/tools/testapc.c diff --git a/src/apc/lexer.c b/src/apc/lexer.c index 30566df..1abe5b5 100644 --- a/src/apc/lexer.c +++ b/src/apc/lexer.c @@ -173,11 +173,8 @@ int lexer_lexfile last_period = NULL; for (iter = fname; *iter; iter++) if (*iter == '.') - { if (iter == fname) - last_period = iter; - } + last_period = iter; if (last_period) *last_period = '\0'; - return lexer_lex(fname); } diff --git a/src/bin/tools/testapc.c b/src/bin/tools/testapc.c new file mode 100644 index 0000000..ea9cbe3 --- /dev/null +++ b/src/bin/tools/testapc.c @@ -0,0 +1,91 @@ +/*!@file + \brief APC test driver + \details This driver does what APC does, but in staggered stages with + additional debugging information + \author Jordan Lavatai + \date Aug 2016 + ----------------------------------------------------------------------------*/ +/* Standard */ +#include //print +#include //errors +#include //strnlen +/* Posix */ +#include //exit +#include //getopt +/* Internal */ +#include //bison +#include //ir + +/* Import apc.c but redefine its primary symbols for jumping */ +#define main apc_main +#define yyparse testapc_yyparse +#include +#undef yyparse +#undef main + +int main(int, char*[]); +int testapc_yyparse(void); + +extern //bison +int yyparse(void); +extern //lexer.c +int lexer_init(void); +extern //apc.c +const char* cargs['Z']; + +extern //apc/parser.tab.c +YYSTYPE yylval; +extern //lexer.c +int lexer(void); + +/* Ansi Term Colors */ +#define RED "\x1b[31m" +#define GREEN "\x1b[32m" +#define YELLOW "\x1b[33m" +#define BLUE "\x1b[34m" +#define MAGENTA "\x1b[35m" +#define CYAN "\x1b[36m" +#define CLRC "\x1b[0m" //clear current color + +/* Main entry from terminal + parses debugging options for testing apc, and calls apc_main +*/ +int main +( int argc, + char* argv[] +) +{ apc_main(argc, argv); + printf(GREEN "PASS\n"); + exit(EXIT_SUCCESS); +} + +#define MAX_TOK 1024 +char tok_lval[MAX_TOK]; + +/* yyparse intercept */ +int testapc_yyparse +() +{ int i, tok; + char* tok_pattern = "T[%i]L[%i]"; + char* lval_type = tok_pattern + 8; //location of i + tok_lval[NUM] = 'i'; + tok_lval[STR] = 's'; + tok_lval[SS] = 'i'; + tok_lval[NAME] = 's'; + tok_lval[REF] = 'x'; + tok_lval[SSD] = 'i'; + tok_lval[FPTR] = 'x'; + //lex 10 tokens + printf(YELLOW); + for (i = 0; i < 10; i++) + { if ((tok = lexer()) != 0) + { *lval_type = tok_lval[tok] ? tok_lval[tok] : 'i'; + printf(tok_pattern, tok, yylval.val); + } + else + { printf(";"); + break; + } + } + printf("\n" CLRC); +} -- 2.18.0