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