summaryrefslogtreecommitdiff
path: root/test/config8.re
blob: 9c0aa09c6a844570a4415d8009f7d91bf378e749 (plain)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <cstring>
#include <iostream>

struct Scanner
{
	Scanner(char *txt)
		: cur(txt), lim(txt + strlen(txt))
	{
	}
	
	char    *cur;
	char    *lim;
	char	*ptr;
	char	*ctx;
	char    *tok;
};

enum What
{
	UNEXPECTED,
	KEYWORD,
	NUMBER,
	EOI
};

char * tokens[] = { "UNEXPECTED", "KEYWORD", "NUMBER", "EOI" };

void fill(int)
{
}

int scan(Scanner &s)
{
	char *cursor = s.cur;

	if(cursor == s.lim)
		return EOI;
	
std:
	s.tok = cursor;

/*!re2c

re2c:define:YYCTYPE		= char;
re2c:define:YYCURSOR	= s.cur;
re2c:define:YYLIMIT		= s.lim;
re2c:define:YYMARKER	= s.ptr;
re2c:define:YYCTXMARKER	= s.ctx;
re2c:define:YYFILL      = fill;

re2c:variable:yych      = curr;
re2c:labelprefix        = xx;

("a"|"b")/[1]    { return KEYWORD; }
("a"|"b")/[0-9]+ { return KEYWORD; }
[0-9]+           { return NUMBER;  }

[ \t\n]
	{
		if(s.cur == s.lim)
			return EOI;
		cursor = s.cur;
		goto std;
	}
.
	{
		return UNEXPECTED;
	}
*/
}

int main(int,char**)
{
	Scanner s("a77 a1 b8 b1");
	
	int t, n = 0;
	while ((t = scan(s)) != EOI)
	{
		std::cout << (++n) << ": " << tokens[t] << " = \""; std::cout.write(s.tok, s.cur-s.tok); std::cout << "\"" << std::endl;
	}
}