X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=idl%2Fmain.c;h=b4eb459004a3974f731f49704fa30647d17f1e3c;hp=c4664be36b45d426523d69d9487a0bfb0f0520ea;hb=f1a387482a9270a34ae684109ad8be7c104148d6;hpb=ca787916893fd2124a4dd72d326e3435fad5b9c8 diff --git a/idl/main.c b/idl/main.c index c4664be..b4eb459 100644 --- a/idl/main.c +++ b/idl/main.c @@ -2,56 +2,34 @@ #include #include -#include "main.h" +#include "parser.h" +#include "validator.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); -} - int main(int argc, char *argv[]) { - PSI_Lexer L; + PSI_Parser P; PSI_Validator V; - void *P = PSI_ParserAlloc(malloc); TRACE = !!getenv("TRACE"); - if (!PSI_LexerInit(&L, argv[1])) { - perror("Failed to init lexer"); + if (!PSI_ParserInit(&P, argv[1])) { + perror("Failer to init parser"); return 1; } - loop(&L, P); - - 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");