flush
[m6w6/ext-psi] / idl / main.c
index b132bbd3813f6e97029103abe845ace2305138f7..db88740e2ef5be487836dc0ebbef2769713e0561 100644 (file)
@@ -2,58 +2,35 @@
 #include <stdlib.h>
 #include <string.h>
 
-static int TRACE;
-
-static void loop(PSI_Lexer *L, void *P)
-{
-       token_t t;
-       PSI_Token *T = NULL;
-
-       if (TRACE) {
-               PSI_ParserTrace(stdout, "> ");
-       }
-
-       while (-1 != (t = PSI_LexerScan(L))) {
-               if (!(T = PSI_TokenAlloc(L, t))) {
-                       break;
-               }
-
-               if (TRACE) {
-                       printf("# Token: <%s>(%d)\n", T->text, t);
-               }
-
-               PSI_Parser(P, t, T, L);
-       }
-       PSI_Parser(P, 0, T, L);
-}
+#include "parser.h"
+#include "validator.h"
 
 int main(int argc, char *argv[])
 {
-       PSI_Lexer L;
        PSI_Parser P;
        PSI_Validator V;
+       unsigned flags = 0;
 
-       TRACE = !!getenv("TRACE");
-
-       if (!PSI_LexerInit(&L, argv[1])) {
-               perror("Failed to init lexer");
-               return 1;
+       if (getenv("TRACE")) {
+               flags |= PSI_PARSER_DEBUG;
        }
-       if (!PSI_ParserInit(&P)) {
+
+       if (!PSI_ParserInit(&P, argv[1], flags)) {
                perror("Failer to init parser");
                return 1;
        }
 
-       while (PSI_ParserParse(&p, &L));
-
-       PSI_ParserFree(P, free);
+       while (-1 != PSI_ParserScan(&P)) {
+               PSI_ParserParse(&P, PSI_TokenAlloc(&P));
+       };
+       PSI_ParserParse(&P, NULL);
 
-       if (!PSI_ValidatorInit(&V, &L)) {
+       if (!PSI_ValidatorInit(&V, &P)) {
                perror("Failed to init validator");
                return 2;
        }
 
-       PSI_LexerDtor(&L);
+       PSI_ParserDtor(&P);
 
        if (PSI_ValidatorValidate(&V)) {
                printf("Whoa! VALID.\n");