Line directives need to use the fileName stored in the InputLoc stuctures from
[external/ragel.git] / test / strings2.rl
1 /*
2  * @LANG: c
3  * @ALLOW_GENFLAGS: -T0 -T1 -F0 -F1
4  * @ALLOW_MINFLAGS: -n -m -l
5  *
6  * Test works with split code gen.
7  */
8
9 #include <string.h>
10 #include <stdio.h>
11
12 #include "strings2.h"
13
14 %%{
15         machine strs;
16         variable cs fsm->cs;
17
18         main := 
19                 "/lib/ld-linux.so.2\n" |
20                 "libstdc++-libc6.2-2.so.3\n" |
21                 "cerr\n" |
22                 "__cp_push_exception\n" |
23                 "_DYNAMIC\n" |
24                 "endl__FR7ostream\n" |
25                 "__ls__7ostreamc\n" |
26                 "_._9exception\n" |
27                 "__vt_9bad_alloc\n" |
28                 "__rtti_user\n" |
29                 "__ls__7ostreamPFR7ostream_R7ostream\n" |
30                 "__rtti_si\n" |
31                 "_init\n" |
32                 "bad__C3ios\n" |
33                 "__throw\n" |
34                 "__ls__7ostreamPCc\n" |
35                 "__deregister_frame_info\n" |
36                 "terminate__Fv\n" |
37                 "__ls__7ostreamb\n" |
38                 "__ls__7ostreami\n" |
39                 "__8ofstreamiPCcii\n" |
40                 "__builtin_vec_new\n" |
41                 "_fini\n" |
42                 "__9exception\n" |
43                 "__builtin_vec_delete\n" |
44                 "_GLOBAL_OFFSET_TABLE_\n" |
45                 "__vt_9exception\n" |
46                 "__nw__FUiPv\n" |
47                 "_._9bad_alloc\n" |
48                 "__builtin_delete\n" |
49                 "__builtin_new\n" |
50                 "cout\n" |
51                 "__register_frame_info\n" |
52                 "__eh_alloc\n" |
53                 "__gmon_start__\n" |
54                 "libm.so.6\n" |
55                 "libc.so.6\n" |
56                 "strcpy\n" |
57                 "stdout\n" |
58                 "memmove\n" |
59                 "memcpy\n" |
60                 "malloc\n" |
61                 "strtoul\n" |
62                 "fprintf\n" |
63                 "stdin\n" |
64                 "ferror\n" |
65                 "strncpy\n" |
66                 "strcasecmp\n" |
67                 "realloc\n" |
68                 "_IO_getc\n" |
69                 "fread\n" |
70                 "memset\n" |
71                 "clearerr\n" |
72                 "__assert_fail\n" |
73                 "strcmp\n" |
74                 "stderr\n" |
75                 "fwrite\n" |
76                 "__errno_location\n" |
77                 "exit\n" |
78                 "fopen\n" |
79                 "atoi\n" |
80                 "_IO_stdin_used\n" |
81                 "__libc_start_main\n" |
82                 "strlen\n" |
83                 "free\n" |
84                 "_edata\n" |
85                 "__bss_start\n" |
86                 "_end\n" |
87                 "GLIBC_2.1\n" |
88                 "GLIBC_2.0\n" |
89                 "PTRh\n" |
90                 "QVhL\n" |
91                 "<WVS\n" |
92                 "LWVS\n" |
93                 "PHRW\n" |
94                 "<WVS\n" |
95                 "\WVS\n" |
96                 ",WVS\n" |
97                 "@Phl\n" |
98                 "<WVS\n" |
99                 "jZjA\n" |
100                 "jzja\n" |
101                 "j9j0\n" |
102                 "j9j0\n" |
103                 "jZjA\n" |
104                 "jzja\n" |
105                 "jzja\n" |
106                 "jZjA\n" |
107                 "j~j!\n" |
108                 "j~j \n" |
109                 "j/j!\n" |
110                 "j@j:\n" |
111                 "j`j[\n" |
112                 "j~j{\n" |
113                 "j9j0\n" |
114                 "jFjA\n" |
115                 "jfja\n" |
116                 ",WVS\n" |
117                 ",WVS\n" |
118                 ";C<|\n" |
119                 "<WVS\n" |
120                 "C ;C\n" |
121                 "C$;C\n" |
122                 "C$;C\n" |
123                 "C ;C\n" |
124                 ",WVS\n" |
125                 ";E uF\n" |
126                 "P ;U\n" |
127                 "P ;U\n" |
128                 "E$fP\n" |
129                 "E$fP\n" |
130                 "E$fP\n" |
131                 "E$fP\n" |
132                 "E$fP\n" |
133                 "E$fP\n" |
134                 "E$fP\n" |
135                 "E$fP\n" |
136                 "u!h@\n" |
137                 "PHRj\n" |
138                 "PHRj\n" |
139                 "P\     U\n" |
140                 "j]hY\n" |
141                 "johY\n" |
142                 "PHRj\n" |
143                 "PHRj\n" |
144                 "E fPj\n" |
145                 "E fP\n" |
146                 "E fP\n" |
147                 "E fP\n" |
148                 "E fP\n" |
149                 "E fP\n" |
150                 "E fPj\n" |
151                 "t$h`\n" |
152                 "F ;C } \n" |
153                 "F ;C ~ \n" |
154                 "@X:BXt)\n" |
155                 "\WVS\n" |
156                 "\WVS\n" |
157                 "PPRS\n" |
158                 "F ;C } \n" |
159                 "F ;C ~ \n" |
160                 "@X:BXt)\n" |
161                 ";H(}:\n" |
162                 "@ fP\n" |
163                 ";P |\n" |
164                 "<WVS\n" |
165                 ";P |\n" |
166                 "bad_alloc\n" |
167                 "usage: ragel [options] file\n" |
168                 "general:\n" |
169                 "   -h, -H, -?   Disply this usage.\n" |
170                 "   -o <file>    Write output to <file>.\n" |
171                 "   -s           Print stats on the compiled fsm.\n" |
172                 "   -f           Dump the final fsm.\n" |
173                 "fsm minimization:\n" |
174                 "   -n           No minimization (default).\n" |
175                 "   -m           Find the minimal fsm accepting the language.\n" |
176                 "generated code language:\n" |
177                 "   -c           Generate c code (default).\n" |
178                 "   -C           Generate c++ code.\n" |
179                 "generated code style:\n" |
180                 "   -T0          Generate a table driven fsm (default).\n" |
181                 "   -T1          Generate a faster table driven fsm.\n" |
182                 "   -S0          Generate a switch driven fsm.\n" |
183                 "   -G0          Generate a goto driven fsm.\n" |
184                 "   -G1          Generate a faster goto driven fsm.\n" |
185                 "   -G2          Generate a really fast goto driven fsm.\n" |
186                 "char * FileNameFromStem(char *, char *)\n" |
187                 "main.cpp\n" |
188                 "len > 0\n" |
189                 "main\n" |
190                 "ragel: main graph not defined\n" |
191                 "graph states:      \n" |
192                 "graph transitions: \n" |
193                 "machine states:    \n" |
194                 "machine functions: \n" |
195                 "function array:    \n" |
196                 "T:S:G:Cco:senmabjkfhH?-:\n" |
197                 "ragel: zero length output file name given\n" |
198                 "ragel: output file already given\n" |
199                 "ragel: invalid param specified (try -h for a list of options)\n" |
200                 "help\n" |
201                 "ragel: zero length input file name given\n" |
202                 "ragel: input file already given\n" |
203                 "ragel: warning: -e given but minimization is not enabled\n" |
204                 "ragel: no input file (try -h for a list of options)\n" |
205                 " for reading\n" |
206                 "ragel: could not open \n" |
207                 " for writing\n" |
208                 "ragel: error opening \n" |
209                 " * Parts of this file are copied from Ragel source covered by the GNU\n" |
210                 " * GPL. As a special exception, you may use the parts of this file copied\n" |
211                 " * from Ragel source without restriction. The remainder is derived from\n" |
212                 "bad_alloc\n" |
213                 "%s:%i: unterminated literal\n" |
214                 "%s:%i: unterminated comment\n" |
215                 "%s:%i: bad character in literal\n" |
216                 "fatal flex scanner internal error--no action found\n" |
217                 "fatal flex scanner internal error--end of buffer missed\n" |
218                 "fatal error - scanner input buffer overflow\n" |
219                 "input in flex scanner failed\n" |
220                 "out of dynamic memory in yy_create_buffer()\n" |
221                 "out of dynamic memory in yy_scan_buffer()\n" |
222                 "out of dynamic memory in yy_scan_bytes()\n" |
223                 "bad buffer in yy_scan_bytes()\n" |
224                 "bad_alloc\n" |
225                 "%s:%i: warning: range gives null fsm\n" |
226                 "%s:%i: warning: literal used in range is not of length 1, using 0x%x\n" |
227                 "%s:%i: warning: overflow in byte constant\n" |
228                 "parse error\n" |
229                 "parser stack overflow\n" |
230                 "%s:%i: %s\n" |
231                 "bad_alloc\n" |
232                 "extend\n" |
233                 "ascii\n" |
234                 "alpha\n" |
235                 "digit\n" |
236                 "alnum\n" |
237                 "lower\n" |
238                 "upper\n" |
239                 "cntrl\n" |
240                 "graph\n" |
241                 "print\n" |
242                 "punct\n" |
243                 "space\n" |
244                 "xdigit\n" |
245                 "struct Fsm * FactorWithAugNode::Walk()\n" |
246                 "parsetree.cpp\n" |
247                 "false\n" |
248                 "bad_alloc\n" |
249                 "xx []()\n" |
250                 " df \n" |
251                 "StartState: \n" |
252                 "Final States:\n" |
253                 "void FsmGraph<State,int,Trans>::AttachStates(State *, State *, Trans *, FsmKeyType, int)\n" |
254                 "rlfsm/fsmattach.cpp\n" |
255                 "trans->toState == __null\n" |
256                 "trans->fromState == __null\n" |
257                 "void FsmGraph<State,int,Trans>::DetachStates(State *, State *, Trans *, FsmKeyType, int)\n" |
258                 "trans->toState == to\n" |
259                 "trans->fromState == from\n" |
260                 "inTel != __null\n" |
261                 "void Vector<BstMapEl<int,int>,ResizeExpn>::setAs(const Vector<BstMapEl<int,int>,ResizeExpn> &)\n" |
262                 "aapl/vectcommon.h\n" |
263                 "&v != this\n" |
264                 "void FsmGraph<State,int,Trans>::ChangeRangeLowerKey(Trans *, int, int)\n" |
265                 "inRangeEl != __null\n" |
266                 "void FsmGraph<State,int,Trans>::IsolateStartState()\n" |
267                 "rlfsm/fsmgraph.cpp\n" |
268                 "md.stateDict.nodeCount == 0\n" |
269                 "md.stfil.listLength == 0\n" |
270                 "struct State * FsmGraph<State,int,Trans>::DetachState(State *)\n" |
271                 "fromTel != __null\n" |
272                 "struct Trans * FsmGraph<State,int,Trans>::AttachStates(State *, State *, FsmKeyType, int, int)\n" |
273                 "outTel != __null\n" |
274                 "outTel1 != __null\n" |
275                 "from->defOutTrans == __null\n" |
276                 "void FsmGraph<State,int,Trans>::VerifyOutFuncs()\n" |
277                 "state->outTransFuncTable.tableLength == 0\n" |
278                 "!state->isOutPriorSet\n" |
279                 "state->outPriority == 0\n" |
280                 "void FsmGraph<State,int,Trans>::VerifyIntegrity()\n" |
281                 "rlfsm/fsmbase.cpp\n" |
282                 "outIt.trans->fromState == state\n" |
283                 "inIt.trans->toState == state\n" |
284                 "static int FsmTrans<State,Trans,int,CmpOrd<int> >::ComparePartPtr(FsmTrans<State,Trans,int,CmpOrd<int> > *, FsmTrans<State,Trans,int,CmpOrd<int> > *)\n" |
285                 "rlfsm/fsmstate.cpp\n" |
286                 "false\n" |
287                 "void FsmGraph<State,int,Trans>::InTransMove(State *, State *)\n" |
288                 "dest != src\n" |
289                 "static bool FsmTrans<State,Trans,int,CmpOrd<int> >::ShouldMarkPtr(MarkIndex<State> &, FsmTrans<State,Trans,int,CmpOrd<int> > *, FsmTrans<State,Trans,int,CmpOrd<int> > *)\n" |
290                 "bad_alloc\n" |
291                 "10FsmCodeGen\n" |
292                 "bad_alloc\n" |
293                 "       case \n" |
294                 "break;}\n" |
295                 "unsigned char\n" |
296                 "unsigned short\n" |
297                 "unsigned int\n" |
298                 "{0, \n" |
299                 "/* Forward dec state for the transition structure. */\n" |
300                 "struct \n" |
301                 "StateStruct;\n" |
302                 "/* A single transition. */\n" |
303                 "struct \n" |
304                 "TransStruct\n" |
305                 "       struct \n" |
306                 "StateStruct *toState;\n" |
307                 "       int *funcs;\n" |
308                 "typedef struct \n" |
309                 "TransStruct \n" |
310                 "Trans;\n" |
311                 "/* A single state. */\n" |
312                 "struct \n" |
313                 "StateStruct\n" |
314                 "       int lowIndex;\n" |
315                 "       int highIndex;\n" |
316                 "       void *transIndex;\n" |
317                 "       unsigned int dflIndex;\n" |
318                 "       int *outFuncs;\n" |
319                 "       int isFinState;\n" |
320                 "typedef struct \n" |
321                 "StateStruct \n" |
322                 "State;\n" |
323                 "/* Only non-static data: current state. */\n" |
324                 "struct \n" |
325                 "Struct\n" |
326                 "State *curState;\n" |
327                 "       int accept;\n" |
328                 "typedef struct \n" |
329                 "Struct \n" |
330                 "/* Init the fsm. */\n" |
331                 "void \n" |
332                 "Init( \n" |
333                 " *fsm );\n" |
334                 "/* Execute some chunk of data. */\n" |
335                 "void \n" |
336                 "Execute( \n" |
337                 " *fsm, char *data, int dlen );\n" |
338                 "/* Indicate to the fsm tha there is no more data. */\n" |
339                 "void \n" |
340                 "Finish( \n" |
341                 " *fsm );\n" |
342                 "/* Did the machine accept? */\n" |
343                 "int \n" |
344                 "Accept( \n" |
345                 " *fsm );\n" |
346                 "#define f \n" |
347                 "#define s \n" |
348                 "#define i \n" |
349                 "#define t \n" |
350                 "/* The array of functions. */\n" |
351                 "#if \n" |
352                 "static int \n" |
353                 "_f[] = {\n" |
354                 "#endif\n" |
355                 "/* The array of indicies into the transition array. */\n" |
356                 "#if \n" |
357                 "static \n" |
358                 "_i[] = {\n" |
359                 "#endif\n" |
360                 "/* The aray of states. */\n" |
361                 "static \n" |
362                 "State \n" |
363                 "_s[] = {\n" |
364                 "/* The array of transitions. */\n" |
365                 "static \n" |
366                 "Trans \n" |
367                 "_t[] = {\n" |
368                 "/* The start state. */\n" |
369                 "static \n" |
370                 "State *\n" |
371                 "_startState = s+\n" |
372                 "#undef f\n" |
373                 "#undef s\n" |
374                 "#undef i\n" |
375                 "#undef t\n" |
376                 "* Execute functions pointed to by funcs until the null function is found. \n" |
377                 "inline static void \n" |
378                 "ExecFuncs( \n" |
379                 " *fsm, int *funcs, char *p )\n" |
380                 "       int len = *funcs++;\n" |
381                 "       while ( len-- > 0 ) {\n" |
382                 "               switch ( *funcs++ ) {\n" |
383                 " * Init the fsm to a runnable state.\n" |
384                 "void \n" |
385                 " *fsm )\n" |
386                 "       fsm->curState = \n" |
387                 "_startState;\n" |
388                 "       fsm->accept = 0;\n" |
389                 " * Did the fsm accept? \n" |
390                 "int \n" |
391                 " *fsm )\n" |
392                 "       return fsm->accept;\n" |
393                 " * Execute the fsm on some chunk of data. \n" |
394                 "void \n" |
395                 " *fsm, char *data, int dlen )\n" |
396                 "       char *p = data;\n" |
397                 "       int len = dlen;\n" |
398                 "State *cs = fsm->curState;\n" |
399                 "       for ( ; len > 0; p++, len-- ) {\n" |
400                 "               int c = (unsigned char) *p;\n" |
401                 "Trans *trans;\n" |
402                 "               if ( cs == 0 )\n" |
403                 "                       goto finished;\n" |
404                 "               /* If the character is within the index bounds then get the\n" |
405                 "                * transition for it. If it is out of the transition bounds\n" |
406                 "                * we will use the default transition. */\n" |
407                 "               if ( cs->lowIndex <= c && c < cs->highIndex ) {\n" |
408                 "                       /* Use the index to look into the transition array. */\n" |
409                 "                       trans = \n" |
410                 "_t + \n" |
411                 "                               ((\n" |
412                 "*)cs->transIndex)[c - cs->lowIndex];\n" |
413                 "               else {\n" |
414                 "                       /* Use the default index as the char is out of range. */\n" |
415                 "                       trans = \n" |
416                 "_t + cs->dflIndex;\n" |
417                 "               /* If there are functions for this transition then execute them. */\n" |
418                 "               if ( trans->funcs != 0 )\n" |
419                 "ExecFuncs( fsm, trans->funcs, p );\n" |
420                 "               /* Move to the new state. */\n" |
421                 "               cs = trans->toState;\n" |
422                 "finished:\n" |
423                 "       fsm->curState = cs;\n" |
424                 " * Indicate to the fsm that the input is done. Does cleanup tasks.\n" |
425                 "void \n" |
426                 " *fsm )\n" |
427                 "State *cs = fsm->curState;\n" |
428                 "       if ( cs != 0 && cs->isFinState ) {\n" |
429                 "               /* If finishing in a final state then execute the\n" |
430                 "                * out functions for it. (if any). */\n" |
431                 "               if ( cs->outFuncs != 0 )\n" |
432                 "ExecFuncs( fsm, cs->outFuncs, 0 );\n" |
433                 "               fsm->accept = 1;\n" |
434                 "       else {\n" |
435                 "               /* If we are not in a final state then this\n" |
436                 "                * is an error. Move to the error state. */\n" |
437                 "               fsm->curState = 0;\n" |
438                 "class \n" |
439                 "public:\n" |
440                 "       /* Forward dec state for the transition structure. */\n" |
441                 "       struct State;\n" |
442                 "       /* A single transition. */\n" |
443                 "       struct Trans\n" |
444                 "               State *toState;\n" |
445                 "               int *funcs;\n" |
446                 "       /* A single state. */\n" |
447                 "       struct State\n" |
448                 "               int lowIndex;\n" |
449                 "               int highIndex;\n" |
450                 "               void *transIndex;\n" |
451                 "               unsigned int dflIndex;\n" |
452                 "               int *outFuncs;\n" |
453                 "               int isFinState;\n" |
454                 "       /* Constructor. */\n" |
455                 "       void Init( );\n" |
456                 "       /* Execute some chunk of data. */\n" |
457                 "       void Execute( char *data, int dlen );\n" |
458                 "       /* Indicate to the fsm tha there is no more data. */\n" |
459                 "       void Finish( );\n" |
460                 "       /* Did the machine accept? */\n" |
461                 "       int Accept( );\n" |
462                 "       State *curState;\n" |
463                 "       int accept;\n" |
464                 "       inline void ExecFuncs( int *funcs, char *p );\n" |
465                 "/* The array of functions. */\n" |
466                 "#if \n" |
467                 "::State \n" |
468                 "/* The array of trainsitions. */\n" |
469                 "static \n" |
470                 "::Trans \n" |
471                 "/* The start state. */\n" |
472                 "static \n" |
473                 "::State *\n" |
474                 " * Execute functions pointed to by funcs until the null function is found. \n" |
475                 "inline void \n" |
476                 "::ExecFuncs( int *funcs, char *p )\n" |
477                 "       int len = *funcs++;\n" |
478                 "       while ( len-- > 0 ) {\n" |
479                 "               switch ( *funcs++ ) {\n" |
480                 " * Constructor\n" |
481                 "       Init();\n" |
482                 "Init\n" |
483                 "void \n" |
484                 "::Init( )\n" |
485                 "       curState = \n" |
486                 "_startState;\n" |
487                 "       accept = 0;\n" |
488                 "::Accept( )\n" |
489                 "       return accept;\n" |
490                 "::Execute( char *data, int dlen )\n" |
491                 "       char *p = data;\n" |
492                 "       int len = dlen;\n" |
493                 "       State *cs = curState;\n" |
494                 "       for ( ; len > 0; p++, len-- ) {\n" |
495                 "               int c = (unsigned char)*p;\n" |
496                 "               Trans *trans;\n" |
497                 "               if ( cs == 0 )\n" |
498                 "                       goto finished;\n" |
499                 "               /* If the character is within the index bounds then get the\n" |
500                 "                * transition for it. If it is out of the transition bounds\n" |
501                 "                * we will use the default transition. */\n" |
502                 "               if ( cs->lowIndex <= c && c < cs->highIndex ) {\n" |
503                 "                       /* Use the index to look into the transition array. */\n" |
504                 "                       trans = \n" |
505                 "_t + cs->dflIndex;\n" |
506                 "               /* If there are functions for this transition then execute them. */\n" |
507                 "               if ( trans->funcs != 0 )\n" |
508                 "                       ExecFuncs( trans->funcs, p );\n" |
509                 "               /* Move to the new state. */\n" |
510                 "               cs = trans->toState;\n" |
511                 "finished:\n" |
512                 "       curState = cs;\n" |
513                 "::Finish( )\n" |
514                 "       State *cs = curState;\n" |
515                 "       if ( cs != 0 && cs->isFinState ) {\n" |
516                 "               /* If finishing in a final state then execute the\n" |
517                 "                * out functions for it. (if any). */\n" |
518                 "               if ( cs->outFuncs != 0 )\n" |
519                 "                       ExecFuncs( cs->outFuncs, 0 );\n" |
520                 "               accept = 1;\n" |
521                 "       else {\n" |
522                 "               /* If we are not in a final state then this\n" |
523                 "                * is an error. Move to the error state. */\n" |
524                 "               curState = 0;\n" |
525                 "10TabCodeGen\n" |
526                 "11CTabCodeGen\n" |
527                 "12CCTabCodeGen\n" |
528                 "10FsmCodeGen\n" |
529                 "bad_alloc\n" |
530                 "       case \n" |
531                 "       break;\n" |
532                 "/* Forward dec state for the transition structure. */\n" |
533                 "struct \n" |
534                 "StateStruct;\n" |
535                 "/* A single transition. */\n" |
536                 "struct \n" |
537                 "TransStruct\n" |
538                 "       struct \n" |
539                 "StateStruct *toState;\n" |
540                 "       int funcs;\n" |
541                 "typedef struct \n" |
542                 "TransStruct \n" |
543                 "Trans;\n" |
544                 "/* A single state. */\n" |
545                 "struct \n" |
546                 "StateStruct\n" |
547                 "       int lowIndex;\n" |
548                 "       int highIndex;\n" |
549                 "       void *transIndex;\n" |
550                 "       int dflIndex;\n" |
551                 "       int outFuncs;\n" |
552                 "       int isFinState;\n" |
553                 "typedef struct \n" |
554                 "StateStruct \n" |
555                 "State;\n" |
556                 "/* Only non-static data: current state. */\n" |
557                 "struct \n" |
558                 "Struct\n" |
559                 "State *curState;\n" |
560                 "       int accept;\n" |
561                 "typedef struct \n" |
562                 "Struct \n" |
563                 "/* Init the fsm. */\n" |
564                 "void \n" |
565                 "Init( \n" |
566                 " *fsm );\n" |
567                 "/* Execute some chunk of data. */\n" |
568                 "void \n" |
569                 "Execute( \n" |
570                 " *fsm, char *data, int dlen );\n" |
571                 "/* Indicate to the fsm tha there is no more data. */\n" |
572                 "void \n" |
573                 "Finish( \n" |
574                 " *fsm );\n" |
575                 "/* Did the machine accept? */\n" |
576                 "int \n" |
577                 "Accept( \n" |
578                 " *fsm );\n" |
579                 "#define s \n" |
580                 "#define i \n" |
581                 "#define t \n" |
582                 "/* The array of indicies into the transition array. */\n" |
583                 "#if \n" |
584                 "static \n" |
585                 "_i[] = {\n" |
586                 "#endif\n" |
587                 "/* The aray of states. */\n" |
588                 "static \n" |
589                 "State \n" |
590                 "_s[] = {\n" |
591                 "/* The array of trainsitions. */\n" |
592                 "static \n" |
593                 "Trans \n" |
594                 "_t[] = {\n" |
595                 "/* The start state. */\n" |
596                 "static \n" |
597                 "State *\n" |
598                 "_startState = s+\n" |
599                 "#undef f\n" |
600                 "#undef s\n" |
601                 "#undef i\n" |
602                 "#undef t\n" |
603                 "/***************************************************************************\n" |
604                 " * Execute functions pointed to by funcs until the null function is found. \n" |
605                 "inline static void \n" |
606                 "ExecFuncs( \n" |
607                 " *fsm, int funcs, char *p )\n" |
608                 "       switch ( funcs ) {\n" |
609                 "/****************************************\n" |
610                 "Init\n" |
611                 "void \n" |
612                 " *fsm )\n" |
613                 "       fsm->curState = \n" |
614                 "_startState;\n" |
615                 "       fsm->accept = 0;\n" |
616                 "/****************************************\n" |
617                 "Accept\n" |
618                 " * Did the fsm accept? \n" |
619                 "int \n" |
620                 " *fsm )\n" |
621                 "       return fsm->accept;\n" |
622                 "/**********************************************************************\n" |
623                 " * Execute the fsm on some chunk of data. \n" |
624                 "void \n" |
625                 " *fsm, char *data, int dlen )\n" |
626                 "       char *p = data;\n" |
627                 "       int len = dlen;\n" |
628                 "State *cs = fsm->curState;\n" |
629                 "       for ( ; len > 0; p++, len-- ) {\n" |
630                 "               int c = (unsigned char)*p;\n" |
631                 "Trans *trans;\n" |
632                 "               if ( cs == 0 )\n" |
633                 "                       goto finished;\n" |
634                 "               /* If the character is within the index bounds then get the\n" |
635                 "                * transition for it. If it is out of the transition bounds\n" |
636                 "                * we will use the default transition. */\n" |
637                 "               if ( cs->lowIndex <= c && c < cs->highIndex ) {\n" |
638                 "                       /* Use the index to look into the transition array. */\n" |
639                 "                       trans = \n" |
640                 "_t + \n" |
641                 "                               ((\n" |
642                 "*)cs->transIndex)[c - cs->lowIndex];\n" |
643                 "               else {\n" |
644                 "                       /* Use the default index as the char is out of range. */\n" |
645                 "                       trans = \n" |
646                 "_t + cs->dflIndex;\n" |
647                 "               /* If there are functions for this transition then execute them. */\n" |
648                 "               if ( trans->funcs >= 0 )\n" |
649                 "ExecFuncs( fsm, trans->funcs, p );\n" |
650                 "               /* Move to the new state. */\n" |
651                 "               cs = trans->toState;\n" |
652                 "finished:\n" |
653                 "       fsm->curState = cs;\n" |
654                 "/**********************************************************************\n" |
655                 "Finish\n" |
656                 " * Indicate to the fsm that the input is done. Does cleanup tasks.\n" |
657                 "void \n" |
658                 " *fsm )\n" |
659                 "State *cs = fsm->curState;\n" |
660                 "       if ( cs != 0 && cs->isFinState ) {\n" |
661                 "               /* If finishing in a final state then execute the\n" |
662                 "                * out functions for it. (if any). */\n" |
663                 "               if ( cs->outFuncs != 0 )\n" |
664                 "ExecFuncs( fsm, cs->outFuncs, 0 );\n" |
665                 "               fsm->accept = 1;\n" |
666                 "       else {\n" |
667                 "               /* If we are not in a final state then this\n" |
668                 "                * is an error. Move to the error state. */\n" |
669                 "               fsm->curState = 0;\n" |
670                 "class \n" |
671                 "public:\n" |
672                 "       /* Function and index type. */\n" |
673                 "       typedef int Func;\n" |
674                 "       /* Forward dec state for the transition structure. */\n" |
675                 "       struct State;\n" |
676                 "       /* A single transition. */\n" |
677                 "       struct Trans\n" |
678                 "               State *toState;\n" |
679                 "               int funcs;\n" |
680                 "       /* A single state. */\n" |
681                 "       struct State\n" |
682                 "               int lowIndex;\n" |
683                 "               int highIndex;\n" |
684                 "               void *transIndex;\n" |
685                 "               int dflIndex;\n" |
686                 "               int outFuncs;\n" |
687                 "               int isFinState;\n" |
688                 "       /* Constructor. */\n" |
689                 "       void Init( );\n" |
690                 "       /* Execute some chunk of data. */\n" |
691                 "       void Execute( char *data, int dlen );\n" |
692                 "       /* Indicate to the fsm tha there is no more data. */\n" |
693                 "       void Finish( );\n" |
694                 "       /* Did the machine accept? */\n" |
695                 "       int Accept( );\n" |
696                 "       State *curState;\n" |
697                 "       int accept;\n" |
698                 "       inline void ExecFuncs( int funcs, char *p );\n" |
699                 "::State \n" |
700                 "::Trans \n" |
701                 "::State *\n" |
702                 "/***************************************************************************\n" |
703                 " * Execute functions pointed to by funcs until the null function is found. \n" |
704                 "inline void \n" |
705                 "::ExecFuncs( int funcs, char *p )\n" |
706                 "       switch ( funcs ) {\n" |
707                 "/****************************************\n" |
708                 " * Constructor\n" |
709                 "       Init();\n" |
710                 "/****************************************\n" |
711                 "::Init( )\n" |
712                 "       curState = \n" |
713                 "_startState;\n" |
714                 "       accept = 0;\n" |
715                 "/****************************************\n" |
716                 " * Did the fsm accept? \n" |
717                 "int \n" |
718                 "::Accept( )\n" |
719                 "       return accept;\n" |
720                 "/**********************************************************************\n" |
721                 " * Execute the fsm on some chunk of data. \n" |
722                 "void \n" |
723                 "::Execute( char *data, int dlen )\n" |
724                 "       char *p = data;\n" |
725                 "       int len = dlen;\n" |
726                 "       State *cs = curState;\n" |
727                 "       for ( ; len > 0; p++, len-- ) {\n" |
728                 "               int c = (unsigned char)*p;\n" |
729                 "               Trans *trans;\n" |
730                 "               if ( cs == 0 )\n" |
731                 "                       goto finished;\n" |
732                 "               /* If the character is within the index bounds then get the\n" |
733                 "                * transition for it. If it is out of the transition bounds\n" |
734                 "                * we will use the default transition. */\n" |
735                 "               if ( cs->lowIndex <= c && c < cs->highIndex ) {\n" |
736                 "                       /* Use the index to look into the transition array. */\n" |
737                 "                       trans = \n" |
738                 "_t + cs->dflIndex;\n" |
739                 "               /* If there are functions for this transition then execute them. */\n" |
740                 "               if ( trans->funcs != 0 )\n" |
741                 "                       ExecFuncs( trans->funcs, p );\n" |
742                 "               /* Move to the new state. */\n" |
743                 "               cs = trans->toState;\n" |
744                 "finished:\n" |
745                 "       curState = cs;\n" |
746                 "/**********************************************************************\n" |
747                 " * Indicate to the fsm that the input is done. Does cleanup tasks.\n" |
748                 "void \n" |
749                 "::Finish( )\n" |
750                 "       State *cs = curState;\n" |
751                 "       if ( cs != 0 && cs->isFinState ) {\n" |
752                 "               /* If finishing in a final state then execute the\n" |
753                 "                * out functions for it. (if any). */\n" |
754                 "               if ( cs->outFuncs != 0 )\n" |
755                 "                       ExecFuncs( cs->outFuncs, 0 );\n" |
756                 "               accept = 1;\n" |
757                 "       else {\n" |
758                 "               /* If we are not in a final state then this\n" |
759                 "                * is an error. Move to the error state. */\n" |
760                 "               curState = 0;\n" |
761                 "11FTabCodeGen\n" |
762                 "12CFTabCodeGen\n" |
763                 "13CCFTabCodeGen\n" |
764                 "bad_alloc\n" |
765                 "cs = -1; \n" |
766                 "cs = \n" |
767                 "break;\n" |
768                 "               switch( cs ) {\n" |
769                 "               case \n" |
770                 "                       switch ( c ) {\n" |
771                 "case \n" |
772                 "default: \n" |
773                 "                       }\n" |
774                 "                       break;\n" |
775                 "       switch( cs ) {\n" |
776                 "accept = 1; \n" |
777                 "/* Only non-static data: current state. */\n" |
778                 "struct \n" |
779                 "Struct\n" |
780                 "       int curState;\n" |
781                 "       int accept;\n" |
782                 "typedef struct \n" |
783                 "Struct \n" |
784                 "/* Init the fsm. */\n" |
785                 "void \n" |
786                 "Init( \n" |
787                 " *fsm );\n" |
788                 "/* Execute some chunk of data. */\n" |
789                 "void \n" |
790                 "Execute( \n" |
791                 " *fsm, char *data, int dlen );\n" |
792                 "/* Indicate to the fsm tha there is no more data. */\n" |
793                 "void \n" |
794                 "Finish( \n" |
795                 " *fsm );\n" |
796                 "/* Did the machine accept? */\n" |
797                 "int \n" |
798                 "Accept( \n" |
799                 " *fsm );\n" |
800                 "/* The start state. */\n" |
801                 "static int \n" |
802                 "_startState = \n" |
803                 "/****************************************\n" |
804                 "Init\n" |
805                 "void \n" |
806                 " *fsm )\n" |
807                 "       fsm->curState = \n" |
808                 "_startState;\n" |
809                 "       fsm->accept = 0;\n" |
810                 "/**********************************************************************\n" |
811                 " * Execute the fsm on some chunk of data. \n" |
812                 "void \n" |
813                 " *fsm, char *data, int dlen )\n" |
814                 "       char *p = data;\n" |
815                 "       int len = dlen;\n" |
816                 "       int cs = fsm->curState;\n" |
817                 "       for ( ; len > 0; p++, len-- ) {\n" |
818                 "               unsigned char c = (unsigned char)*p;\n" |
819                 "       fsm->curState = cs;\n" |
820                 "/**********************************************************************\n" |
821                 "Finish\n" |
822                 " * Indicate to the fsm that the input is done. Does cleanup tasks.\n" |
823                 "void \n" |
824                 " *fsm )\n" |
825                 "       int cs = fsm->curState;\n" |
826                 "       int accept = 0;\n" |
827                 "       fsm->accept = accept;\n" |
828                 "/*******************************************************\n" |
829                 "Accept\n" |
830                 " * Did the machine accept?\n" |
831                 "int \n" |
832                 " *fsm )\n" |
833                 "       return fsm->accept;\n" |
834                 "/* Only non-static data: current state. */\n" |
835                 "class \n" |
836                 "public:\n" |
837                 "       /* Init the fsm. */\n" |
838                 "       void Init( );\n" |
839                 "       /* Execute some chunk of data. */\n" |
840                 "       void Execute( char *data, int dlen );\n" |
841                 "       /* Indicate to the fsm tha there is no more data. */\n" |
842                 "       void Finish( );\n" |
843                 "       /* Did the machine accept? */\n" |
844                 "       int Accept( );\n" |
845                 "       int curState;\n" |
846                 "       int accept;\n" |
847                 "       /* The start state. */\n" |
848                 "       static int startState;\n" |
849                 "/* The start state. */\n" |
850                 "int \n" |
851                 "::startState = \n" |
852                 "       Init();\n" |
853                 "/****************************************\n" |
854                 "::Init\n" |
855                 "void \n" |
856                 "::Init( )\n" |
857                 "       curState = startState;\n" |
858                 "       accept = 0;\n" |
859                 "::Execute( char *data, int dlen )\n" |
860                 "       char *p = data;\n" |
861                 "       int len = dlen;\n" |
862                 "       int cs = curState;\n" |
863                 "       for ( ; len > 0; p++, len-- ) {\n" |
864                 "               unsigned char c = (unsigned char)*p;\n" |
865                 "       curState = cs;\n" |
866                 "/**********************************************************************\n" |
867                 "::Finish\n" |
868                 " * Indicate to the fsm that the input is done. Does cleanup tasks.\n" |
869                 "void \n" |
870                 "::Finish( )\n" |
871                 "       int cs = curState;\n" |
872                 "       int accept = 0;\n" |
873                 "       this->accept = accept;\n" |
874                 "/*******************************************************\n" |
875                 "::Accept\n" |
876                 " * Did the machine accept?\n" |
877                 "int \n" |
878                 "::Accept( )\n" |
879                 "       return accept;\n" |
880                 "10SelCodeGen\n" |
881                 "11CSelCodeGen\n" |
882                 "12CCSelCodeGen\n" |
883                 "10FsmCodeGen\n" |
884                 "bad_alloc\n" |
885                 "goto tr\n" |
886                 "goto st\n" |
887                 "goto err;\n" |
888                 "       case \n" |
889                 "break;}\n" |
890                 ": goto st\n" |
891                 "               case \n" |
892                 "               default: return;\n" |
893                 "       goto st\n" |
894                 "       if ( --len == 0 )\n" |
895                 "               goto out\n" |
896                 "       switch( (alph) *++p ) {\n" |
897                 "case \n" |
898                 "               default: \n" |
899                 "       return;\n" |
900                 "curState = \n" |
901                 "       switch( cs ) {\n" |
902                 "accept = 1; \n" |
903                 "break;\n" |
904                 "err:\n" |
905                 "curState = -1;\n" |
906                 ", p );\n" |
907                 "ExecFuncs( fsm, f+\n" |
908                 "fsm->\n" |
909                 "/* Only non-static data: current state. */\n" |
910                 "struct \n" |
911                 "Struct\n" |
912                 "       int curState;\n" |
913                 "       int accept;\n" |
914                 "typedef struct \n" |
915                 "Struct \n" |
916                 "/* Init the fsm. */\n" |
917                 "void \n" |
918                 "Init( \n" |
919                 " *fsm );\n" |
920                 "/* Execute some chunk of data. */\n" |
921                 "void \n" |
922                 "Execute( \n" |
923                 " *fsm, char *data, int dlen );\n" |
924                 "/* Indicate to the fsm tha there is no more data. */\n" |
925                 "void \n" |
926                 "Finish( \n" |
927                 " *fsm );\n" |
928                 "/* Did the machine accept? */\n" |
929                 "int \n" |
930                 "Accept( \n" |
931                 " *fsm );\n" |
932                 "/* The start state. */\n" |
933                 "static int \n" |
934                 "_startState = \n" |
935                 "#define f \n" |
936                 "#define alph unsigned char\n" |
937                 "/* The array of functions. */\n" |
938                 "#if \n" |
939                 "static int \n" |
940                 "_f[] = {\n" |
941                 "#endif\n" |
942                 "/****************************************\n" |
943                 "Init\n" |
944                 "void \n" |
945                 " *fsm )\n" |
946                 "       fsm->curState = \n" |
947                 "_startState;\n" |
948                 "       fsm->accept = 0;\n" |
949                 "/***************************************************************************\n" |
950                 " * Function exection. We do not inline this as in tab\n" |
951                 " * code gen because if we did, we might as well just expand \n" |
952                 " * the function as in the faster goto code generator.\n" |
953                 "static void \n" |
954                 "ExecFuncs( \n" |
955                 " *fsm, int *funcs, char *p )\n" |
956                 "       int len = *funcs++;\n" |
957                 "       while ( len-- > 0 ) {\n" |
958                 "               switch ( *funcs++ ) {\n" |
959                 "/**********************************************************************\n" |
960                 " * Execute the fsm on some chunk of data. \n" |
961                 "void \n" |
962                 " *fsm, char *data, int dlen )\n" |
963                 "       /* Prime these to one back to simulate entering the \n" |
964                 "        * machine on a transition. */ \n" |
965                 "       register char *p = data - 1;\n" |
966                 "       register int len = dlen + 1;\n" |
967                 "       /* Switch statment to enter the machine. */\n" |
968                 "       switch ( \n" |
969                 "curState ) {\n" |
970                 "/**********************************************************************\n" |
971                 " * Indicate to the fsm that the input is done. Does cleanup tasks.\n" |
972                 "void \n" |
973                 " *fsm )\n" |
974                 "       int cs = fsm->curState;\n" |
975                 "       int accept = 0;\n" |
976                 "       fsm->accept = accept;\n" |
977                 "/*******************************************************\n" |
978                 " * Did the machine accept?\n" |
979                 "int \n" |
980                 " *fsm )\n" |
981                 "       return fsm->accept;\n" |
982                 "#undef f\n" |
983                 "#undef alph\n" |
984                 "       ExecFuncs( f+\n" |
985                 "/* Only non-static data: current state. */\n" |
986                 "class \n" |
987                 "public:\n" |
988                 "       /* Init the fsm. */\n" |
989                 "       void Init( );\n" |
990                 "       /* Execute some chunk of data. */\n" |
991                 "       void Execute( char *data, int dlen );\n" |
992                 "       /* Indicate to the fsm tha there is no more data. */\n" |
993                 "       void Finish( );\n" |
994                 "       /* Did the machine accept? */\n" |
995                 "       int Accept( );\n" |
996                 "       int curState;\n" |
997                 "       int accept;\n" |
998                 "       /* The start state. */\n" |
999                 "       static int startState;\n" |
1000                 "       /* Function exection. We do not inline this as in tab code gen\n" |
1001                 "        * because if we did, we might as well just expand the function \n" |
1002                 "        * as in the faster goto code generator. */\n" |
1003                 "       void ExecFuncs( int *funcs, char * );\n" |
1004                 "/* The start state. */\n" |
1005                 "int \n" |
1006                 "::startState = \n" |
1007                 "/* some defines to lessen the code size. */\n" |
1008                 "#define f \n" |
1009                 "#endif\n" |
1010                 "/****************************************\n" |
1011                 " * Make sure the fsm is initted.\n" |
1012                 "       Init();\n" |
1013                 "/****************************************\n" |
1014                 " * Initialize the fsm.\n" |
1015                 "void \n" |
1016                 "::Init( )\n" |
1017                 "       curState = startState;\n" |
1018                 "       accept = 0;\n" |
1019                 "/***************************************************************************\n" |
1020                 " * Execute functions pointed to by funcs until the null function is found. \n" |
1021                 "void \n" |
1022                 "::ExecFuncs( int *funcs, char *p )\n" |
1023                 "       int len = *funcs++;\n" |
1024                 "       while ( len-- > 0 ) {\n" |
1025                 "               switch ( *funcs++ ) {\n" |
1026                 "/**********************************************************************\n" |
1027                 " * Execute the fsm on some chunk of data. \n" |
1028                 "void \n" |
1029                 "::Execute( char *data, int dlen )\n" |
1030                 "       /* Prime these to one back to simulate entering the \n" |
1031                 "        * machine on a transition. */ \n" |
1032                 "       register char *p = data - 1;\n" |
1033                 "       register int len = dlen + 1;\n" |
1034                 "       /* Switch statment to enter the machine. */\n" |
1035                 "       switch ( curState ) {\n" |
1036                 "/**********************************************************************\n" |
1037                 "::Finish\n" |
1038                 " * Indicate to the fsm that the input is done. Does cleanup tasks.\n" |
1039                 "void \n" |
1040                 "::Finish( )\n" |
1041                 "       int cs = curState;\n" |
1042                 "       int accept = 0;\n" |
1043                 "       this->accept = accept;\n" |
1044                 "/*******************************************************\n" |
1045                 "::Accept\n" |
1046                 " * Did the machine accept?\n" |
1047                 "int \n" |
1048                 "::Accept( )\n" |
1049                 "       return accept;\n" |
1050                 "#undef f\n" |
1051                 "#undef alph\n" |
1052                 "11GotoCodeGen\n" |
1053                 "12CGotoCodeGen\n" |
1054                 "13CCGotoCodeGen\n" |
1055                 "10FsmCodeGen\n" |
1056                 "bad_alloc\n" |
1057                 "       case \n" |
1058                 "       break;\n" |
1059                 ", p );\n" |
1060                 "ExecFuncs( fsm, \n" |
1061                 "fsm->\n" |
1062                 "/* Only non-static data: current state. */\n" |
1063                 "struct \n" |
1064                 "Struct\n" |
1065                 "       int curState;\n" |
1066                 "       int accept;\n" |
1067                 "typedef struct \n" |
1068                 "Struct \n" |
1069                 "/* Init the fsm. */\n" |
1070                 "void \n" |
1071                 "Init( \n" |
1072                 " *fsm );\n" |
1073                 "/* Execute some chunk of data. */\n" |
1074                 "void \n" |
1075                 "Execute( \n" |
1076                 " *fsm, char *data, int dlen );\n" |
1077                 "/* Indicate to the fsm tha there is no more data. */\n" |
1078                 "void \n" |
1079                 "Finish( \n" |
1080                 " *fsm );\n" |
1081                 "/* Did the machine accept? */\n" |
1082                 "int \n" |
1083                 "Accept( \n" |
1084                 " *fsm );\n" |
1085                 "/* The start state. */\n" |
1086                 "static int \n" |
1087                 "_startState = \n" |
1088                 "/****************************************\n" |
1089                 "Init\n" |
1090                 "void \n" |
1091                 " *fsm )\n" |
1092                 "       fsm->curState = \n" |
1093                 "_startState;\n" |
1094                 "       fsm->accept = 0;\n" |
1095                 "/***************************************************************************\n" |
1096                 " * Function exection. We do not inline this as in tab\n" |
1097                 " * code gen because if we did, we might as well just expand \n" |
1098                 " * the function as in the faster goto code generator.\n" |
1099                 "static void \n" |
1100                 "ExecFuncs( \n" |
1101                 " *fsm, int func, char *p )\n" |
1102                 "       switch ( func ) {\n" |
1103                 "#define alph unsigned char\n" |
1104                 "/**********************************************************************\n" |
1105                 " * Execute the fsm on some chunk of data. \n" |
1106                 "void \n" |
1107                 " *fsm, char *data, int dlen )\n" |
1108                 "       /* Prime these to one back to simulate entering the \n" |
1109                 "        * machine on a transition. */ \n" |
1110                 "       register char *p = data-1;\n" |
1111                 "       register int len = dlen+1;\n" |
1112                 "       /* Switch statment to enter the machine. */\n" |
1113                 "       switch ( \n" |
1114                 "curState ) {\n" |
1115                 "/**********************************************************************\n" |
1116                 "Finish\n" |
1117                 " * Indicate to the fsm that the input is done. Does cleanup tasks.\n" |
1118                 "void \n" |
1119                 " *fsm )\n" |
1120                 "       int cs = fsm->curState;\n" |
1121                 "       int accept = 0;\n" |
1122                 "       fsm->accept = accept;\n" |
1123                 "/*******************************************************\n" |
1124                 "Accept\n" |
1125                 " * Did the machine accept?\n" |
1126                 "int \n" |
1127                 " *fsm )\n" |
1128                 "       return fsm->accept;\n" |
1129                 "#undef alph\n" |
1130                 "       ExecFuncs( \n" |
1131                 "/* Only non-static data: current state. */\n" |
1132                 "class \n" |
1133                 "public:\n" |
1134                 "       /* Init the fsm. */\n" |
1135                 "       void Init( );\n" |
1136                 "       /* Execute some chunk of data. */\n" |
1137                 "       void Execute( char *data, int dlen );\n" |
1138                 "       /* Indicate to the fsm tha there is no more data. */\n" |
1139                 "       void Finish( );\n" |
1140                 "       /* Did the machine accept? */\n" |
1141                 "       int Accept( );\n" |
1142                 "       int curState;\n" |
1143                 "       int accept;\n" |
1144                 "       /* The start state. */\n" |
1145                 "       static int startState;\n" |
1146                 "       /* Function exection. We do not inline this as in tab code gen\n" |
1147                 "        * because if we did, we might as well just expand the function \n" |
1148                 "        * as in the faster goto code generator. */\n" |
1149                 "       void ExecFuncs( int func, char *p );\n" |
1150                 "/* The start state. */\n" |
1151                 "int \n" |
1152                 "::startState = \n" |
1153                 "       Init();\n" |
1154                 "/****************************************\n" |
1155                 "::Init\n" |
1156                 "void \n" |
1157                 "::Init( )\n" |
1158                 "       curState = startState;\n" |
1159                 "       accept = 0;\n" |
1160                 "/***************************************************************************\n" |
1161                 " * Execute functions pointed to by funcs until the null function is found. \n" |
1162                 "void \n" |
1163                 "::ExecFuncs( int func, char *p )\n" |
1164                 "       switch ( func ) {\n" |
1165                 "::Execute( char *data, int dlen )\n" |
1166                 "       /* Prime these to one back to simulate entering the \n" |
1167                 "        * machine on a transition. */ \n" |
1168                 "       register char *p = data-1;\n" |
1169                 "       register int len = dlen+1;\n" |
1170                 "       /* Switch statment to enter the machine. */\n" |
1171                 "       switch ( curState ) {\n" |
1172                 "::Finish\n" |
1173                 " * Indicate to the fsm that the input is done. Does cleanup tasks.\n" |
1174                 "void \n" |
1175                 "::Finish( )\n" |
1176                 "       int cs = curState;\n" |
1177                 "       int accept = 0;\n" |
1178                 "       this->accept = accept;\n" |
1179                 "/*******************************************************\n" |
1180                 "::Accept\n" |
1181                 " * Did the machine accept?\n" |
1182                 "int \n" |
1183                 "::Accept( )\n" |
1184                 "       return accept;\n" |
1185                 "#undef alph\n" |
1186                 "12FGotoCodeGen\n" |
1187                 "13CFGotoCodeGen\n" |
1188                 "14CCFGotoCodeGen\n" |
1189                 "11GotoCodeGen\n" |
1190                 "10FsmCodeGen\n" |
1191                 "bad_alloc\n" |
1192                 "fsm->\n" |
1193                 "/* Only non-static data: current state. */\n" |
1194                 "struct \n" |
1195                 "Struct\n" |
1196                 "       int curState;\n" |
1197                 "       int accept;\n" |
1198                 "typedef struct \n" |
1199                 "Struct \n" |
1200                 "/* Init the fsm. */\n" |
1201                 "void \n" |
1202                 "Init( \n" |
1203                 " *fsm );\n" |
1204                 "/* Execute some chunk of data. */\n" |
1205                 "void \n" |
1206                 "Execute( \n" |
1207                 " *fsm, char *data, int dlen );\n" |
1208                 "/* Indicate to the fsm tha there is no more data. */\n" |
1209                 "void \n" |
1210                 "Finish( \n" |
1211                 " *fsm );\n" |
1212                 "/* Did the machine accept? */\n" |
1213                 "int \n" |
1214                 "Accept( \n" |
1215                 " *fsm );\n" |
1216                 "/* The start state. */\n" |
1217                 "static int \n" |
1218                 "_startState = \n" |
1219                 "/****************************************\n" |
1220                 "Init\n" |
1221                 "void \n" |
1222                 " *fsm )\n" |
1223                 "       fsm->curState = \n" |
1224                 "_startState;\n" |
1225                 "       fsm->accept = 0;\n" |
1226                 "#define alph unsigned char\n" |
1227                 "/**********************************************************************\n" |
1228                 " * Execute the fsm on some chunk of data. \n" |
1229                 "void \n" |
1230                 " *fsm, char *data, int dlen )\n" |
1231                 "       /* Prime these to one back to simulate entering the \n" |
1232                 "        * machine on a transition. */ \n" |
1233                 "       register char *p = data-1;\n" |
1234                 "       register int len = dlen+1;\n" |
1235                 "       /* Switch statment to enter the machine. */\n" |
1236                 "       switch ( \n" |
1237                 "curState ) {\n" |
1238                 "/**********************************************************************\n" |
1239                 "Finish\n" |
1240                 " * Indicate to the fsm that the input is done. Does cleanup tasks.\n" |
1241                 "void \n" |
1242                 " *fsm )\n" |
1243                 "       int cs = fsm->curState;\n" |
1244                 "       int accept = 0;\n" |
1245                 "       fsm->accept = accept;\n" |
1246                 "/*******************************************************\n" |
1247                 "Accept\n" |
1248                 " * Did the machine accept?\n" |
1249                 "int \n" |
1250                 " *fsm )\n" |
1251                 "       return fsm->accept;\n" |
1252                 "#undef alph\n" |
1253                 "/* Only non-static data: current state. */\n" |
1254                 "class \n" |
1255                 "public:\n" |
1256                 "       /* Init the fsm. */\n" |
1257                 "       void Init( );\n" |
1258                 "       /* Execute some chunk of data. */\n" |
1259                 "       void Execute( char *data, int dlen );\n" |
1260                 "       /* Indicate to the fsm tha there is no more data. */\n" |
1261                 "       void Finish( );\n" |
1262                 "       /* Did the machine accept? */\n" |
1263                 "       int Accept( );\n" |
1264                 "       int curState;\n" |
1265                 "       int accept;\n" |
1266                 "       /* The start state. */\n" |
1267                 "       static int startState;\n" |
1268                 "/* The start state. */\n" |
1269                 "int \n" |
1270                 "::startState = \n" |
1271                 "       Init();\n" |
1272                 "/****************************************\n" |
1273                 "::Init\n" |
1274                 "void \n" |
1275                 "::Init( )\n" |
1276                 "       curState = startState;\n" |
1277                 "       accept = 0;\n" |
1278                 "#define alph unsigned char\n" |
1279                 "/**********************************************************************\n" |
1280                 " * Execute the fsm on some chunk of data. \n" |
1281                 "void \n" |
1282                 "::Execute( char *data, int dlen )\n" |
1283                 "       /* Prime these to one back to simulate entering the \n" |
1284                 "        * machine on a transition. */ \n" |
1285                 "       register char *p = data-1;\n" |
1286                 "       register int len = dlen+1;\n" |
1287                 "       /* Switch statment to enter the machine. */\n" |
1288                 "       switch ( curState ) {\n" |
1289                 "::Finish\n" |
1290                 " * Indicate to the fsm that the input is done. Does cleanup tasks.\n" |
1291                 "void \n" |
1292                 "::Finish( )\n" |
1293                 "       int cs = curState;\n" |
1294                 "       int accept = 0;\n" |
1295                 "       this->accept = accept;\n" |
1296                 "/*******************************************************\n" |
1297                 "::Accept\n" |
1298                 " * Did the machine accept?\n" |
1299                 "int \n" |
1300                 "::Accept( )\n" |
1301                 "       return accept;\n" |
1302                 "#undef alph\n" |
1303                 "13IpGotoCodeGen\n" |
1304                 "14CIpGotoCodeGen\n" |
1305                 "15CCIpGotoCodeGen\n" |
1306                 "11GotoCodeGen\n" |
1307                 "10FsmCodeGen\n";
1308 }%%
1309
1310 %% write data;
1311 struct strs the_fsm;
1312
1313 void test( char *buf )
1314 {
1315         struct strs *fsm = &the_fsm;
1316         char *p = buf;
1317         char *pe = buf + strlen( buf );
1318
1319         %% write init;
1320         %% write exec;
1321
1322         if ( fsm->cs >= strs_first_final )
1323                 printf("ACCEPT\n");
1324         else
1325                 printf("FAIL\n");
1326 }
1327
1328
1329 int main()
1330 {
1331         test( "stdin\n" );
1332         test( "bad_alloc\n" );
1333         test( "_GLOBAL_OFFSET_TABLE_\n" );
1334         test( "not in\n" );
1335         test(
1336                 "isatty\n"
1337                 "junk on end.\n"
1338         );
1339
1340         return 0;
1341 }
1342
1343 #ifdef _____OUTPUT_____
1344 ACCEPT
1345 ACCEPT
1346 ACCEPT
1347 FAIL
1348 FAIL
1349 #endif