X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=idl%2Fmain.c;h=db88740e2ef5be487836dc0ebbef2769713e0561;hp=6732b7dbac8b1a2b46b6e5f0861a35d1243b54cd;hb=94fbd01435494508cb54d6321c7d745b94949475;hpb=6ed7825ca4ddea88b00968e20cbaeeb1e8eb3de4 diff --git a/idl/main.c b/idl/main.c index 6732b7d..db88740 100644 --- a/idl/main.c +++ b/idl/main.c @@ -1,48 +1,41 @@ #include #include #include -#include "lexer.h" -#include "parser.h" -static volatile 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))) { - T = PSI_TokenAlloc(L, t); - - 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; }