The fbreak statement now advances p.
[ragel.git] / rlgen-ruby / ruby-flatcodegen.cpp
blob71dbc9d39192b27068b1e003d420aa8b95f084c6
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 " " << P() << " += 1\n"
519 " _trigger_goto = true\n"
520 " _goto_level = _out\n"
521 " break\n"
522 " end\n";
525 int RubyFlatCodeGen::TO_STATE_ACTION( RedStateAp *state )
527 int act = 0;
528 if ( state->toStateAction != 0 )
529 act = state->toStateAction->location+1;
530 return act;
533 int RubyFlatCodeGen::FROM_STATE_ACTION( RedStateAp *state )
535 int act = 0;
536 if ( state->fromStateAction != 0 )
537 act = state->fromStateAction->location+1;
538 return act;
541 int RubyFlatCodeGen::EOF_ACTION( RedStateAp *state )
543 int act = 0;
544 if ( state->eofAction != 0 )
545 act = state->eofAction->location+1;
546 return act;
549 int RubyFlatCodeGen::TRANS_ACTION( RedTransAp *trans )
551 /* If there are actions, emit them. Otherwise emit zero. */
552 int act = 0;
553 if ( trans->action != 0 )
554 act = trans->action->location+1;
555 return act;
558 void RubyFlatCodeGen::writeData()
560 /* If there are any transtion functions then output the array. If there
561 * are none, don't bother emitting an empty array that won't be used. */
562 if ( redFsm->anyActions() ) {
563 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActArrItem), A() );
564 ACTIONS_ARRAY();
565 CLOSE_ARRAY() <<
566 "\n";
569 if ( redFsm->anyConditions() ) {
570 OPEN_ARRAY( WIDE_ALPH_TYPE(), CK() );
571 COND_KEYS();
572 CLOSE_ARRAY() <<
573 "\n";
575 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondSpan), CSP() );
576 COND_KEY_SPANS();
577 CLOSE_ARRAY() <<
578 "\n";
580 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCond), C() );
581 CONDS();
582 CLOSE_ARRAY() <<
583 "\n";
585 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondIndexOffset), CO() );
586 COND_INDEX_OFFSET();
587 CLOSE_ARRAY() <<
588 "\n";
591 OPEN_ARRAY( WIDE_ALPH_TYPE(), K() );
592 KEYS();
593 CLOSE_ARRAY() <<
594 "\n";
596 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxSpan), SP() );
597 KEY_SPANS();
598 CLOSE_ARRAY() <<
599 "\n";
601 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxFlatIndexOffset), IO() );
602 FLAT_INDEX_OFFSET();
603 CLOSE_ARRAY() <<
604 "\n";
606 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndex), I() );
607 INDICIES();
608 CLOSE_ARRAY() <<
609 "\n";
611 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() );
612 TRANS_TARGS();
613 CLOSE_ARRAY() <<
614 "\n";
616 if ( redFsm->anyActions() ) {
617 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TA() );
618 TRANS_ACTIONS();
619 CLOSE_ARRAY() <<
620 "\n";
623 if ( redFsm->anyToStateActions() ) {
624 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TSA() );
625 TO_STATE_ACTIONS();
626 CLOSE_ARRAY() <<
627 "\n";
630 if ( redFsm->anyFromStateActions() ) {
631 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), FSA() );
632 FROM_STATE_ACTIONS();
633 CLOSE_ARRAY() <<
634 "\n";
637 if ( redFsm->anyEofActions() ) {
638 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), EA() );
639 EOF_ACTIONS();
640 CLOSE_ARRAY() <<
641 "\n";
644 if ( redFsm->anyEofTrans() ) {
645 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndex+1), ET() );
646 EOF_TRANS();
647 CLOSE_ARRAY() <<
648 "\n";
651 STATE_IDS();
654 void RubyFlatCodeGen::writeExec()
656 out <<
657 "begin # ragel flat\n"
658 " testEof = false\n"
659 " _slen, _trans, _keys, _inds";
660 if ( redFsm->anyRegCurStateRef() )
661 out << ", _ps";
662 if ( redFsm->anyConditions() )
663 out << ", _cond, _conds, _widec";
664 if ( redFsm->anyToStateActions() || redFsm->anyRegActions()
665 || redFsm->anyFromStateActions() )
666 out << ", _acts, _nacts";
668 out << " = nil\n";
670 out <<
671 " _goto_level = 0\n"
672 " _resume = 10\n"
673 " _eof_trans = 15\n"
674 " _again = 20\n"
675 " _test_eof = 30\n"
676 " _out = 40\n";
678 out <<
679 " while true\n"
680 " _trigger_goto = false\n"
681 " if _goto_level <= 0\n";
683 if ( hasEnd ) {
684 out <<
685 " if " << P() << " == " << PE() << "\n"
686 " _goto_level = _test_eof\n"
687 " next\n"
688 " end\n";
691 if ( redFsm->errState != 0 ) {
692 out <<
693 " if " << CS() << " == " << redFsm->errState->id << "\n"
694 " _goto_level = _out\n"
695 " next\n"
696 " end\n";
699 /* The resume label. */
700 out <<
701 " end\n"
702 " if _goto_level <= _resume\n";
704 if ( redFsm->anyFromStateActions() ) {
705 out <<
706 " _acts = " << FSA() << "[" << CS() << "]\n"
707 " _nacts = " << A() << "[_acts]\n"
708 " _acts += 1\n"
709 " while _nacts > 0\n"
710 " _nacts -= 1\n"
711 " _acts += 1\n"
712 " case " << A() << "[_acts - 1]\n";
713 FROM_STATE_ACTION_SWITCH();
714 out <<
715 " end # from state action switch\n"
716 " end\n"
717 " if _trigger_goto\n"
718 " next\n"
719 " end\n";
722 if ( redFsm->anyConditions() )
723 COND_TRANSLATE();
725 LOCATE_TRANS();
727 if ( redFsm->anyEofTrans() ) {
728 out <<
729 " end\n"
730 " if _goto_level <= _eof_trans\n";
733 if ( redFsm->anyRegCurStateRef() )
734 out << " _ps = " << CS() << "\n";
736 out << " " << CS() << " = " << TT() << "[_trans]\n";
738 if ( redFsm->anyRegActions() ) {
739 out <<
740 " if " << TA() << "[_trans] != 0\n"
741 " _acts = " << TA() << "[_trans]\n"
742 " _nacts = " << A() << "[_acts]\n"
743 " _acts += 1\n"
744 " while _nacts > 0\n"
745 " _nacts -= 1\n"
746 " _acts += 1\n"
747 " case " << A() << "[_acts - 1]\n";
748 ACTION_SWITCH();
749 out <<
750 " end # action switch\n"
751 " end\n"
752 " end\n"
753 " if _trigger_goto\n"
754 " next\n"
755 " end\n";
758 /* The again label. */
759 out <<
760 " end\n"
761 " if _goto_level <= _again\n";
763 if ( redFsm->anyToStateActions() ) {
764 out <<
765 " _acts = " << TSA() << "[" << CS() << "]\n"
766 " _nacts = " << A() << "[_acts]\n"
767 " _acts += 1\n"
768 " while _nacts > 0\n"
769 " _nacts -= 1\n"
770 " _acts += 1\n"
771 " case " << A() << "[_acts - 1]\n";
772 TO_STATE_ACTION_SWITCH() <<
773 " end # to state action switch\n"
774 " end\n"
775 " if _trigger_goto\n"
776 " next\n"
777 " end\n";
780 if ( redFsm->errState != 0 ) {
781 out <<
782 " if " << CS() << " == " << redFsm->errState->id << "\n"
783 " _goto_level = _out\n"
784 " next\n"
785 " end\n";
788 out << " " << P() << " += 1\n";
790 if ( hasEnd ) {
791 out <<
792 " if " << P() << " != " << PE() << "\n"
793 " _goto_level = _resume\n"
794 " next\n"
795 " end\n";
797 else {
798 out <<
799 " _goto_level = _resume\n"
800 " next\n";
803 /* The test_eof label. */
804 out <<
805 " end\n"
806 " if _goto_level <= _test_eof\n";
808 if ( redFsm->anyEofTrans() || redFsm->anyEofActions() ) {
809 out <<
810 " if " << P() << " == " << EOFV() << "\n";
812 if ( redFsm->anyEofTrans() ) {
813 out <<
814 " if " << ET() << "[" << CS() << "] > 0\n"
815 " _trans = " << ET() << "[" << CS() << "] - 1;\n"
816 " _goto_level = _eof_trans\n"
817 " next;\n"
818 " end\n";
821 if ( redFsm->anyEofActions() ) {
822 out <<
823 " begin\n"
824 " __acts = " << EA() << "[" << CS() << "]\n"
825 " __nacts = " << A() << "[__acts]\n" <<
826 " __acts += 1\n"
827 " while ( __nacts > 0 ) \n"
828 " __nacts -= 1\n"
829 " __acts += 1\n"
830 " case ( "<< A() << "[__acts-1] ) \n";
831 EOF_ACTION_SWITCH() <<
832 " end\n"
833 " end\n"
834 " if _trigger_goto\n"
835 " next\n"
836 " end\n"
837 " end\n";
840 out <<
841 " end\n";
844 out <<
845 " end\n"
846 " if _goto_level <= _out\n"
847 " break\n"
848 " end\n";
850 /* The loop for faking goto. */
851 out <<
852 " end\n";
854 /* Wrapping the execute block. */
855 out <<
856 " end\n";
861 * Local Variables:
862 * mode: c++
863 * indent-tabs-mode: 1
864 * c-file-style: "bsd"
865 * End: