/
bf.h
67 lines (56 loc) · 1014 Bytes
/
bf.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdio.h>
#define c g->code
#define p g->pointer
#define f g->file
struct Data {
const char *code;
char vars[30000];
char *pointer;
};
void dummyLexer(struct Data *g) { while(*c) if(*c++ == ']') return; }
void lexer(struct Data *g) {
const char *cc = c;
while(*c) {
switch (*c++) {
case '>':
++p;
break;
case '<':
--p;
break;
case '+':
++*p;
break;
case '-':
--*p;
break;
case '.':
putchar(*p);
break;
case ',':
*p = getchar();
break;
case '[':
cc = c;
if(!*p) dummyLexer(g);
while(*p) {
c = cc; // restore char position to start of loop
lexer(g);
}
break;
case ']':
return;
default:
// everything else is comments
break;
}
}
return;
}
/*
* Usage:
* struct Data g;
* g.code = file;
* g.pointer = &g.data[15000];
* lexer(&g);
*/