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