2 * Show off concurrent abilities.
23 int execute( const char *data, int len );
35 start_word = cur_char;
38 cout << "word: " << start_word <<
39 " " << cur_char-1 << endl;
42 action start_comment {
43 start_comment = cur_char;
46 cout << "comment: " << start_comment <<
47 " " << cur_char-1 << endl;
50 action start_literal {
51 start_literal = cur_char;
54 cout << "literal: " << start_literal <<
55 " " << cur_char-1 << endl;
59 chars = ( any @next_char )*;
61 # Words are non-whitespace.
62 word = ( any-space )+ >start_word %end_word;
63 words = ( ( word | space ) $1 %0 )*;
65 # Finds C style comments.
66 comment = ( '/*' any* :>> '*/' ) >start_comment %end_comment;
67 comments = ( comment | any )**;
69 # Finds single quoted strings.
70 literalChar = ( any - ['\\] ) | ( '\\' . any );
71 literal = ('\'' literalChar* '\'' ) >start_literal %end_literal;
72 literals = ( ( literal | (any-'\'') ) $1 %0 )*;
74 main := chars | words | comments | literals;
79 int Concurrent::init( )
86 int Concurrent::execute( const char *data, int len )
89 const char *pe = data + len;
93 if ( cs == Concurrent_error )
95 if ( cs >= Concurrent_first_final )
100 int Concurrent::finish( )
102 if ( cs == Concurrent_error )
104 if ( cs >= Concurrent_first_final )
109 Concurrent concurrent;
116 int len = fread( buf, 1, BUFSIZE, stdin );
117 concurrent.execute( buf, len );
118 if ( len != BUFSIZE )
122 if ( concurrent.finish() <= 0 )
123 cerr << "concurrent: error parsing input" << endl;