6732b7dbac8b1a2b46b6e5f0861a35d1243b54cd
[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
7 static volatile 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 T = PSI_TokenAlloc(L, t);
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 void *P = PSI_ParserAlloc(malloc);
34
35 TRACE = !!getenv("TRACE");
36
37 if (!PSI_LexerInit(&L, argv[1])) {
38 perror("Failed to init lexer");
39 return 1;
40 }
41
42 loop(&L, P);
43
44 PSI_ParserFree(P, free);
45 PSI_LexerDtor(&L);
46
47 return 0;
48 }