X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=idl%2Fmain.c;h=db88740e2ef5be487836dc0ebbef2769713e0561;hp=fe49647bf49b398229c3f48c3ac0aa19bd2ce2f8;hb=94fbd01435494508cb54d6321c7d745b94949475;hpb=5917ec1de81d919ac670af18166a41238aa1d3f6 diff --git a/idl/main.c b/idl/main.c index fe49647..db88740 100644 --- a/idl/main.c +++ b/idl/main.c @@ -1,50 +1,41 @@ #include #include #include -#include "lexer.h" -#include "parser.h" -static int TRACE; +#include "parser.h" +#include "validator.h" -static void loop(PSI_Lexer *L, void *P) +int main(int argc, char *argv[]) { - token_t t; - PSI_Token *T = NULL; + PSI_Parser P; + PSI_Validator V; + unsigned flags = 0; - if (TRACE) { - PSI_ParserTrace(stdout, "> "); + if (getenv("TRACE")) { + flags |= PSI_PARSER_DEBUG; } - 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); + if (!PSI_ParserInit(&P, argv[1], flags)) { + perror("Failer to init parser"); + return 1; } - PSI_Parser(P, 0, T, L); -} - -int main(int argc, char *argv[]) -{ - PSI_Lexer L; - void *P = PSI_ParserAlloc(malloc); - TRACE = !!getenv("TRACE"); + while (-1 != PSI_ParserScan(&P)) { + PSI_ParserParse(&P, PSI_TokenAlloc(&P)); + }; + PSI_ParserParse(&P, NULL); - if (!PSI_LexerInit(&L, argv[1])) { - perror("Failed to init lexer"); - return 1; + if (!PSI_ValidatorInit(&V, &P)) { + perror("Failed to init validator"); + return 2; } - loop(&L, P); + PSI_ParserDtor(&P); - PSI_ParserFree(P, free); - PSI_LexerDtor(&L); + if (PSI_ValidatorValidate(&V)) { + printf("Whoa! VALID.\n"); + } + PSI_ValidatorDtor(&V); return 0; }