Added .deps to ignore.
[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, sourceFileName, 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         rubyLineDirective( ret, sourceFileName, action->loc.line );
281 }
282
283
284
285 string RubyCodeGen::GET_WIDE_KEY()
286 {
287         if ( redFsm->anyConditions() ) 
288                 return "_widec";
289         else
290                 return GET_KEY();
291 }
292
293 string RubyCodeGen::GET_WIDE_KEY( RedStateAp *state )
294 {
295         if ( state->stateCondList.length() > 0 )
296                 return "_widec";
297         else
298                 return GET_KEY();
299 }
300
301 string RubyCodeGen::GET_KEY()
302 {
303         ostringstream ret;
304         if ( getKeyExpr != 0 ) { 
305                 /* Emit the user supplied method of retrieving the key. */
306                 ret << "(";
307                 INLINE_LIST( ret, getKeyExpr, 0, false );
308                 ret << ")";
309         }
310         else {
311                 /* Expression for retrieving the key, use simple dereference. */
312                 ret << DATA() << "[" << P() << "]";
313         }
314         return ret.str();
315 }
316
317 string RubyCodeGen::KEY( Key key )
318 {
319         ostringstream ret;
320         if ( keyOps->isSigned || !hostLang->explicitUnsigned )
321                 ret << key.getVal();
322         else
323                 ret << (unsigned long) key.getVal();
324         return ret.str();
325 }
326
327
328 /* Write out level number of tabs. Makes the nested binary search nice
329  * looking. */
330 string RubyCodeGen::TABS( int level )
331 {
332         string result;
333         while ( level-- > 0 )
334                 result += "\t";
335         return result;
336 }
337
338 string RubyCodeGen::INT( int i )
339 {
340         ostringstream ret;
341         ret << i;
342         return ret.str();
343 }
344
345 void RubyCodeGen::CONDITION( ostream &ret, GenAction *condition )
346 {
347         ret << "\n";
348         rubyLineDirective( ret, sourceFileName, condition->loc.line );
349         INLINE_LIST( ret, condition->inlineList, 0, false );
350 }
351
352 /* Emit the alphabet data type. */
353 string RubyCodeGen::ALPH_TYPE()
354 {
355         string ret = keyOps->alphType->data1;
356         if ( keyOps->alphType->data2 != 0 ) {
357                 ret += " ";
358                 ret += + keyOps->alphType->data2;
359         }
360         return ret;
361 }
362
363 /* Emit the alphabet data type. */
364 string RubyCodeGen::WIDE_ALPH_TYPE()
365 {
366         string ret;
367         if ( redFsm->maxKey <= keyOps->maxKey )
368                 ret = ALPH_TYPE();
369         else {
370                 long long maxKeyVal = redFsm->maxKey.getLongLong();
371                 HostType *wideType = keyOps->typeSubsumes( keyOps->isSigned, maxKeyVal );
372                 assert( wideType != 0 );
373
374                 ret = wideType->data1;
375                 if ( wideType->data2 != 0 ) {
376                         ret += " ";
377                         ret += wideType->data2;
378                 }
379         }
380         return ret;
381 }
382
383
384 string RubyCodeGen::ARRAY_TYPE( unsigned long maxVal )
385 {
386         long long maxValLL = (long long) maxVal;
387         HostType *arrayType = keyOps->typeSubsumes( maxValLL );
388         assert( arrayType != 0 );
389
390         string ret = arrayType->data1;
391         if ( arrayType->data2 != 0 ) {
392                 ret += " ";
393                 ret += arrayType->data2;
394         }
395         return ret;
396 }
397
398 /* Write out the array of actions. */
399 std::ostream &RubyCodeGen::ACTIONS_ARRAY()
400 {
401         START_ARRAY_LINE();
402         int totalActions = 0;
403         ARRAY_ITEM( INT(0), ++totalActions, false );
404         for ( GenActionTableMap::Iter act = redFsm->actionMap; act.lte(); act++ ) {
405                 /* Write out the length, which will never be the last character. */
406                 ARRAY_ITEM( INT(act->key.length()), ++totalActions, false );
407
408                 for ( GenActionTable::Iter item = act->key; item.lte(); item++ ) {
409                         ARRAY_ITEM( INT(item->value->actionId), ++totalActions, (act.last() && item.last()) );
410                 }
411         }
412         END_ARRAY_LINE();
413         return out;
414 }
415
416 void RubyCodeGen::STATE_IDS()
417 {
418         if ( redFsm->startState != 0 )
419                 STATIC_VAR( "int", START() ) << " = " << START_STATE_ID() << ";\n";
420
421         if ( !noFinal )
422                 STATIC_VAR( "int" , FIRST_FINAL() ) << " = " << FIRST_FINAL_STATE() << ";\n";
423
424         if ( !noError )
425                 STATIC_VAR( "int", ERROR() ) << " = " << ERROR_STATE() << ";\n";
426
427         out << "\n";
428
429         if ( entryPointNames.length() > 0 ) {
430                 for ( EntryNameVect::Iter en = entryPointNames; en.lte(); en++ ) {
431                         STATIC_VAR( "int", DATA_PREFIX() + "en_" + *en ) << 
432                                         " = " << entryPointIds[en.pos()] << ";\n";
433                 }
434                 out << "\n";
435         }
436 }
437
438 std::ostream &RubyCodeGen::START_ARRAY_LINE()
439 {
440         out << "\t";
441         return out;
442 }
443
444 std::ostream &RubyCodeGen::ARRAY_ITEM( string item, int count, bool last )
445 {
446         out << item;
447         if ( !last )
448         {
449                 out << ", ";
450                 if ( count % IALL == 0 )
451                 {
452                         END_ARRAY_LINE();
453                         START_ARRAY_LINE();
454                 }
455         }
456         return out;
457 }
458
459 std::ostream &RubyCodeGen::END_ARRAY_LINE()
460 {
461         out << "\n";
462         return out;
463 }
464
465 /* Emit the offset of the start state as a decimal integer. */
466 string RubyCodeGen::START_STATE_ID()
467 {
468         ostringstream ret;
469         ret << redFsm->startState->id;
470         return ret.str();
471 };
472
473 string RubyCodeGen::ERROR_STATE()
474 {
475         ostringstream ret;
476         if ( redFsm->errState != 0 )
477                 ret << redFsm->errState->id;
478         else
479                 ret << "-1";
480         return ret.str();
481 }
482
483 string RubyCodeGen::FIRST_FINAL_STATE()
484 {
485         ostringstream ret;
486         if ( redFsm->firstFinState != 0 )
487                 ret << redFsm->firstFinState->id;
488         else
489                 ret << redFsm->nextStateId;
490         return ret.str();
491 }
492
493 string RubyCodeGen::ACCESS()
494 {
495         ostringstream ret;
496         if ( accessExpr != 0 )
497                 INLINE_LIST( ret, accessExpr, 0, false );
498         return ret.str();
499 }
500
501 /* Write out an inline tree structure. Walks the list and possibly calls out
502  * to virtual functions than handle language specific items in the tree. */
503 void RubyCodeGen::INLINE_LIST( ostream &ret, GenInlineList *inlineList, 
504                 int targState, bool inFinish )
505 {
506         for ( GenInlineList::Iter item = *inlineList; item.lte(); item++ ) {
507                 switch ( item->type ) {
508                 case GenInlineItem::Text:
509                         ret << item->data;
510                         break;
511                 case GenInlineItem::Goto:
512                         GOTO( ret, item->targState->id, inFinish );
513                         break;
514                 case GenInlineItem::Call:
515                         CALL( ret, item->targState->id, targState, inFinish );
516                         break;
517                 case GenInlineItem::Next:
518                         NEXT( ret, item->targState->id, inFinish );
519                         break;
520                 case GenInlineItem::Ret:
521                         RET( ret, inFinish );
522                         break;
523                 case GenInlineItem::PChar:
524                         ret << P();
525                         break;
526                 case GenInlineItem::Char:
527                         ret << GET_KEY();
528                         break;
529                 case GenInlineItem::Hold:
530                         ret << P() << " = " << P() << " - 1;";
531                         break;
532                 case GenInlineItem::Exec:
533                         EXEC( ret, item, targState, inFinish );
534                         break;
535                 case GenInlineItem::Curs:
536                         ret << "(_ps)";
537                         break;
538                 case GenInlineItem::Targs:
539                         ret << "(" << vCS() << ")";
540                         break;
541                 case GenInlineItem::Entry:
542                         ret << item->targState->id;
543                         break;
544                 case GenInlineItem::GotoExpr:
545                         GOTO_EXPR( ret, item, inFinish );
546                         break;
547                 case GenInlineItem::CallExpr:
548                         CALL_EXPR( ret, item, targState, inFinish );
549                         break;
550                 case GenInlineItem::NextExpr:
551                         NEXT_EXPR( ret, item, inFinish );
552                         break;
553                 case GenInlineItem::LmSwitch:
554                         LM_SWITCH( ret, item, targState, inFinish );
555                         break;
556                 case GenInlineItem::LmSetActId:
557                         SET_ACT( ret, item );
558                         break;
559                 case GenInlineItem::LmSetTokEnd:
560                         SET_TOKEND( ret, item );
561                         break;
562                 case GenInlineItem::LmGetTokEnd:
563                         GET_TOKEND( ret, item );
564                         break;
565                 case GenInlineItem::LmInitTokStart:
566                         INIT_TOKSTART( ret, item );
567                         break;
568                 case GenInlineItem::LmInitAct:
569                         INIT_ACT( ret, item );
570                         break;
571                 case GenInlineItem::LmSetTokStart:
572                         SET_TOKSTART( ret, item );
573                         break;
574                 case GenInlineItem::SubAction:
575                         SUB_ACTION( ret, item, targState, inFinish );
576                         break;
577                 case GenInlineItem::Break:
578                         BREAK( ret, targState );
579                         break;
580                 }
581         }
582 }
583
584
585 void RubyCodeGen::EXEC( ostream &ret, GenInlineItem *item, int targState, int inFinish )
586 {
587         /* The parser gives fexec two children. The double brackets are for D
588          * code. If the inline list is a single word it will get interpreted as a
589          * C-style cast by the D compiler. */
590         ret << " begin " << P() << " = ((";
591         INLINE_LIST( ret, item->children, targState, inFinish );
592         ret << "))-1; end\n";
593 }
594
595 void RubyCodeGen::LM_SWITCH( ostream &ret, GenInlineItem *item, 
596                 int targState, int inFinish )
597 {
598         ret << 
599                 "       case " << ACT() << "\n";
600
601         for ( GenInlineList::Iter lma = *item->children; lma.lte(); lma++ ) {
602                 /* Write the case label, the action and the case break. */
603                 if ( lma->lmId < 0 )
604                         ret << "        else\n";
605                 else
606                         ret << "        when " << lma->lmId << " then\n";
607
608
609                 /* Write the block and close it off. */
610                 ret << "        begin";
611                 INLINE_LIST( ret, lma->children, targState, inFinish );
612                 ret << "end\n";
613         }
614
615         ret << "end \n\t";
616 }
617
618 void RubyCodeGen::SET_ACT( ostream &ret, GenInlineItem *item )
619 {
620         ret << ACT() << " = " << item->lmId << ";";
621 }
622
623 void RubyCodeGen::INIT_TOKSTART( ostream &ret, GenInlineItem *item )
624 {
625         ret << TOKSTART() << " = " << NULL_ITEM() << ";";
626 }
627
628 void RubyCodeGen::INIT_ACT( ostream &ret, GenInlineItem *item )
629 {
630         ret << ACT() << " = 0\n";
631 }
632
633 void RubyCodeGen::SET_TOKSTART( ostream &ret, GenInlineItem *item )
634 {
635         ret << TOKSTART() << " = " << P() << "\n";
636 }
637
638 void RubyCodeGen::SET_TOKEND( ostream &ret, GenInlineItem *item )
639 {
640         /* The tokend action sets tokend. */
641         ret << TOKEND() << " = " << P();
642         if ( item->offset != 0 ) 
643                 out << "+" << item->offset;
644         out << "\n";
645 }
646
647 void RubyCodeGen::GET_TOKEND( ostream &ret, GenInlineItem *item )
648 {
649         ret << TOKEND();
650 }
651
652 void RubyCodeGen::SUB_ACTION( ostream &ret, GenInlineItem *item, 
653                 int targState, bool inFinish )
654 {
655         if ( item->children->length() > 0 ) {
656                 /* Write the block and close it off. */
657                 ret << " begin ";
658                 INLINE_LIST( ret, item->children, targState, inFinish );
659                 ret << " end\n";
660         }
661 }
662
663 int RubyCodeGen::TRANS_ACTION( RedTransAp *trans )
664 {
665         /* If there are actions, emit them. Otherwise emit zero. */
666         int act = 0;
667         if ( trans->action != 0 )
668                 act = trans->action->location+1;
669         return act;
670 }
671
672 ostream &RubyCodeGen::source_warning( const InputLoc &loc )
673 {
674         cerr << sourceFileName << ":" << loc.line << ":" << loc.col << ": warning: ";
675         return cerr;
676 }
677
678 ostream &RubyCodeGen::source_error( const InputLoc &loc )
679 {
680         gblErrorCount += 1;
681         assert( sourceFileName != 0 );
682         cerr << sourceFileName << ":" << loc.line << ":" << loc.col << ": ";
683         return cerr;
684 }
685
686 void RubyCodeGen::finishRagelDef()
687 {
688         if ( codeStyle == GenGoto || codeStyle == GenFGoto || 
689                         codeStyle == GenIpGoto || codeStyle == GenSplit )
690         {
691                 /* For directly executable machines there is no required state
692                  * ordering. Choose a depth-first ordering to increase the
693                  * potential for fall-throughs. */
694                 redFsm->depthFirstOrdering();
695         }
696         else {
697                 /* The frontend will do this for us, but it may be a good idea to
698                  * force it if the intermediate file is edited. */
699                 redFsm->sortByStateId();
700         }
701
702         /* Choose default transitions and the single transition. */
703         redFsm->chooseDefaultSpan();
704                 
705         /* Maybe do flat expand, otherwise choose single. */
706         if ( codeStyle == GenFlat || codeStyle == GenFFlat )
707                 redFsm->makeFlat();
708         else
709                 redFsm->chooseSingle();
710
711         /* If any errors have occured in the input file then don't write anything. */
712         if ( gblErrorCount > 0 )
713                 return;
714         
715         if ( codeStyle == GenSplit )
716                 redFsm->partitionFsm( numSplitPartitions );
717
718         if ( codeStyle == GenIpGoto || codeStyle == GenSplit )
719                 redFsm->setInTrans();
720
721         /* Anlayze Machine will find the final action reference counts, among
722          * other things. We will use these in reporting the usage
723          * of fsm directives in action code. */
724         analyzeMachine();
725
726         /* Determine if we should use indicies. */
727         calcIndexSize();
728 }
729
730
731 /* Determine if we should use indicies or not. */
732 void RubyCodeGen::calcIndexSize()
733 {
734         int sizeWithInds = 0, sizeWithoutInds = 0;
735
736         /* Calculate cost of using with indicies. */
737         for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
738                 int totalIndex = st->outSingle.length() + st->outRange.length() + 
739                                 (st->defTrans == 0 ? 0 : 1);
740                 sizeWithInds += arrayTypeSize(redFsm->maxIndex) * totalIndex;
741         }
742         sizeWithInds += arrayTypeSize(redFsm->maxState) * redFsm->transSet.length();
743         if ( redFsm->anyActions() )
744                 sizeWithInds += arrayTypeSize(redFsm->maxActionLoc) * redFsm->transSet.length();
745
746         /* Calculate the cost of not using indicies. */
747         for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
748                 int totalIndex = st->outSingle.length() + st->outRange.length() + 
749                                 (st->defTrans == 0 ? 0 : 1);
750                 sizeWithoutInds += arrayTypeSize(redFsm->maxState) * totalIndex;
751                 if ( redFsm->anyActions() )
752                         sizeWithoutInds += arrayTypeSize(redFsm->maxActionLoc) * totalIndex;
753         }
754
755         /* If using indicies reduces the size, use them. */
756         useIndicies = sizeWithInds < sizeWithoutInds;
757 }
758
759 unsigned int RubyCodeGen::arrayTypeSize( unsigned long maxVal )
760 {
761         long long maxValLL = (long long) maxVal;
762         HostType *arrayType = keyOps->typeSubsumes( maxValLL );
763         assert( arrayType != 0 );
764         return arrayType->size;
765 }
766
767
768 void RubyCodeGen::writeInit()
769 {
770         out << "begin\n";
771         
772         out << "        " << P() << " ||= 0\n";
773
774         if ( !noEnd ) 
775                 out << "        " << PE() << " ||= " << DATA() << ".length\n";
776
777         if ( !noCS )
778                 out << "        " << vCS() << " = " << START() << "\n";
779
780         /* If there are any calls, then the stack top needs initialization. */
781         if ( redFsm->anyActionCalls() || redFsm->anyActionRets() )
782                 out << "        " << TOP() << " = 0\n";
783
784         if ( hasLongestMatch ) {
785                 out <<
786                         "       " << TOKSTART() << " = " << NULL_ITEM() << "\n"
787                         "       " << TOKEND() << " = " << NULL_ITEM() << "\n"
788                         "       " << ACT() << " = 0\n";
789         }
790
791         out << "end\n";
792 }
793
794 void RubyCodeGen::writeExports()
795 {
796         if ( exportList.length() > 0 ) {
797                 for ( ExportList::Iter ex = exportList; ex.lte(); ex++ ) {
798                         STATIC_VAR( ALPH_TYPE(), DATA_PREFIX() + "ex_" + ex->name ) 
799                                         << " = " << KEY(ex->key) << "\n";
800                 }
801                 out << "\n";
802         }
803 }
804
805 void RubyCodeGen::writeStart()
806 {
807         out << START_STATE_ID();
808 }
809
810 void RubyCodeGen::writeFirstFinal()
811 {
812         out << FIRST_FINAL_STATE();
813 }
814
815 void RubyCodeGen::writeError()
816 {
817         out << ERROR_STATE();
818 }
819
820
821 /*
822  * Local Variables:
823  * mode: c++
824  * indent-tabs-mode: 1
825  * c-file-style: "bsd"
826  * End:
827  */