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