private sync
[external/ragel.git] / ragel / rubycodegen.cpp
1 /*
2  *  2007 Victor Hugo Borja <vic@rubyforge.org>
3  *  Copyright 2001-2007 Adrian Thurston <thurston@complang.org>
4  */
5
6 /*  This file is part of Ragel.
7  *
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.
12  * 
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.
17  * 
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 
21  */
22
23 #include <iomanip>
24 #include <sstream>
25 #include "redfsm.h"
26 #include "gendata.h"
27 #include "ragel.h"
28 #include "rubycodegen.h"
29 #include "pcheck.h"
30 #include "vector.h"
31 #include "version.h"
32 #include "common.h"
33
34 #include "ragel.h"
35 #include "rubytable.h"
36 #include "rubyftable.h"
37 #include "rubyflat.h"
38 #include "rubyfflat.h"
39 #include "rbxgoto.h"
40
41 using std::ostream;
42 using std::ostringstream;
43 using std::string;
44 using std::cerr;
45 using std::endl;
46 using std::istream;
47 using std::ifstream;
48 using std::ostream;
49 using std::ios;
50 using std::cin;
51 using std::cout;
52 using std::cerr;
53 using std::endl;
54
55 /* Target ruby impl */
56
57 /* Target language and output style. */
58 extern CodeStyle codeStyle;
59
60 extern int numSplitPartitions;
61
62 /*
63  * Callbacks invoked by the XML data parser.
64  */
65
66
67 void rubyLineDirective( ostream &out, const char *fileName, int line )
68 {
69         /* Write a comment containing line info. */
70         out << "# line " << line  << " \"";
71         for ( const char *pc = fileName; *pc != 0; pc++ ) {
72                 if ( *pc == '\\' )
73                         out << "\\\\";
74                 else
75                         out << *pc;
76         }
77         out << "\"\n";
78 }
79
80 void RubyCodeGen::genLineDirective( ostream &out )
81 {
82         std::streambuf *sbuf = out.rdbuf();
83         output_filter *filter = static_cast<output_filter*>(sbuf);
84         rubyLineDirective( out, filter->fileName, filter->line + 1 );
85 }
86
87 string RubyCodeGen::DATA_PREFIX()
88 {
89         if ( !noPrefix )
90                 return FSM_NAME() + "_";
91         return "";
92 }
93
94 std::ostream &RubyCodeGen::STATIC_VAR( string type, string name )
95 {
96         out << 
97                 "class << self\n"
98                 "       attr_accessor :" << name << "\n"
99                 "end\n"
100                 "self." << name;
101         return out;
102 }
103
104
105 std::ostream &RubyCodeGen::OPEN_ARRAY( string type, string name )
106 {
107         out << 
108                 "class << self\n"
109                 "       attr_accessor :" << name << "\n"
110                 "       private :" << name << ", :" << name << "=\n"
111                 "end\n"
112                 "self." << name << " = [\n";
113         return out;
114 }
115
116 std::ostream &RubyCodeGen::CLOSE_ARRAY()
117 {
118         out << "]\n";
119         return out;
120 }
121
122
123 string RubyCodeGen::ARR_OFF( string ptr, string offset )
124 {
125         return ptr + "[" + offset + "]";
126 }
127
128 string RubyCodeGen::NULL_ITEM()
129 {
130         return "nil";
131 }
132
133
134 string RubyCodeGen::P()
135
136         ostringstream ret;
137         if ( pExpr == 0 )
138                 ret << "p";
139         else {
140                 //ret << "(";
141                 INLINE_LIST( ret, pExpr, 0, false );
142                 //ret << ")";
143         }
144         return ret.str();
145 }
146
147 string RubyCodeGen::PE()
148 {
149         ostringstream ret;
150         if ( peExpr == 0 )
151                 ret << "pe";
152         else {
153                 //ret << "(";
154                 INLINE_LIST( ret, peExpr, 0, false );
155                 //ret << ")";
156         }
157         return ret.str();
158 }
159
160 string RubyCodeGen::vEOF()
161 {
162         ostringstream ret;
163         if ( eofExpr == 0 )
164                 ret << "eof";
165         else {
166                 //ret << "(";
167                 INLINE_LIST( ret, eofExpr, 0, false );
168                 //ret << ")";
169         }
170         return ret.str();
171 }
172
173 string RubyCodeGen::vCS()
174 {
175         ostringstream ret;
176         if ( csExpr == 0 )
177                 ret << ACCESS() << "cs";
178         else {
179                 //ret << "(";
180                 INLINE_LIST( ret, csExpr, 0, false );
181                 //ret << ")";
182         }
183         return ret.str();
184 }
185
186 string RubyCodeGen::TOP()
187 {
188         ostringstream ret;
189         if ( topExpr == 0 )
190                 ret << ACCESS() + "top";
191         else {
192                 //ret << "(";
193                 INLINE_LIST( ret, topExpr, 0, false );
194                 //ret << ")";
195         }
196         return ret.str();
197 }
198
199 string RubyCodeGen::STACK()
200 {
201         ostringstream ret;
202         if ( stackExpr == 0 )
203                 ret << ACCESS() + "stack";
204         else {
205                 //ret << "(";
206                 INLINE_LIST( ret, stackExpr, 0, false );
207                 //ret << ")";
208         }
209         return ret.str();
210 }
211
212 string RubyCodeGen::ACT()
213 {
214         ostringstream ret;
215         if ( actExpr == 0 )
216                 ret << ACCESS() + "act";
217         else {
218                 //ret << "(";
219                 INLINE_LIST( ret, actExpr, 0, false );
220                 //ret << ")";
221         }
222         return ret.str();
223 }
224
225 string RubyCodeGen::TOKSTART()
226 {
227         ostringstream ret;
228         if ( tokstartExpr == 0 )
229                 ret << ACCESS() + "ts";
230         else {
231                 //ret << "(";
232                 INLINE_LIST( ret, tokstartExpr, 0, false );
233                 //ret << ")";
234         }
235         return ret.str();
236 }
237
238 string RubyCodeGen::TOKEND()
239 {
240         ostringstream ret;
241         if ( tokendExpr == 0 )
242                 ret << ACCESS() + "te";
243         else {
244                 //ret << "(";
245                 INLINE_LIST( ret, tokendExpr, 0, false );
246                 //ret << ")";
247         }
248         return ret.str();
249 }
250
251 string RubyCodeGen::DATA()
252 {
253         ostringstream ret;
254         if ( dataExpr == 0 )
255                 ret << ACCESS() + "data";
256         else {
257                 //ret << "(";
258                 INLINE_LIST( ret, dataExpr, 0, false );
259                 //ret << ")";
260         }
261         return ret.str();
262 }
263
264 /* Write out the fsm name. */
265 string RubyCodeGen::FSM_NAME()
266 {
267         return fsmName;
268 }
269
270
271 void RubyCodeGen::ACTION( ostream &ret, GenAction *action, int targState, bool inFinish )
272 {
273         /* Write the preprocessor line info for going into the source file. */
274         rubyLineDirective( ret, action->loc.fileName, action->loc.line );
275
276         /* Write the block and close it off. */
277         ret << "                begin\n";
278         INLINE_LIST( ret, action->inlineList, targState, inFinish );
279         ret << "                end\n";
280 }
281
282
283
284 string RubyCodeGen::GET_WIDE_KEY()
285 {
286         if ( redFsm->anyConditions() ) 
287                 return "_widec";
288         else
289                 return GET_KEY();
290 }
291
292 string RubyCodeGen::GET_WIDE_KEY( RedStateAp *state )
293 {
294         if ( state->stateCondList.length() > 0 )
295                 return "_widec";
296         else
297                 return GET_KEY();
298 }
299
300 string RubyCodeGen::GET_KEY()
301 {
302         ostringstream ret;
303         if ( getKeyExpr != 0 ) { 
304                 /* Emit the user supplied method of retrieving the key. */
305                 ret << "(";
306                 INLINE_LIST( ret, getKeyExpr, 0, false );
307                 ret << ")";
308         }
309         else {
310                 /* Expression for retrieving the key, use simple dereference. */
311                 ret << DATA() << "[" << P() << "]";
312         }
313         return ret.str();
314 }
315
316 string RubyCodeGen::KEY( Key key )
317 {
318         ostringstream ret;
319         if ( keyOps->isSigned || !hostLang->explicitUnsigned )
320                 ret << key.getVal();
321         else
322                 ret << (unsigned long) key.getVal();
323         return ret.str();
324 }
325
326
327 /* Write out level number of tabs. Makes the nested binary search nice
328  * looking. */
329 string RubyCodeGen::TABS( int level )
330 {
331         string result;
332         while ( level-- > 0 )
333                 result += "\t";
334         return result;
335 }
336
337 string RubyCodeGen::INT( int i )
338 {
339         ostringstream ret;
340         ret << i;
341         return ret.str();
342 }
343
344 void RubyCodeGen::CONDITION( ostream &ret, GenAction *condition )
345 {
346         ret << "\n";
347         rubyLineDirective( ret, condition->loc.fileName, condition->loc.line );
348         INLINE_LIST( ret, condition->inlineList, 0, false );
349 }
350
351 /* Emit the alphabet data type. */
352 string RubyCodeGen::ALPH_TYPE()
353 {
354         string ret = keyOps->alphType->data1;
355         if ( keyOps->alphType->data2 != 0 ) {
356                 ret += " ";
357                 ret += + keyOps->alphType->data2;
358         }
359         return ret;
360 }
361
362 /* Emit the alphabet data type. */
363 string RubyCodeGen::WIDE_ALPH_TYPE()
364 {
365         string ret;
366         if ( redFsm->maxKey <= keyOps->maxKey )
367                 ret = ALPH_TYPE();
368         else {
369                 long long maxKeyVal = redFsm->maxKey.getLongLong();
370                 HostType *wideType = keyOps->typeSubsumes( keyOps->isSigned, maxKeyVal );
371                 assert( wideType != 0 );
372
373                 ret = wideType->data1;
374                 if ( wideType->data2 != 0 ) {
375                         ret += " ";
376                         ret += wideType->data2;
377                 }
378         }
379         return ret;
380 }
381
382
383 string RubyCodeGen::ARRAY_TYPE( unsigned long maxVal )
384 {
385         long long maxValLL = (long long) maxVal;
386         HostType *arrayType = keyOps->typeSubsumes( maxValLL );
387         assert( arrayType != 0 );
388
389         string ret = arrayType->data1;
390         if ( arrayType->data2 != 0 ) {
391                 ret += " ";
392                 ret += arrayType->data2;
393         }
394         return ret;
395 }
396
397 /* Write out the array of actions. */
398 std::ostream &RubyCodeGen::ACTIONS_ARRAY()
399 {
400         START_ARRAY_LINE();
401         int totalActions = 0;
402         ARRAY_ITEM( INT(0), ++totalActions, false );
403         for ( GenActionTableMap::Iter act = redFsm->actionMap; act.lte(); act++ ) {
404                 /* Write out the length, which will never be the last character. */
405                 ARRAY_ITEM( INT(act->key.length()), ++totalActions, false );
406
407                 for ( GenActionTable::Iter item = act->key; item.lte(); item++ ) {
408                         ARRAY_ITEM( INT(item->value->actionId), ++totalActions, (act.last() && item.last()) );
409                 }
410         }
411         END_ARRAY_LINE();
412         return out;
413 }
414
415 void RubyCodeGen::STATE_IDS()
416 {
417         if ( redFsm->startState != 0 )
418                 STATIC_VAR( "int", START() ) << " = " << START_STATE_ID() << ";\n";
419
420         if ( !noFinal )
421                 STATIC_VAR( "int" , FIRST_FINAL() ) << " = " << FIRST_FINAL_STATE() << ";\n";
422
423         if ( !noError )
424                 STATIC_VAR( "int", ERROR() ) << " = " << ERROR_STATE() << ";\n";
425
426         out << "\n";
427
428         if ( entryPointNames.length() > 0 ) {
429                 for ( EntryNameVect::Iter en = entryPointNames; en.lte(); en++ ) {
430                         STATIC_VAR( "int", DATA_PREFIX() + "en_" + *en ) << 
431                                         " = " << entryPointIds[en.pos()] << ";\n";
432                 }
433                 out << "\n";
434         }
435 }
436
437 std::ostream &RubyCodeGen::START_ARRAY_LINE()
438 {
439         out << "\t";
440         return out;
441 }
442
443 std::ostream &RubyCodeGen::ARRAY_ITEM( string item, int count, bool last )
444 {
445         out << item;
446         if ( !last )
447         {
448                 out << ", ";
449                 if ( count % IALL == 0 )
450                 {
451                         END_ARRAY_LINE();
452                         START_ARRAY_LINE();
453                 }
454         }
455         return out;
456 }
457
458 std::ostream &RubyCodeGen::END_ARRAY_LINE()
459 {
460         out << "\n";
461         return out;
462 }
463
464 /* Emit the offset of the start state as a decimal integer. */
465 string RubyCodeGen::START_STATE_ID()
466 {
467         ostringstream ret;
468         ret << redFsm->startState->id;
469         return ret.str();
470 };
471
472 string RubyCodeGen::ERROR_STATE()
473 {
474         ostringstream ret;
475         if ( redFsm->errState != 0 )
476                 ret << redFsm->errState->id;
477         else
478                 ret << "-1";
479         return ret.str();
480 }
481
482 string RubyCodeGen::FIRST_FINAL_STATE()
483 {
484         ostringstream ret;
485         if ( redFsm->firstFinState != 0 )
486                 ret << redFsm->firstFinState->id;
487         else
488                 ret << redFsm->nextStateId;
489         return ret.str();
490 }
491
492 string RubyCodeGen::ACCESS()
493 {
494         ostringstream ret;
495         if ( accessExpr != 0 )
496                 INLINE_LIST( ret, accessExpr, 0, false );
497         return ret.str();
498 }
499
500 /* Write out an inline tree structure. Walks the list and possibly calls out
501  * to virtual functions than handle language specific items in the tree. */
502 void RubyCodeGen::INLINE_LIST( ostream &ret, GenInlineList *inlineList, 
503                 int targState, bool inFinish )
504 {
505         for ( GenInlineList::Iter item = *inlineList; item.lte(); item++ ) {
506                 switch ( item->type ) {
507                 case GenInlineItem::Text:
508                         ret << item->data;
509                         break;
510                 case GenInlineItem::Goto:
511                         GOTO( ret, item->targState->id, inFinish );
512                         break;
513                 case GenInlineItem::Call:
514                         CALL( ret, item->targState->id, targState, inFinish );
515                         break;
516                 case GenInlineItem::Next:
517                         NEXT( ret, item->targState->id, inFinish );
518                         break;
519                 case GenInlineItem::Ret:
520                         RET( ret, inFinish );
521                         break;
522                 case GenInlineItem::PChar:
523                         ret << P();
524                         break;
525                 case GenInlineItem::Char:
526                         ret << GET_KEY();
527                         break;
528                 case GenInlineItem::Hold:
529                         ret << P() << " = " << P() << " - 1;";
530                         break;
531                 case GenInlineItem::Exec:
532                         EXEC( ret, item, targState, inFinish );
533                         break;
534                 case GenInlineItem::Curs:
535                         ret << "(_ps)";
536                         break;
537                 case GenInlineItem::Targs:
538                         ret << "(" << vCS() << ")";
539                         break;
540                 case GenInlineItem::Entry:
541                         ret << item->targState->id;
542                         break;
543                 case GenInlineItem::GotoExpr:
544                         GOTO_EXPR( ret, item, inFinish );
545                         break;
546                 case GenInlineItem::CallExpr:
547                         CALL_EXPR( ret, item, targState, inFinish );
548                         break;
549                 case GenInlineItem::NextExpr:
550                         NEXT_EXPR( ret, item, inFinish );
551                         break;
552                 case GenInlineItem::LmSwitch:
553                         LM_SWITCH( ret, item, targState, inFinish );
554                         break;
555                 case GenInlineItem::LmSetActId:
556                         SET_ACT( ret, item );
557                         break;
558                 case GenInlineItem::LmSetTokEnd:
559                         SET_TOKEND( ret, item );
560                         break;
561                 case GenInlineItem::LmGetTokEnd:
562                         GET_TOKEND( ret, item );
563                         break;
564                 case GenInlineItem::LmInitTokStart:
565                         INIT_TOKSTART( ret, item );
566                         break;
567                 case GenInlineItem::LmInitAct:
568                         INIT_ACT( ret, item );
569                         break;
570                 case GenInlineItem::LmSetTokStart:
571                         SET_TOKSTART( ret, item );
572                         break;
573                 case GenInlineItem::SubAction:
574                         SUB_ACTION( ret, item, targState, inFinish );
575                         break;
576                 case GenInlineItem::Break:
577                         BREAK( ret, targState );
578                         break;
579                 }
580         }
581 }
582
583
584 void RubyCodeGen::EXEC( ostream &ret, GenInlineItem *item, int targState, int inFinish )
585 {
586         /* The parser gives fexec two children. The double brackets are for D
587          * code. If the inline list is a single word it will get interpreted as a
588          * C-style cast by the D compiler. */
589         ret << " begin " << P() << " = ((";
590         INLINE_LIST( ret, item->children, targState, inFinish );
591         ret << "))-1; end\n";
592 }
593
594 void RubyCodeGen::LM_SWITCH( ostream &ret, GenInlineItem *item, 
595                 int targState, int inFinish )
596 {
597         ret << 
598                 "       case " << ACT() << "\n";
599
600         for ( GenInlineList::Iter lma = *item->children; lma.lte(); lma++ ) {
601                 /* Write the case label, the action and the case break. */
602                 if ( lma->lmId < 0 )
603                         ret << "        else\n";
604                 else
605                         ret << "        when " << lma->lmId << " then\n";
606
607
608                 /* Write the block and close it off. */
609                 ret << "        begin";
610                 INLINE_LIST( ret, lma->children, targState, inFinish );
611                 ret << "end\n";
612         }
613
614         ret << "end \n\t";
615 }
616
617 void RubyCodeGen::SET_ACT( ostream &ret, GenInlineItem *item )
618 {
619         ret << ACT() << " = " << item->lmId << ";";
620 }
621
622 void RubyCodeGen::INIT_TOKSTART( ostream &ret, GenInlineItem *item )
623 {
624         ret << TOKSTART() << " = " << NULL_ITEM() << ";";
625 }
626
627 void RubyCodeGen::INIT_ACT( ostream &ret, GenInlineItem *item )
628 {
629         ret << ACT() << " = 0\n";
630 }
631
632 void RubyCodeGen::SET_TOKSTART( ostream &ret, GenInlineItem *item )
633 {
634         ret << TOKSTART() << " = " << P() << "\n";
635 }
636
637 void RubyCodeGen::SET_TOKEND( ostream &ret, GenInlineItem *item )
638 {
639         /* The tokend action sets tokend. */
640         ret << TOKEND() << " = " << P();
641         if ( item->offset != 0 ) 
642                 out << "+" << item->offset;
643         out << "\n";
644 }
645
646 void RubyCodeGen::GET_TOKEND( ostream &ret, GenInlineItem *item )
647 {
648         ret << TOKEND();
649 }
650
651 void RubyCodeGen::SUB_ACTION( ostream &ret, GenInlineItem *item, 
652                 int targState, bool inFinish )
653 {
654         if ( item->children->length() > 0 ) {
655                 /* Write the block and close it off. */
656                 ret << " begin ";
657                 INLINE_LIST( ret, item->children, targState, inFinish );
658                 ret << " end\n";
659         }
660 }
661
662 int RubyCodeGen::TRANS_ACTION( RedTransAp *trans )
663 {
664         /* If there are actions, emit them. Otherwise emit zero. */
665         int act = 0;
666         if ( trans->action != 0 )
667                 act = trans->action->location+1;
668         return act;
669 }
670
671 ostream &RubyCodeGen::source_warning( const InputLoc &loc )
672 {
673         cerr << sourceFileName << ":" << loc.line << ":" << loc.col << ": warning: ";
674         return cerr;
675 }
676
677 ostream &RubyCodeGen::source_error( const InputLoc &loc )
678 {
679         gblErrorCount += 1;
680         assert( sourceFileName != 0 );
681         cerr << sourceFileName << ":" << loc.line << ":" << loc.col << ": ";
682         return cerr;
683 }
684
685 void RubyCodeGen::finishRagelDef()
686 {
687         if ( codeStyle == GenGoto || codeStyle == GenFGoto || 
688                         codeStyle == GenIpGoto || codeStyle == GenSplit )
689         {
690                 /* For directly executable machines there is no required state
691                  * ordering. Choose a depth-first ordering to increase the
692                  * potential for fall-throughs. */
693                 redFsm->depthFirstOrdering();
694         }
695         else {
696                 /* The frontend will do this for us, but it may be a good idea to
697                  * force it if the intermediate file is edited. */
698                 redFsm->sortByStateId();
699         }
700
701         /* Choose default transitions and the single transition. */
702         redFsm->chooseDefaultSpan();
703                 
704         /* Maybe do flat expand, otherwise choose single. */
705         if ( codeStyle == GenFlat || codeStyle == GenFFlat )
706                 redFsm->makeFlat();
707         else
708                 redFsm->chooseSingle();
709
710         /* If any errors have occured in the input file then don't write anything. */
711         if ( gblErrorCount > 0 )
712                 return;
713         
714         if ( codeStyle == GenSplit )
715                 redFsm->partitionFsm( numSplitPartitions );
716
717         if ( codeStyle == GenIpGoto || codeStyle == GenSplit )
718                 redFsm->setInTrans();
719
720         /* Anlayze Machine will find the final action reference counts, among
721          * other things. We will use these in reporting the usage
722          * of fsm directives in action code. */
723         analyzeMachine();
724
725         /* Determine if we should use indicies. */
726         calcIndexSize();
727 }
728
729
730 /* Determine if we should use indicies or not. */
731 void RubyCodeGen::calcIndexSize()
732 {
733         int sizeWithInds = 0, sizeWithoutInds = 0;
734
735         /* Calculate cost of using with indicies. */
736         for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
737                 int totalIndex = st->outSingle.length() + st->outRange.length() + 
738                                 (st->defTrans == 0 ? 0 : 1);
739                 sizeWithInds += arrayTypeSize(redFsm->maxIndex) * totalIndex;
740         }
741         sizeWithInds += arrayTypeSize(redFsm->maxState) * redFsm->transSet.length();
742         if ( redFsm->anyActions() )
743                 sizeWithInds += arrayTypeSize(redFsm->maxActionLoc) * redFsm->transSet.length();
744
745         /* Calculate the cost of not using indicies. */
746         for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
747                 int totalIndex = st->outSingle.length() + st->outRange.length() + 
748                                 (st->defTrans == 0 ? 0 : 1);
749                 sizeWithoutInds += arrayTypeSize(redFsm->maxState) * totalIndex;
750                 if ( redFsm->anyActions() )
751                         sizeWithoutInds += arrayTypeSize(redFsm->maxActionLoc) * totalIndex;
752         }
753
754         /* If using indicies reduces the size, use them. */
755         useIndicies = sizeWithInds < sizeWithoutInds;
756 }
757
758 unsigned int RubyCodeGen::arrayTypeSize( unsigned long maxVal )
759 {
760         long long maxValLL = (long long) maxVal;
761         HostType *arrayType = keyOps->typeSubsumes( maxValLL );
762         assert( arrayType != 0 );
763         return arrayType->size;
764 }
765
766
767 void RubyCodeGen::writeInit()
768 {
769         out << "begin\n";
770         
771         out << "        " << P() << " ||= 0\n";
772
773         if ( !noEnd ) 
774                 out << "        " << PE() << " ||= " << DATA() << ".length\n";
775
776         if ( !noCS )
777                 out << "        " << vCS() << " = " << START() << "\n";
778
779         /* If there are any calls, then the stack top needs initialization. */
780         if ( redFsm->anyActionCalls() || redFsm->anyActionRets() )
781                 out << "        " << TOP() << " = 0\n";
782
783         if ( hasLongestMatch ) {
784                 out <<
785                         "       " << TOKSTART() << " = " << NULL_ITEM() << "\n"
786                         "       " << TOKEND() << " = " << NULL_ITEM() << "\n"
787                         "       " << ACT() << " = 0\n";
788         }
789
790         out << "end\n";
791 }
792
793 void RubyCodeGen::writeExports()
794 {
795         if ( exportList.length() > 0 ) {
796                 for ( ExportList::Iter ex = exportList; ex.lte(); ex++ ) {
797                         STATIC_VAR( ALPH_TYPE(), DATA_PREFIX() + "ex_" + ex->name ) 
798                                         << " = " << KEY(ex->key) << "\n";
799                 }
800                 out << "\n";
801         }
802 }
803
804 void RubyCodeGen::writeStart()
805 {
806         out << START_STATE_ID();
807 }
808
809 void RubyCodeGen::writeFirstFinal()
810 {
811         out << FIRST_FINAL_STATE();
812 }
813
814 void RubyCodeGen::writeError()
815 {
816         out << ERROR_STATE();
817 }
818
819
820 /*
821  * Local Variables:
822  * mode: c++
823  * indent-tabs-mode: 1
824  * c-file-style: "bsd"
825  * End:
826  */