6 * Test in and out state actions.
12 static const int TK_Dlit = 192;
13 static const int TK_Slit = 193;
14 static const int TK_Float = 194;
15 static const int TK_Id = 195;
16 static const int TK_NameSep = 197;
17 static const int TK_Arrow = 211;
18 static const int TK_PlusPlus = 212;
19 static const int TK_MinusMinus = 213;
20 static const int TK_ArrowStar = 214;
21 static const int TK_DotStar = 215;
22 static const int TK_ShiftLeft = 216;
23 static const int TK_ShiftRight = 217;
24 static const int TK_IntegerDecimal = 218;
25 static const int TK_IntegerOctal = 219;
26 static const int TK_IntegerHex = 220;
27 static const int TK_EqualsEquals = 223;
28 static const int TK_NotEquals = 224;
29 static const int TK_AndAnd = 225;
30 static const int TK_OrOr = 226;
31 static const int TK_MultAssign = 227;
32 static const int TK_DivAssign = 228;
33 static const int TK_PercentAssign = 229;
34 static const int TK_PlusAssign = 230;
35 static const int TK_MinusAssign = 231;
36 static const int TK_AmpAssign = 232;
37 static const int TK_CaretAssign = 233;
38 static const int TK_BarAssign = 234;
39 static const int TK_DotDotDot = 240;
40 static const int TK_Whitespace = 241;
41 static const int TK_Comment = 242;
52 printf( "<%i> ", tok );
53 for ( int i = 0; i < len; i++ )
54 printf( "%c", data[i] );
64 # Single and double literals.
65 ( 'L'? "'" ( [^'\\\n] | /\\./ )* "'" )
66 => { token( TK_Slit );};
67 ( 'L'? '"' ( [^"\\\n] | /\\./ )* '"' )
68 => { token( TK_Dlit );};
71 ( [a-zA-Z_] [a-zA-Z0-9_]* )
75 fract_const = digit* '.' digit+ | digit+ '.';
76 exponent = [eE] [+\-]? digit+;
77 float_suffix = [flFL];
79 ( fract_const exponent? float_suffix? |
80 digit+ exponent float_suffix? )
81 => { token( TK_Float );};
83 # Integer decimal. Leading part buffered by float.
84 ( ( '0' | [1-9] [0-9]* ) [ulUL]{0,3} )
85 => { token( TK_IntegerDecimal );};
87 # Integer octal. Leading part buffered by float.
88 ( '0' [0-9]+ [ulUL]{0,2} )
89 => { token( TK_IntegerOctal );};
91 # Integer hex. Leading 0 buffered by float.
92 ( '0' ( 'x' [0-9a-fA-F]+ [ulUL]{0,2} ) )
93 => { token( TK_IntegerHex );};
95 # Only buffer the second item, first buffered by symbol. */
96 '::' => {token( TK_NameSep );};
97 '==' => {token( TK_EqualsEquals );};
98 '!=' => {token( TK_NotEquals );};
99 '&&' => {token( TK_AndAnd );};
100 '||' => {token( TK_OrOr );};
101 '*=' => {token( TK_MultAssign );};
102 '/=' => {token( TK_DivAssign );};
103 '%=' => {token( TK_PercentAssign );};
104 '+=' => {token( TK_PlusAssign );};
105 '-=' => {token( TK_MinusAssign );};
106 '&=' => {token( TK_AmpAssign );};
107 '^=' => {token( TK_CaretAssign );};
108 '|=' => {token( TK_BarAssign );};
109 '++' => {token( TK_PlusPlus );};
110 '--' => {token( TK_MinusMinus );};
111 '->' => {token( TK_Arrow );};
112 '->*' => {token( TK_ArrowStar );};
113 '.*' => {token( TK_DotStar );};
115 # Three char compounds, first item already buffered. */
116 '...' => { token( TK_DotDotDot );};
118 # Single char symbols.
119 ( punct - [_"'] ) => { token( ts[0] );};
125 # Comments and whitespace.
126 '/*' ( any* $0 '*/' @1 ) => comment;
127 '//' ( any* $0 '\n' @1 ) => comment;
128 ( any - 33..126 )+ => { token( TK_Whitespace );};
134 %% write data noprefix;
141 void execute( char* data, int len )
144 char *pe = data + len;
150 // Indicate that there is no more data. Returns -1 if the machine finishes
151 // in the error state and does not accept, 0 if the machine finishes
152 // in any other non-accepting state and 1 if the machine finishes in an
158 if ( cs >= first_final )
164 static const int BUFSIZE = 12;
166 void test( char buf[] )
168 Scanner scanner = new Scanner();
171 scanner.execute( buf.ptr, buf.length );
172 if ( scanner.cs == Scanner.error ) {
173 /* Machine failed before finding a token. */
174 printf("PARSE ERROR\n");
193 "'\\''\"\\n\\d'\\\"\"\n"