apc initial implementation
[henge/webcc.git] / src / apc / filescannerparser_old.rl
1 #include <stdio.h>
2 #include <math.h>
3 #include <string.h>
4 #include <dirent.h>
5 #include "fileparser.tab.h"
6 extern FILE* yyin;
7
8 int rinit(void);
9
10 #define MAX_TOK_LEN 32
11 static char buf[MAX_TOK_LEN];
12 static char *p, *pe; /* scanner points to p, pe points to end of buf */
13
14 %%{
15 machine scanner;
16
17 main := |*
18
19 'env_street_road03_0.png' => {ret=VDAT;memmove(rbuf, ts, (te-ts)); yylval.str=strdup(rbuf); printf("Lexer matched with %s\n",yylval.str);fbreak; };
20 '.' => {printf("matched with .\n");fbreak;};
21 '..' => {printf("matched with ..\n");fbreak;};
22
23 *|;
24
25 }%%
26
27 %%write data;
28
29 int
30 rinit()
31 { p = buf;
32 pe = p + fread(buf, 1, MAX_TOK_LEN, yyin);
33 printf("buf in rinit is %s\n", buf);
34 return 0;
35 }
36
37 int
38 yylex()
39 { int ret;
40 static char *eof;
41 char rbuf[MAX_TOK_LEN];
42 int cs, act;
43 char *ts, *te;
44
45 /*init cs, ts, te, act */
46 %%write init;
47 ret = 0;
48
49 %%write exec ;
50 if (te == 0)
51 {
52 if(eof == pe ){
53 return 0;
54 }
55 printf("This is a lexical error, tokens can not be larger than max token length\n buf is = %s | ts = %s | te = %s\n", buf,ts,te);
56 return 0;
57 }
58
59
60 /* We matched a token, remove it from buf and set
61 buf to have rest of unmatched buf (buf - matchedtoken).*/
62 if (!feof(yyin))
63 { int r = pe-te; /* remainder length */
64 memmove(buf, te, r); /* also the max more buf can hold */
65 p = buf;
66 pe = p + r + fread(buf+r,1,MAX_TOK_LEN -r,yyin);
67 }
68 if((p+1) == pe && feof(yyin))
69 eof = pe;
70
71 return ret;
72 }
73
74 /* 'sprites' => {};
75 /0x[xdigit]{8}/ => {};
76 '_' => {};
77 /[digit]{2}/ => {}; /* CC */
78