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