2 * Show off concurrent abilities.
23 int execute( const char *data, int len, bool isEof );
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, bool isEof )
89 const char *pe = data + len;
90 const char *eof = isEof ? pe : 0;
94 if ( cs == Concurrent_error )
96 if ( cs >= Concurrent_first_final )
101 int Concurrent::finish( )
103 if ( cs == Concurrent_error )
105 if ( cs >= Concurrent_first_final )
110 Concurrent concurrent;
117 int len = fread( buf, 1, BUFSIZE, stdin );
118 concurrent.execute( buf, len, len != BUFSIZE );
119 if ( len != BUFSIZE )
123 if ( concurrent.finish() <= 0 )
124 cerr << "concurrent: error parsing input" << endl;