13 #define TK_NameSep 197
15 #define TK_PlusPlus 212
16 #define TK_MinusMinus 213
17 #define TK_ArrowStar 214
18 #define TK_DotStar 215
19 #define TK_ShiftLeft 216
20 #define TK_ShiftRight 217
21 #define TK_IntegerDecimal 218
22 #define TK_IntegerOctal 219
23 #define TK_IntegerHex 220
24 #define TK_EqualsEquals 223
25 #define TK_NotEquals 224
28 #define TK_MultAssign 227
29 #define TK_DivAssign 228
30 #define TK_PercentAssign 229
31 #define TK_PlusAssign 230
32 #define TK_MinusAssign 231
33 #define TK_AmpAssign 232
34 #define TK_CaretAssign 233
35 #define TK_BarAssign 234
36 #define TK_DotDotDot 240
37 #define TK_Whitespace 241
38 #define TK_Comment 242
45 void token( const char *data, int len );
52 // Initialize the machine. Invokes any init statement blocks. Returns 0
53 // if the machine begins in a non-accepting state and 1 if the machine
54 // begins in an accepting state.
57 // Execute the machine on a block of data. Returns -1 if after processing
58 // the data, the machine is in the error state and can never accept, 0 if
59 // the machine is in a non-accepting state and 1 if the machine is in an
61 int execute( const char *data, int len );
63 // Indicate that there is no more data. Returns -1 if the machine finishes
64 // in the error state and does not accept, 0 if the machine finishes
65 // in any other non-accepting state and 1 if the machine finishes in an
73 # Single and double literals.
74 slit = ( 'L'? "'" ( [^'\\\n] | /\\./ )* "'" ) @{tok = TK_Slit;};
75 dlit = ( 'L'? '"' ( [^"\\\n] | /\\./ )* '"' ) @{tok = TK_Dlit;};
78 id = ( [a-zA-Z_] [a-zA-Z0-9_]* ) @{tok = TK_Id;};
81 fract_const = digit* '.' digit+ | digit+ '.';
82 exponent = [eE] [+\-]? digit+;
83 float_suffix = [flFL];
85 ( fract_const exponent? float_suffix? |
86 digit+ exponent float_suffix? ) @{tok = TK_Float;};
88 # Integer decimal. Leading part buffered by float.
89 integer_decimal = ( ( '0' | [1-9] [0-9]* ) [ulUL]{0,3} ) @{tok = TK_IntegerDecimal;};
91 # Integer octal. Leading part buffered by float.
92 integer_octal = ( '0' [0-9]+ [ulUL]{0,2} ) @{tok = TK_IntegerOctal;};
94 # Integer hex. Leading 0 buffered by float.
95 integer_hex = ( '0' ( 'x' [0-9a-fA-F]+ [ulUL]{0,2} ) ) @{tok = TK_IntegerHex;};
97 # Only buffer the second item, first buffered by symbol. */
98 namesep = '::' @{tok = TK_NameSep;};
99 deqs = '==' @{tok = TK_EqualsEquals;};
100 neqs = '!=' @{tok = TK_NotEquals;};
101 and_and = '&&' @{tok = TK_AndAnd;};
102 or_or = '||' @{tok = TK_OrOr;};
103 mult_assign = '*=' @{tok = TK_MultAssign;};
104 div_assign = '/=' @{tok = TK_DivAssign;};
105 percent_assign = '%=' @{tok = TK_PercentAssign;};
106 plus_assign = '+=' @{tok = TK_PlusAssign;};
107 minus_assign = '-=' @{tok = TK_MinusAssign;};
108 amp_assign = '&=' @{tok = TK_AmpAssign;};
109 caret_assign = '^=' @{tok = TK_CaretAssign;};
110 bar_assign = '|=' @{tok = TK_BarAssign;};
111 plus_plus = '++' @{tok = TK_PlusPlus;};
112 minus_minus = '--' @{tok = TK_MinusMinus;};
113 arrow = '->' @{tok = TK_Arrow;};
114 arrow_star = '->*' @{tok = TK_ArrowStar;};
115 dot_star = '.*' @{tok = TK_DotStar;};
117 # Three char compounds, first item already buffered. */
118 dot_dot_dot = '...' @{tok = TK_DotDotDot;};
121 compound = namesep | deqs | neqs | and_and | or_or | mult_assign |
122 div_assign | percent_assign | plus_assign | minus_assign |
123 amp_assign | caret_assign | bar_assign | plus_plus | minus_minus |
124 arrow | arrow_star | dot_star | dot_dot_dot;
126 # Single char symbols.
127 symbol = ( punct - [_"'] ) @{tok = fc;};
133 # Comments and whitespace.
134 commc = '/*' @discard ( any* $0 '*/' @1 ) @{tok = TK_Comment;};
135 commcc = '//' @discard ( any* $0 '\n' @1 ) @{tok = TK_Comment;};
136 whitespace = ( any - 33..126 )+ >discard @{tok = TK_Whitespace;};
138 # All outside code tokens.
140 id | slit | dlit | float | integer_decimal |
141 integer_octal | integer_hex | compound | symbol |
142 commc | commcc | whitespace );
146 const char *rst_data;
148 if ( tok == TK_Comment || tok == TK_Whitespace ) {
149 /* Reset comment status, don't send. */
152 /* Restart right at the error point if consuming whitespace or
153 * a comment. Consume may have spanned multiple buffers. */
157 /* Send the token. */
158 token( ts, te - ts + 1 );
160 /* Restart right after the token. */
170 main := tokens >{ts=fpc;} @{te=fpc;} $!onError;
185 int Scanner::execute( const char *data, int len )
187 const char *p = data;
188 const char *pe = data + len;
189 const char *eof = pe;
193 if ( cs == Scanner_error )
195 if ( cs >= Scanner_first_final )
200 int Scanner::finish( )
202 if ( cs == Scanner_error )
204 if ( cs >= Scanner_first_final )
210 void token( const char *data, int len )
212 cout << "<" << tok << "> ";
213 for ( int i = 0; i < len; i++ )
218 void test( const char * data )
222 scanner.execute( data, strlen(data) );
224 if ( tok != 0 && tok != TK_Comment && tok != TK_Whitespace )
225 token( ts, te - ts + 1 );
236 "/* Move ranges to the singles list. */\n"
237 "void RedFsmAp::move( RedStateAp *state )\n"
239 " RedTranst &range = state->outRange;\n"
240 " for ( int rpos = 0; rpos < range.length(); ) {\n"
241 " if ( can( range, rpos ) ) {\n"
242 " while ( range[rpos].value != range[rpos+1].value ) {\n"
243 " single.append( range[rpos+1] );\n"
246 " range[rpos].highKey = range[rpos+1].highKey;\n"
248 " else if ( keyOps->span( range[rpos].lowKey, range[rpos].highKey ) == 1 ) {\n"
249 " single.append( range[rpos] );\n"
265 #ifdef _____OUTPUT_____