lexer testing complete
authorken <ken@mihrtec.com>
Sun, 9 Oct 2016 03:44:08 +0000 (20:44 -0700)
committerken <ken@mihrtec.com>
Sun, 9 Oct 2016 03:44:08 +0000 (20:44 -0700)
src/apc/lexer.c
src/bin/tools/testapc.c [new file with mode: 0644]

index 30566df..1abe5b5 100644 (file)
@@ -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 (file)
index 0000000..ea9cbe3
--- /dev/null
@@ -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 <stdio.h>  //print
+#include <errno.h>  //errors
+#include <string.h> //strnlen
+/* Posix */
+#include <stdlib.h> //exit
+#include <unistd.h> //getopt
+/* Internal */
+#include <apc/parser.tab.h> //bison
+#include <apc/ir.h>         //ir
+
+/* Import apc.c but redefine its primary symbols for jumping */
+#define main apc_main
+#define yyparse testapc_yyparse
+#include <bin/tools/apc.c>
+#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);
+}