3 * Show off concurrent abilities.
23 // Initialize the machine. Invokes any init statement blocks. Returns 0
24 // if the machine begins in a non-accepting state and 1 if the machine
25 // begins in an accepting state.
28 // Execute the machine on a block of data. Returns -1 if after processing
29 // the data, the machine is in the error state and can never accept, 0 if
30 // the machine is in a non-accepting state and 1 if the machine is in an
32 void execute( const char *data, int len );
34 // Indicate that there is no more data. Returns -1 if the machine finishes
35 // in the error state and does not accept, 0 if the machine finishes
36 // in any other non-accepting state and 1 if the machine finishes in an
49 start_word = cur_char;
52 cout << "word: " << start_word <<
53 " " << cur_char-1 << endl;
56 action start_comment {
57 start_comment = cur_char;
60 cout << "comment: " << start_comment <<
61 " " << cur_char-1 << endl;
64 action start_literal {
65 start_literal = cur_char;
68 cout << "literal: " << start_literal <<
69 " " << cur_char-1 << endl;
73 chars = ( any @next_char )*;
75 # Words are non-whitespace.
76 word = ( any-space )+ >start_word %end_word;
77 words = ( ( word | space ) $1 %0 )*;
79 # Finds C style comments.
80 comment = ( '/*' any* $0 '*/'@1 ) >start_comment %end_comment;
81 comments = ( ( comment | any ) $1 %0 )*;
83 # Finds single quoted strings.
84 literalChar = ( any - ['\\] ) | ( '\\' . any );
85 literal = ('\'' literalChar* '\'' ) >start_literal %end_literal;
86 literals = ( ( literal | (any-'\'') ) $1 %0 )*;
88 main := chars | words | comments | literals;
93 void Concurrent::init( )
99 void Concurrent::execute( const char *data, int len )
101 const char *p = data;
102 const char *pe = data + len;
107 int Concurrent::finish( )
110 if ( cs == Concurrent_error )
112 if ( cs >= Concurrent_first_final )
117 void test( char *buf )
119 Concurrent concurrent;
121 concurrent.execute( buf, strlen(buf) );
122 if ( concurrent.finish() > 0 )
123 cout << "ACCEPT" << endl;
125 cout << "FAIL" << endl;
132 " * ' and now in a literal string\n"
135 "the comment has now ended but the literal string lives on\n"
137 "' comment closed\n" );
138 test( "/* * ' \\' */ \\' '\n" );
139 test( "/**/'\\''/*/*/\n" );
143 #ifdef _____OUTPUT_____