start validator
[m6w6/ext-psi] / idl / main.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include "lexer.h"
5 #include "parser.h"
6 #include "validator.h"
7
8 static int TRACE;
9
10 static void loop(PSI_Lexer *L, void *P)
11 {
12 token_t t;
13 PSI_Token *T = NULL;
14
15 if (TRACE) {
16 PSI_ParserTrace(stdout, "> ");
17 }
18
19 while (-1 != (t = PSI_LexerScan(L))) {
20 if (!(T = PSI_TokenAlloc(L, t))) {
21 break;
22 }
23
24 if (TRACE) {
25 printf("# Token: <%s>(%d)\n", T->text, t);
26 }
27
28 PSI_Parser(P, t, T, L);
29 }
30 PSI_Parser(P, 0, T, L);
31 }
32
33 int main(int argc, char *argv[])
34 {
35 PSI_Lexer L;
36 PSI_Validator V;
37 void *P = PSI_ParserAlloc(malloc);
38
39 TRACE = !!getenv("TRACE");
40
41 if (!PSI_LexerInit(&L, argv[1])) {
42 perror("Failed to init lexer");
43 return 1;
44 }
45
46 loop(&L, P);
47
48 PSI_ParserFree(P, free);
49
50 if (!PSI_ValidatorInit(&V, &L)) {
51 perror("Failed to init validator");
52 return 2;
53 }
54
55 PSI_LexerDtor(&L);
56
57 if (PSI_ValidatorValidate(&V)) {
58 printf("Whoa! VALID.\n");
59 }
60 PSI_ValidatorDtor(&V);
61
62 return 0;
63 }