More fixes for ruby 1.9.
[ragel.git] / rlgen-ruby / ruby-flatcodegen.cpp
blobea20b55fd06f43f925bef8384f3b6970152eced0
1 /*
2 * Copyright 2001-2007 Adrian Thurston <thurston@cs.queensu.ca>
3 * Copyright 2007 Victor Hugo Borja <vic@rubyforge.org>
4 */
6 /* This file is part of Ragel.
8 * Ragel is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * Ragel is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Ragel; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "ruby-flatcodegen.h"
24 #include "rlgen-ruby.h"
25 #include "redfsm.h"
26 #include "gendata.h"
28 using std::ostream;
29 using std::string;
31 std::ostream &RubyFlatCodeGen::TO_STATE_ACTION_SWITCH()
33 /* Walk the list of functions, printing the cases. */
34 for ( ActionList::Iter act = actionList; act.lte(); act++ ) {
35 /* Write out referenced actions. */
36 if ( act->numToStateRefs > 0 ) {
37 /* Write the case label, the action and the case break */
38 out << "\twhen " << act->actionId << " then\n";
39 ACTION( out, act, 0, false );
43 genLineDirective( out );
44 return out;
47 std::ostream &RubyFlatCodeGen::FROM_STATE_ACTION_SWITCH()
49 /* Walk the list of functions, printing the cases. */
50 for ( ActionList::Iter act = actionList; act.lte(); act++ ) {
51 /* Write out referenced actions. */
52 if ( act->numFromStateRefs > 0 ) {
53 /* Write the case label, the action and the case break */
54 out << "\twhen " << act->actionId << " then\n";
55 ACTION( out, act, 0, false );
59 genLineDirective( out );
60 return out;
63 std::ostream &RubyFlatCodeGen::EOF_ACTION_SWITCH()
65 /* Walk the list of functions, printing the cases. */
66 for ( ActionList::Iter act = actionList; act.lte(); act++ ) {
67 /* Write out referenced actions. */
68 if ( act->numEofRefs > 0 ) {
69 /* Write the case label, the action and the case break */
70 out << "\twhen " << act->actionId << " then\n";
71 ACTION( out, act, 0, true );
75 genLineDirective( out );
76 return out;
79 std::ostream &RubyFlatCodeGen::ACTION_SWITCH()
81 /* Walk the list of functions, printing the cases. */
82 for ( ActionList::Iter act = actionList; act.lte(); act++ ) {
83 /* Write out referenced actions. */
84 if ( act->numTransRefs > 0 ) {
85 /* Write the case label, the action and the case break */
86 out << "\twhen " << act->actionId << " then\n";
87 ACTION( out, act, 0, false );
91 genLineDirective( out );
92 return out;
96 std::ostream &RubyFlatCodeGen::KEYS()
98 START_ARRAY_LINE();
99 int totalTrans = 0;
100 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
101 /* Emit just low key and high key. */
102 ARRAY_ITEM( KEY( st->lowKey ), ++totalTrans, false );
103 ARRAY_ITEM( KEY( st->highKey ), ++totalTrans, false );
104 if ( ++totalTrans % IALL == 0 )
105 out << "\n\t";
109 /* Output one last number so we don't have to figure out when the last
110 * entry is and avoid writing a comma. */
111 ARRAY_ITEM( INT( 0 ), ++totalTrans, true );
112 END_ARRAY_LINE();
113 return out;
116 std::ostream &RubyFlatCodeGen::INDICIES()
118 int totalTrans = 0;
119 START_ARRAY_LINE();
120 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
121 if ( st->transList != 0 ) {
122 /* Walk the singles. */
123 unsigned long long span = keyOps->span( st->lowKey, st->highKey );
124 for ( unsigned long long pos = 0; pos < span; pos++ ) {
125 ARRAY_ITEM( KEY( st->transList[pos]->id ), ++totalTrans, false );
129 /* The state's default index goes next. */
130 if ( st->defTrans != 0 )
131 ARRAY_ITEM( KEY( st->defTrans->id ), ++totalTrans, false );
134 /* Output one last number so we don't have to figure out when the last
135 * entry is and avoid writing a comma. */
136 ARRAY_ITEM( INT( 0 ), ++totalTrans, true );
137 END_ARRAY_LINE();
138 return out;
141 std::ostream &RubyFlatCodeGen::FLAT_INDEX_OFFSET()
143 START_ARRAY_LINE();
144 int totalStateNum = 0, curIndOffset = 0;
145 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
146 /* Write the index offset. */
147 ARRAY_ITEM( INT( curIndOffset ), ++totalStateNum, st.last() );
148 /* Move the index offset ahead. */
149 if ( st->transList != 0 )
150 curIndOffset += keyOps->span( st->lowKey, st->highKey );
152 if ( st->defTrans != 0 )
153 curIndOffset += 1;
156 END_ARRAY_LINE();
157 return out;
160 std::ostream &RubyFlatCodeGen::KEY_SPANS()
162 START_ARRAY_LINE();
163 int totalStateNum = 0;
164 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
165 /* Write singles length. */
166 unsigned long long span = 0;
167 if ( st->transList != 0 )
168 span = keyOps->span( st->lowKey, st->highKey );
169 ARRAY_ITEM( INT( span ), ++totalStateNum, st.last() );
171 END_ARRAY_LINE();
172 return out;
175 std::ostream &RubyFlatCodeGen::TO_STATE_ACTIONS()
177 START_ARRAY_LINE();
178 int totalStateNum = 0;
179 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
180 /* Write any eof action. */
181 ARRAY_ITEM( INT( TO_STATE_ACTION(st) ), ++totalStateNum, st.last() );
183 END_ARRAY_LINE();
184 return out;
187 std::ostream &RubyFlatCodeGen::FROM_STATE_ACTIONS()
189 START_ARRAY_LINE();
190 int totalStateNum = 0;
191 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
192 /* Write any eof action. */
193 ARRAY_ITEM( INT( FROM_STATE_ACTION(st) ), ++totalStateNum, st.last() );
195 END_ARRAY_LINE();
196 return out;
199 std::ostream &RubyFlatCodeGen::EOF_ACTIONS()
201 START_ARRAY_LINE();
202 int totalStateNum = 0;
203 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
204 /* Write any eof action. */
205 ARRAY_ITEM( INT( EOF_ACTION(st) ), ++totalStateNum, st.last() );
207 END_ARRAY_LINE();
208 return out;
211 std::ostream &RubyFlatCodeGen::EOF_TRANS()
213 START_ARRAY_LINE();
214 int totalStateNum = 0;
215 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
216 /* Write any eof action. */
217 long trans = 0;
218 if ( st->eofTrans != 0 )
219 trans = st->eofTrans->id+1;
221 /* Write any eof action. */
222 ARRAY_ITEM( INT(trans), ++totalStateNum, st.last() );
224 END_ARRAY_LINE();
225 return out;
228 std::ostream &RubyFlatCodeGen::TRANS_TARGS()
230 /* Transitions must be written ordered by their id. */
231 RedTransAp **transPtrs = new RedTransAp*[redFsm->transSet.length()];
232 for ( TransApSet::Iter trans = redFsm->transSet; trans.lte(); trans++ )
233 transPtrs[trans->id] = trans;
235 /* Keep a count of the num of items in the array written. */
236 START_ARRAY_LINE();
238 int totalStates = 0;
239 for ( int t = 0; t < redFsm->transSet.length(); t++ ) {
240 /* Write out the target state. */
241 RedTransAp *trans = transPtrs[t];
242 ARRAY_ITEM( INT( trans->targ->id ), ++totalStates, t >= redFsm->transSet.length()-1 );
244 END_ARRAY_LINE();
245 delete[] transPtrs;
246 return out;
250 std::ostream &RubyFlatCodeGen::TRANS_ACTIONS()
252 /* Transitions must be written ordered by their id. */
253 RedTransAp **transPtrs = new RedTransAp*[redFsm->transSet.length()];
254 for ( TransApSet::Iter trans = redFsm->transSet; trans.lte(); trans++ )
255 transPtrs[trans->id] = trans;
257 /* Keep a count of the num of items in the array written. */
258 START_ARRAY_LINE();
259 int totalAct = 0;
260 for ( int t = 0; t < redFsm->transSet.length(); t++ ) {
261 /* Write the function for the transition. */
262 RedTransAp *trans = transPtrs[t];
263 ARRAY_ITEM( INT( TRANS_ACTION( trans ) ), ++totalAct, t >= redFsm->transSet.length()-1 );
265 END_ARRAY_LINE();
266 delete[] transPtrs;
267 return out;
271 void RubyFlatCodeGen::LOCATE_TRANS()
273 out <<
274 " _keys = " << CS() << " << 1\n"
275 " _inds = " << IO() << "[" << CS() << "]\n"
276 " _slen = " << SP() << "[" << CS() << "]\n"
277 " _trans = if ( _slen > 0 && \n"
278 " " << K() << "[_keys] <= " << GET_WIDE_KEY() << " && \n"
279 " " << GET_WIDE_KEY() << " <= " << K() << "[_keys + 1] \n"
280 " ) then\n"
281 " " << I() << "[ _inds + " << GET_WIDE_KEY() << " - " << K() << "[_keys] ] \n"
282 " else \n"
283 " " << I() << "[ _inds + _slen ]\n"
284 " end\n"
289 std::ostream &RubyFlatCodeGen::COND_INDEX_OFFSET()
291 START_ARRAY_LINE();
292 int totalStateNum = 0, curIndOffset = 0;
293 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
294 /* Write the index offset. */
295 ARRAY_ITEM( INT( curIndOffset ), ++totalStateNum, st.last() );
296 /* Move the index offset ahead. */
297 if ( st->condList != 0 )
298 curIndOffset += keyOps->span( st->condLowKey, st->condHighKey );
300 END_ARRAY_LINE();
301 return out;
304 void RubyFlatCodeGen::COND_TRANSLATE()
306 out <<
307 " _widec = " << GET_KEY() << "\n"
308 " _keys = " << CS() << " << 1\n"
309 " _conds = " << CO() << "[" << CS() << "]\n"
310 " _slen = " << CSP() << "[" << CS() << "]\n"
311 " _cond = if ( _slen > 0 && \n"
312 " " << CK() << "[_keys] <= " << GET_WIDE_KEY() << " &&\n"
313 " " << GET_WIDE_KEY() << " <= " << CK() << "[_keys + 1]\n"
314 " ) then \n"
315 " " << C() << "[ _conds + " << GET_WIDE_KEY() << " - " << CK() << "[_keys]" << " ]\n"
316 " else\n"
317 " 0\n"
318 " end\n";
319 out <<
320 " case _cond \n";
321 for ( CondSpaceList::Iter csi = condSpaceList; csi.lte(); csi++ ) {
322 CondSpace *condSpace = csi;
323 out << " when " << condSpace->condSpaceId + 1 << " then\n";
324 out << TABS(2) << "_widec = " << "(" <<
325 KEY(condSpace->baseKey) << " + (" << GET_KEY() <<
326 " - " << KEY(keyOps->minKey) << "))\n";
328 for ( CondSet::Iter csi = condSpace->condSet; csi.lte(); csi++ ) {
329 out << TABS(2) << "if ( ";
330 CONDITION( out, *csi );
331 Size condValOffset = ((1 << csi.pos()) * keyOps->alphSize());
332 out <<
333 " ) then \n" <<
334 TABS(3) << " _widec += " << condValOffset << "\n"
335 "end\n";
339 out <<
340 " end # _cond switch \n";
343 std::ostream &RubyFlatCodeGen::CONDS()
345 int totalTrans = 0;
346 START_ARRAY_LINE();
347 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
348 if ( st->condList != 0 ) {
349 /* Walk the singles. */
350 unsigned long long span = keyOps->span( st->condLowKey, st->condHighKey );
351 for ( unsigned long long pos = 0; pos < span; pos++ ) {
352 if ( st->condList[pos] != 0 )
353 ARRAY_ITEM( INT( st->condList[pos]->condSpaceId + 1 ), ++totalTrans, false );
354 else
355 ARRAY_ITEM( INT( 0 ), ++totalTrans, false );
360 /* Output one last number so we don't have to figure out when the last
361 * entry is and avoid writing a comma. */
362 ARRAY_ITEM( INT( 0 ), ++totalTrans, true );
363 END_ARRAY_LINE();
364 return out;
367 std::ostream &RubyFlatCodeGen::COND_KEYS()
369 START_ARRAY_LINE();
370 int totalTrans = 0;
371 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
372 /* Emit just cond low key and cond high key. */
373 ARRAY_ITEM( KEY( st->condLowKey ), ++totalTrans, false );
374 ARRAY_ITEM( KEY( st->condHighKey ), ++totalTrans, false );
377 /* Output one last number so we don't have to figure out when the last
378 * entry is and avoid writing a comma. */
379 ARRAY_ITEM( INT( 0 ), ++totalTrans, true );
380 END_ARRAY_LINE();
381 return out;
384 std::ostream &RubyFlatCodeGen::COND_KEY_SPANS()
386 START_ARRAY_LINE();
387 int totalStateNum = 0;
388 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
389 /* Write singles length. */
390 unsigned long long span = 0;
391 if ( st->condList != 0 )
392 span = keyOps->span( st->condLowKey, st->condHighKey );
393 ARRAY_ITEM( INT( span ), ++totalStateNum, false );
395 END_ARRAY_LINE();
396 return out;
400 void RubyFlatCodeGen::GOTO( ostream &out, int gotoDest, bool inFinish )
402 out <<
403 " begin\n"
404 " " << CS() << " = " << gotoDest << "\n"
405 " _trigger_goto = true\n"
406 " _goto_level = _again\n"
407 " break\n"
408 " end\n";
411 void RubyFlatCodeGen::CALL( ostream &out, int callDest, int targState, bool inFinish )
413 if ( prePushExpr != 0 ) {
414 out << "begin\n";
415 INLINE_LIST( out, prePushExpr, 0, false );
418 out <<
419 " begin\n"
420 " " << STACK() << "[" << TOP() << "] = " << CS() << "\n"
421 " " << TOP() << "+= 1\n"
422 " " << CS() << " = " << callDest << "\n"
423 " _trigger_goto = true\n"
424 " _goto_level = _again\n"
425 " break\n"
426 " end\n";
428 if ( prePushExpr != 0 )
429 out << "end\n";
432 void RubyFlatCodeGen::CALL_EXPR(ostream &out, InlineItem *ilItem, int targState, bool inFinish )
434 if ( prePushExpr != 0 ) {
435 out << "begin\n";
436 INLINE_LIST( out, prePushExpr, 0, false );
439 out <<
440 " begin\n"
441 " " << STACK() << "[" << TOP() << "] = " << CS() << "\n"
442 " " << TOP() << " += 1\n"
443 " " << CS() << " = (";
444 INLINE_LIST( out, ilItem->children, targState, inFinish );
445 out << ")\n";
447 out <<
448 " _trigger_goto = true\n"
449 " _goto_level = _again\n"
450 " break\n"
451 " end\n";
453 if ( prePushExpr != 0 )
454 out << "end\n";
457 void RubyFlatCodeGen::RET( ostream &out, bool inFinish )
459 out <<
460 " begin\n"
461 " " << TOP() << " -= 1\n"
462 " " << CS() << " = " << STACK() << "[" << TOP() << "]\n";
464 if ( postPopExpr != 0 ) {
465 out << "begin\n";
466 INLINE_LIST( out, postPopExpr, 0, false );
467 out << "end\n";
470 out <<
471 " _trigger_goto = true\n"
472 " _goto_level = _again\n"
473 " break\n"
474 " end\n";
477 void RubyFlatCodeGen::NEXT( ostream &ret, int nextDest, bool inFinish )
479 ret << CS() << " = " << nextDest << ";";
482 void RubyFlatCodeGen::GOTO_EXPR( ostream &out, InlineItem *ilItem, bool inFinish )
484 out <<
485 " begin\n"
486 " " << CS() << " = (";
487 INLINE_LIST( out, ilItem->children, 0, inFinish );
488 out << ")\n";
489 out <<
490 " _trigger_goto = true\n"
491 " _goto_level = _again\n"
492 " break\n"
493 " end\n";
496 void RubyFlatCodeGen::NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish )
498 ret << CS() << " = (";
499 INLINE_LIST( ret, ilItem->children, 0, inFinish );
500 ret << ");";
504 void RubyFlatCodeGen::CURS( ostream &ret, bool inFinish )
506 ret << "(_ps)";
509 void RubyFlatCodeGen::TARGS( ostream &ret, bool inFinish, int targState )
511 ret << "(" << CS() << ")";
514 void RubyFlatCodeGen::BREAK( ostream &out, int targState )
516 out <<
517 " begin\n"
518 " _trigger_goto = true\n"
519 " _goto_level = _out\n"
520 " break\n"
521 " end\n";
524 int RubyFlatCodeGen::TO_STATE_ACTION( RedStateAp *state )
526 int act = 0;
527 if ( state->toStateAction != 0 )
528 act = state->toStateAction->location+1;
529 return act;
532 int RubyFlatCodeGen::FROM_STATE_ACTION( RedStateAp *state )
534 int act = 0;
535 if ( state->fromStateAction != 0 )
536 act = state->fromStateAction->location+1;
537 return act;
540 int RubyFlatCodeGen::EOF_ACTION( RedStateAp *state )
542 int act = 0;
543 if ( state->eofAction != 0 )
544 act = state->eofAction->location+1;
545 return act;
548 int RubyFlatCodeGen::TRANS_ACTION( RedTransAp *trans )
550 /* If there are actions, emit them. Otherwise emit zero. */
551 int act = 0;
552 if ( trans->action != 0 )
553 act = trans->action->location+1;
554 return act;
557 void RubyFlatCodeGen::writeData()
559 /* If there are any transtion functions then output the array. If there
560 * are none, don't bother emitting an empty array that won't be used. */
561 if ( redFsm->anyActions() ) {
562 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActArrItem), A() );
563 ACTIONS_ARRAY();
564 CLOSE_ARRAY() <<
565 "\n";
568 if ( redFsm->anyConditions() ) {
569 OPEN_ARRAY( WIDE_ALPH_TYPE(), CK() );
570 COND_KEYS();
571 CLOSE_ARRAY() <<
572 "\n";
574 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondSpan), CSP() );
575 COND_KEY_SPANS();
576 CLOSE_ARRAY() <<
577 "\n";
579 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCond), C() );
580 CONDS();
581 CLOSE_ARRAY() <<
582 "\n";
584 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondIndexOffset), CO() );
585 COND_INDEX_OFFSET();
586 CLOSE_ARRAY() <<
587 "\n";
590 OPEN_ARRAY( WIDE_ALPH_TYPE(), K() );
591 KEYS();
592 CLOSE_ARRAY() <<
593 "\n";
595 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxSpan), SP() );
596 KEY_SPANS();
597 CLOSE_ARRAY() <<
598 "\n";
600 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxFlatIndexOffset), IO() );
601 FLAT_INDEX_OFFSET();
602 CLOSE_ARRAY() <<
603 "\n";
605 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndex), I() );
606 INDICIES();
607 CLOSE_ARRAY() <<
608 "\n";
610 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() );
611 TRANS_TARGS();
612 CLOSE_ARRAY() <<
613 "\n";
615 if ( redFsm->anyActions() ) {
616 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TA() );
617 TRANS_ACTIONS();
618 CLOSE_ARRAY() <<
619 "\n";
622 if ( redFsm->anyToStateActions() ) {
623 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TSA() );
624 TO_STATE_ACTIONS();
625 CLOSE_ARRAY() <<
626 "\n";
629 if ( redFsm->anyFromStateActions() ) {
630 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), FSA() );
631 FROM_STATE_ACTIONS();
632 CLOSE_ARRAY() <<
633 "\n";
636 if ( redFsm->anyEofActions() ) {
637 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), EA() );
638 EOF_ACTIONS();
639 CLOSE_ARRAY() <<
640 "\n";
643 if ( redFsm->anyEofTrans() ) {
644 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndex+1), ET() );
645 EOF_TRANS();
646 CLOSE_ARRAY() <<
647 "\n";
650 STATE_IDS();
653 void RubyFlatCodeGen::writeExec()
655 out <<
656 "begin # ragel flat\n"
657 " testEof = false\n"
658 " _slen, _trans, _keys, _inds";
659 if ( redFsm->anyRegCurStateRef() )
660 out << ", _ps";
661 if ( redFsm->anyConditions() )
662 out << ", _cond, _conds, _widec";
663 if ( redFsm->anyToStateActions() || redFsm->anyRegActions()
664 || redFsm->anyFromStateActions() )
665 out << ", _acts, _nacts";
667 out << " = nil\n";
669 out <<
670 " _goto_level = 0\n"
671 " _resume = 10\n"
672 " _eof_trans = 15\n"
673 " _again = 20\n"
674 " _test_eof = 30\n"
675 " _out = 40\n";
677 out <<
678 " while true\n"
679 " _trigger_goto = false\n"
680 " if _goto_level <= 0\n";
682 if ( hasEnd ) {
683 out <<
684 " if " << P() << " == " << PE() << "\n"
685 " _goto_level = _test_eof\n"
686 " next\n"
687 " end\n";
690 if ( redFsm->errState != 0 ) {
691 out <<
692 " if " << CS() << " == " << redFsm->errState->id << "\n"
693 " _goto_level = _out\n"
694 " next\n"
695 " end\n";
698 /* The resume label. */
699 out <<
700 " end\n"
701 " if _goto_level <= _resume\n";
703 if ( redFsm->anyFromStateActions() ) {
704 out <<
705 " _acts = " << FSA() << "[" << CS() << "]\n"
706 " _nacts = " << A() << "[_acts]\n"
707 " _acts += 1\n"
708 " while _nacts > 0\n"
709 " _nacts -= 1\n"
710 " _acts += 1\n"
711 " case " << A() << "[_acts - 1]\n";
712 FROM_STATE_ACTION_SWITCH();
713 out <<
714 " end # from state action switch\n"
715 " end\n"
716 " if _trigger_goto\n"
717 " next\n"
718 " end\n";
721 if ( redFsm->anyConditions() )
722 COND_TRANSLATE();
724 LOCATE_TRANS();
726 if ( redFsm->anyEofTrans() ) {
727 out <<
728 " end\n"
729 " if _goto_level <= _eof_trans\n";
732 if ( redFsm->anyRegCurStateRef() )
733 out << " _ps = " << CS() << "\n";
735 out << " " << CS() << " = " << TT() << "[_trans]\n";
737 if ( redFsm->anyRegActions() ) {
738 out <<
739 " if " << TA() << "[_trans] != 0\n"
740 " _acts = " << TA() << "[_trans]\n"
741 " _nacts = " << A() << "[_acts]\n"
742 " _acts += 1\n"
743 " while _nacts > 0\n"
744 " _nacts -= 1\n"
745 " _acts += 1\n"
746 " case " << A() << "[_acts - 1]\n";
747 ACTION_SWITCH();
748 out <<
749 " end # action switch\n"
750 " end\n"
751 " end\n"
752 " if _trigger_goto\n"
753 " next\n"
754 " end\n";
757 /* The again label. */
758 out <<
759 " end\n"
760 " if _goto_level <= _again\n";
762 if ( redFsm->anyToStateActions() ) {
763 out <<
764 " _acts = " << TSA() << "[" << CS() << "]\n"
765 " _nacts = " << A() << "[_acts]\n"
766 " _acts += 1\n"
767 " while _nacts > 0\n"
768 " _nacts -= 1\n"
769 " _acts += 1\n"
770 " case " << A() << "[_acts - 1]\n";
771 TO_STATE_ACTION_SWITCH() <<
772 " end # to state action switch\n"
773 " end\n"
774 " if _trigger_goto\n"
775 " next\n"
776 " end\n";
779 if ( redFsm->errState != 0 ) {
780 out <<
781 " if " << CS() << " == " << redFsm->errState->id << "\n"
782 " _goto_level = _out\n"
783 " next\n"
784 " end\n";
787 out << " " << P() << " += 1\n";
789 if ( hasEnd ) {
790 out <<
791 " if " << P() << " != " << PE() << "\n"
792 " _goto_level = _resume\n"
793 " next\n"
794 " end\n";
796 else {
797 out <<
798 " _goto_level = _resume\n"
799 " next\n";
802 /* The test_eof label. */
803 out <<
804 " end\n"
805 " if _goto_level <= _test_eof\n";
807 if ( redFsm->anyEofTrans() || redFsm->anyEofActions() ) {
808 out <<
809 " if " << P() << " == " << EOFV() << "\n";
811 if ( redFsm->anyEofTrans() ) {
812 out <<
813 " if " << ET() << "[" << CS() << "] > 0\n"
814 " _trans = " << ET() << "[" << CS() << "] - 1;\n"
815 " _goto_level = _eof_trans\n"
816 " next;\n"
817 " end\n";
820 if ( redFsm->anyEofActions() ) {
821 out <<
822 " begin\n"
823 " __acts = " << EA() << "[" << CS() << "]\n"
824 " __nacts = " << A() << "[__acts]\n" <<
825 " __acts += 1\n"
826 " while ( __nacts > 0 ) \n"
827 " __nacts -= 1\n"
828 " __acts += 1\n"
829 " case ( "<< A() << "[__acts-1] ) \n";
830 EOF_ACTION_SWITCH() <<
831 " end\n"
832 " end\n"
833 " if _trigger_goto\n"
834 " next\n"
835 " end\n"
836 " end\n";
839 out <<
840 " end\n";
843 out <<
844 " end\n"
845 " if _goto_level <= _out\n"
846 " break\n"
847 " end\n";
849 /* The loop for faking goto. */
850 out <<
851 " end\n";
853 /* Wrapping the execute block. */
854 out <<
855 " end\n";
860 * Local Variables:
861 * mode: c++
862 * indent-tabs-mode: 1
863 * c-file-style: "bsd"
864 * End: