summaryrefslogtreecommitdiff
path: root/test/gotocallret2.rl
blob: 4a3bc0ef9b80824c833d41fcb14437b2343c1ecf (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
/*
 * @LANG: indep
 */

char comm;
int top;
int stack[32];
ptr tokstart;
ptr tokend;
int act;
int val;
%%
%%{
	machine GotoCallRet;

	sp = ' ';

	handle := any @{ 
		prints "handle ";
		fhold; 
		if ( val == 1 ) fnext *fentry(one); 
		if ( val == 2 ) fnext *fentry(two); 
		if ( val == 3 ) fnext main;
	};

	one := |*
		'{' => { prints "{ "; fcall *fentry(one); };
		"[" => { prints "[ "; fcall *fentry(two); };
		"}" sp* => { prints "} "; fret; };
		[a-z]+ => { prints "word "; val = 1; fgoto *fentry(handle); };
		' ' => { prints "space "; };
	*|;

	two := |*
		'{' => { prints "{ "; fcall *fentry(one); };
		"[" => { prints "[ "; fcall *fentry(two); };
		']' sp* => { prints "] "; fret; };
		[a-z]+ => { prints "word "; val = 2; fgoto *fentry(handle); };
		' ' => { prints "space "; };
	*|;

	main := |* 
		'{' => { prints "{ "; fcall one; };
		"[" => { prints "[ "; fcall two; };
		[a-z]+ => { prints "word "; val = 3; fgoto handle; };
		[a-z] ' foil' => { prints "this is the foil";};
		' ' => { prints "space "; };
		'\n';
	*|;
}%%
/* _____INPUT_____
"{a{b[c d]d}c}\n"
"[a{b[c d]d}c}\n"
"[a[b]c]d{ef{g{h}i}j}l\n"
"{{[]}}\n"
"a b c\n"
"{a b c}\n"
"[a b c]\n"
"{]\n"
"{{}\n"
"[[[[[[]]]]]]\n"
"[[[[[[]]}]]]\n"
_____INPUT_____ */
/* _____OUTPUT_____
{ word handle { word handle [ word handle space word handle ] word handle } word handle } ACCEPT
[ word handle { word handle [ word handle space word handle ] word handle } word handle FAIL
[ word handle [ word handle ] word handle ] word handle { word handle { word handle { word handle } word handle } word handle } word handle ACCEPT
{ { [ ] } } ACCEPT
word handle space word handle space word handle ACCEPT
{ word handle space word handle space word handle } ACCEPT
[ word handle space word handle space word handle ] ACCEPT
{ FAIL
{ { } FAIL
[ [ [ [ [ [ ] ] ] ] ] ] ACCEPT
[ [ [ [ [ [ ] ] FAIL
_____OUTPUT_____ */