Initialize Tizen 2.3
[external/ragel.git] / test / minimize1.rl
1 /*
2  * @LANG: c
3  */
4
5 #include <stdio.h>
6 #include <string.h>
7
8 struct min
9 {
10         int cs;
11 };
12
13 %%{
14         machine min;
15         variable cs fsm->cs;
16
17         action a_or_b { printf("a or b\n"); }
18
19         main := (
20                 ( 'a' . [ab]* @a_or_b ) |
21                 ( 'b' . [ab]* @a_or_b ) 
22         ) . '\n';
23 }%%
24
25 %% write data;
26
27 void min_init( struct min *fsm )
28 {
29         %% write init;
30 }
31
32 void min_execute( struct min *fsm, const char *_data, int _len )
33 {
34         const char *p = _data;
35         const char *pe = _data+_len;
36
37         %% write exec;
38 }
39
40 int min_finish( struct min *fsm )
41 {
42         if ( fsm->cs == min_error )
43                 return -1;
44         if ( fsm->cs >= min_first_final )
45                 return 1;
46         return 0;
47 }
48
49 struct min fsm;
50
51 void test( char *buf )
52 {
53         int len = strlen( buf );
54         min_init( &fsm );
55         min_execute( &fsm, buf, len );
56         if ( min_finish( &fsm ) > 0 )
57                 printf("ACCEPT\n");
58         else
59                 printf("FAIL\n");
60 }
61
62
63 int main()
64 {
65         test( "aaaaaa\n" );
66         test( "a\n" );
67         test( "abc\n" );
68         return 0;
69 }
70
71 #ifdef _____OUTPUT_____
72 a or b
73 a or b
74 a or b
75 a or b
76 a or b
77 ACCEPT
78 ACCEPT
79 a or b
80 FAIL
81 #endif