summaryrefslogtreecommitdiff
path: root/test/element2.rl
blob: 7aa62173f47a970889f1b0653813ee6bbc20ba34 (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
82
83
/*
 * @LANG: c
 */

#include <stdio.h>

struct LangEl
{
	int key;
	char *name;
};

struct fsm
{
	int cs;
};

%%{
	machine fsm;
	alphtype int;
	getkey fpc->key;
	variable cs fsm->cs;

	action a1 {}
	action a2 {}
	action a3 {}

	main := ( 1 2* 3  ) 
			${printf("%s\n", fpc->name);} 
			%/{printf("accept\n");};
}%%

%% write data;

void fsm_init( struct fsm *fsm )
{
	%% write init;
}

void fsm_execute( struct fsm *fsm,  struct LangEl *_data, int _len )
{
	struct LangEl *p = _data;
	struct LangEl *pe = _data+_len;
	struct LangEl *eof = pe;

	%% write exec;
}

int fsm_finish( struct fsm *fsm )
{
	if ( fsm->cs == fsm_error )
		return -1;
	if ( fsm->cs >= fsm_first_final )
		return 1;
	return 0;
}

int main()
{
	static struct fsm fsm;
	static struct LangEl lel[] = { 
		{1, "one"}, 
		{2, "two-a"}, 
		{2, "two-b"}, 
		{2, "two-c"}, 
		{3, "three"}
	};

	fsm_init( &fsm );
	fsm_execute( &fsm, lel, 5 );
	fsm_finish( &fsm );

	return 0;
}

#ifdef _____OUTPUT_____
one
two-a
two-b
two-c
three
accept
#endif