#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#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;
}