2 * Copyright 2001-2007 Adrian Thurston <thurston@cs.queensu.ca>
5 /* This file is part of Ragel.
7 * Ragel is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * Ragel is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Ragel; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 Key readKey( char *td, char **end );
36 long readOffsetPtr( char *td, char **end );
37 unsigned long readLength( char *td );
43 include "xmlparse.kh";
48 /* If we get no input the assumption is that the frontend died and
49 * emitted an error. This forces the backend to return a non-zero
50 * exit status, but does not print an error. */
54 tag_ragel: tag_ragel_head ragel_def_list host_or_write_list '/' TAG_ragel;
56 tag_ragel_head: TAG_ragel
58 /* Check version used to generated the intermediate file. */
59 Attribute *versionAttr = $1->tag->findAttr( "version" );
60 if ( versionAttr == 0 )
61 error($1->loc) << "tag <ragel> requires a version attribute" << endp;
62 if ( strcmp( versionAttr->value, VERSION ) != 0 )
63 error($1->loc) << "version mismatch between frontend and backend" << endp;
65 /* Check for file name attribute. */
66 Attribute *fileNameAttr = $1->tag->findAttr( "filename" );
67 if ( fileNameAttr == 0 )
68 error($1->loc) << "tag <ragel> requires a filename attribute" << endp;
69 sourceFileName = fileNameAttr->value;
71 /* Check for language attribute. */
72 Attribute *langAttr = $1->tag->findAttr( "lang" );
74 error($1->loc) << "tag <ragel> requires a lang attribute" << endp;
76 if ( strcmp( langAttr->value, "C" ) == 0 )
77 hostLang = &hostLangC;
78 else if ( strcmp( langAttr->value, "D" ) == 0 )
79 hostLang = &hostLangD;
80 else if ( strcmp( langAttr->value, "Java" ) == 0 )
81 hostLang = &hostLangJava;
82 else if ( strcmp( langAttr->value, "Ruby" ) == 0 )
83 hostLang = &hostLangRuby;
85 error($1->loc) << "expecting lang attribute to be "
86 "one of C, D, Java or Ruby" << endp;
89 outStream = openOutput( sourceFileName );
92 ragel_def_list: ragel_def_list ragel_def;
95 host_or_write_list: host_or_write_list host_or_write;
98 host_or_write: tag_host;
99 host_or_write: tag_write;
102 TAG_host '/' TAG_host
104 Attribute *lineAttr = $1->tag->findAttr( "line" );
106 error($1->loc) << "tag <host> requires a line attribute" << endp;
108 int line = atoi( lineAttr->value );
110 lineDirective( *outStream, sourceFileName, line );
114 *outStream << $3->tag->content;
118 tag_ragel_def_head ragel_def_item_list '/' TAG_ragel_def
120 /* Do this before distributing transitions out to singles and defaults
121 * makes life easier. */
122 cgd->redFsm->maxKey = cgd->findMaxKey();
124 cgd->redFsm->assignActionLocs();
126 /* Find the first final state (The final state with the lowest id). */
127 cgd->redFsm->findFirstFinState();
129 /* Call the user's callback. */
130 cgd->finishRagelDef();
133 tag_ragel_def_head: TAG_ragel_def
136 Attribute *nameAttr = $1->tag->findAttr( "name" );
137 if ( nameAttr != 0 ) {
138 fsmName = nameAttr->value;
140 CodeGenMapEl *mapEl = codeGenMap.find( fsmName );
144 cgd = makeCodeGen( sourceFileName, fsmName, *outStream, wantComplete );
145 codeGenMap.insert( fsmName, cgd );
149 cgd = makeCodeGen( sourceFileName, fsmName,
150 *outStream, wantComplete );
153 ::keyOps = &cgd->thisKeyOps;
156 ragel_def_item_list: ragel_def_item_list ragel_def_item;
157 ragel_def_item_list: ;
159 ragel_def_item: tag_alph_type;
160 ragel_def_item: tag_getkey_expr;
161 ragel_def_item: tag_access_expr;
162 ragel_def_item: tag_export_list;
163 ragel_def_item: tag_machine;
164 ragel_def_item: tag_p_expr;
165 ragel_def_item: tag_pe_expr;
166 ragel_def_item: tag_cs_expr;
167 ragel_def_item: tag_top_expr;
168 ragel_def_item: tag_stack_expr;
169 ragel_def_item: tag_act_expr;
170 ragel_def_item: tag_tokstart_expr;
171 ragel_def_item: tag_tokend_expr;
173 tag_export_list: TAG_exports export_list '/' TAG_exports;
175 export_list: export_list tag_export;
178 tag_export: TAG_ex '/' TAG_ex
180 Attribute *nameAttr = $1->tag->findAttr( "name" );
182 error($1->loc) << "tag <ex> requires a name attribute" << endp;
184 char *td = $3->tag->content;
185 Key exportKey = readKey( td, &td );
186 cgd->exportList.append( new Export( nameAttr->value, exportKey ) );
190 tag_alph_type: TAG_alphtype '/' TAG_alphtype
192 if ( ! cgd->setAlphType( $3->tag->content ) )
193 error($1->loc) << "tag <alphtype> specifies unknown alphabet type" << endp;
196 tag_getkey_expr: TAG_getkey inline_list '/' TAG_getkey
198 cgd->getKeyExpr = $2->inlineList;
201 tag_access_expr: TAG_access inline_list '/' TAG_access
203 cgd->accessExpr = $2->inlineList;
206 tag_p_expr: TAG_p_expr inline_list '/' TAG_p_expr
207 final { cgd->pExpr = $2->inlineList; };
208 tag_pe_expr: TAG_pe_expr inline_list '/' TAG_pe_expr
209 final { cgd->peExpr = $2->inlineList; };
210 tag_cs_expr: TAG_cs_expr inline_list '/' TAG_cs_expr
211 final { cgd->csExpr = $2->inlineList; };
212 tag_top_expr: TAG_top_expr inline_list '/' TAG_top_expr
213 final { cgd->topExpr = $2->inlineList; };
214 tag_stack_expr: TAG_stack_expr inline_list '/' TAG_stack_expr
215 final { cgd->stackExpr = $2->inlineList; };
216 tag_act_expr: TAG_act_expr inline_list '/' TAG_act_expr
217 final { cgd->actExpr = $2->inlineList; };
218 tag_tokstart_expr: TAG_tokstart_expr inline_list '/' TAG_tokstart_expr
219 final { cgd->tokstartExpr = $2->inlineList; };
220 tag_tokend_expr: TAG_tokend_expr inline_list '/' TAG_tokend_expr
221 final { cgd->tokendExpr = $2->inlineList; };
224 tag_write: tag_write_head write_option_list '/' TAG_write
226 /* Terminate the options list and call the write statement handler. */
227 writeOptions.append(0);
228 cgd->writeStatement( $1->loc, writeOptions.length()-1, writeOptions.data );
230 /* Clear the options in prep for the next write statement. */
231 writeOptions.empty();
234 nonterm tag_write_head
239 tag_write_head: TAG_write
241 Attribute *nameAttr = $1->tag->findAttr( "def_name" );
242 Attribute *lineAttr = $1->tag->findAttr( "line" );
243 Attribute *colAttr = $1->tag->findAttr( "col" );
246 error($1->loc) << "tag <write> requires a def_name attribute" << endp;
248 error($1->loc) << "tag <write> requires a line attribute" << endp;
250 error($1->loc) << "tag <write> requires a col attribute" << endp;
252 if ( nameAttr != 0 && lineAttr != 0 && colAttr != 0 ) {
253 CodeGenMapEl *mapEl = codeGenMap.find( nameAttr->value );
255 error($1->loc) << "internal error: cannot find codeGen" << endp;
258 ::keyOps = &cgd->thisKeyOps;
261 $$->loc.line = atoi(lineAttr->value);
262 $$->loc.col = atoi(colAttr->value);
267 write_option_list: write_option_list tag_arg;
275 tag_arg: TAG_arg '/' TAG_arg
277 writeOptions.append( $3->tag->content );
280 tag_machine: tag_machine_head machine_item_list '/' TAG_machine
285 tag_machine_head: TAG_machine
287 cgd->createMachine();
290 machine_item_list: machine_item_list machine_item;
293 machine_item: tag_start_state;
294 machine_item: tag_error_state;
295 machine_item: tag_entry_points;
296 machine_item: tag_state_list;
297 machine_item: tag_action_list;
298 machine_item: tag_action_table_list;
299 machine_item: tag_cond_space_list;
305 tag_start_state: TAG_start_state '/' TAG_start_state
307 unsigned long startState = strtoul( $3->tag->content, 0, 10 );
308 cgd->setStartState( startState );
311 tag_error_state: TAG_error_state '/' TAG_error_state
313 unsigned long errorState = strtoul( $3->tag->content, 0, 10 );
314 cgd->setErrorState( errorState );
317 tag_entry_points: TAG_entry_points entry_point_list '/' TAG_entry_points
319 Attribute *errorAttr = $1->tag->findAttr( "error" );
320 if ( errorAttr != 0 )
321 cgd->setForcedErrorState();
324 entry_point_list: entry_point_list tag_entry;
327 tag_entry: TAG_entry '/' TAG_entry
329 Attribute *nameAttr = $1->tag->findAttr( "name" );
330 if ( nameAttr == 0 ) {
331 error($1->loc) << "tag <entry_points>::<entry> "
332 "requires a name attribute" << endp;
335 char *data = $3->tag->content;
336 unsigned long entry = strtoul( data, &data, 10 );
337 cgd->addEntryPoint( nameAttr->value, entry );
341 tag_state_list: tag_state_list_head state_list '/' TAG_state_list;
343 tag_state_list_head: TAG_state_list
345 Attribute *lengthAttr = $1->tag->findAttr( "length" );
346 if ( lengthAttr == 0 )
347 error($1->loc) << "tag <state_list> requires a length attribute" << endp;
349 unsigned long length = strtoul( lengthAttr->value, 0, 10 );
350 cgd->initStateList( length );
355 state_list: state_list tag_state;
358 tag_state: TAG_state state_item_list '/' TAG_state
360 Attribute *idAttr = $1->tag->findAttr( "id" );
362 error($1->loc) << "tag <state> requires an id attribute" << endp;
364 int id = atoi( idAttr->value );
365 cgd->setId( curState, id );
368 Attribute *lengthAttr = $1->tag->findAttr( "final" );
369 if ( lengthAttr != 0 )
370 cgd->setFinal( curState );
374 state_item_list: state_item_list state_item;
377 state_item: tag_state_actions;
378 state_item: tag_state_cond_list;
379 state_item: tag_trans_list;
381 tag_state_actions: TAG_state_actions '/' TAG_state_actions
383 char *ad = $3->tag->content;
385 long toStateAction = readOffsetPtr( ad, &ad );
386 long fromStateAction = readOffsetPtr( ad, &ad );
387 long eofAction = readOffsetPtr( ad, &ad );
389 cgd->setStateActions( curState, toStateAction,
390 fromStateAction, eofAction );
393 tag_state_cond_list: tag_state_cond_list_head state_cond_list '/' TAG_cond_list;
395 tag_state_cond_list_head: TAG_cond_list
397 Attribute *lengthAttr = $1->tag->findAttr( "length" );
398 if ( lengthAttr == 0 )
399 error($1->loc) << "tag <cond_list> requires a length attribute" << endp;
401 ulong length = readLength( lengthAttr->value );
402 cgd->initStateCondList( curState, length );
407 state_cond_list: state_cond_list state_cond;
410 state_cond: TAG_c '/' TAG_c
412 char *td = $3->tag->content;
413 Key lowKey = readKey( td, &td );
414 Key highKey = readKey( td, &td );
415 long condId = readOffsetPtr( td, &td );
416 cgd->addStateCond( curState, lowKey, highKey, condId );
419 tag_trans_list: tag_trans_list_head trans_list '/' TAG_trans_list
421 cgd->finishTransList( curState );
424 tag_trans_list_head: TAG_trans_list
426 Attribute *lengthAttr = $1->tag->findAttr( "length" );
427 if ( lengthAttr == 0 )
428 error($1->loc) << "tag <trans_list> requires a length attribute" << endp;
430 unsigned long length = strtoul( lengthAttr->value, 0, 10 );
431 cgd->initTransList( curState, length );
436 trans_list: trans_list tag_trans;
439 tag_trans: TAG_t '/' TAG_t
441 char *td = $3->tag->content;
442 Key lowKey = readKey( td, &td );
443 Key highKey = readKey( td, &td );
444 long targ = readOffsetPtr( td, &td );
445 long action = readOffsetPtr( td, &td );
447 cgd->newTrans( curState, curTrans++, lowKey, highKey, targ, action );
454 tag_action_list: tag_action_list_head action_list '/' TAG_action_list;
456 tag_action_list_head: TAG_action_list
458 Attribute *lengthAttr = $1->tag->findAttr( "length" );
459 if ( lengthAttr == 0 )
460 error($1->loc) << "tag <action_list> requires a length attribute" << endp;
462 unsigned long length = strtoul( lengthAttr->value, 0, 10 );
463 cgd->initActionList( length );
468 action_list: action_list tag_action;
475 tag_action: TAG_action inline_list '/' TAG_action
477 Attribute *lineAttr = $1->tag->findAttr( "line" );
478 Attribute *colAttr = $1->tag->findAttr( "col" );
479 Attribute *nameAttr = $1->tag->findAttr( "name" );
480 if ( lineAttr == 0 || colAttr == 0)
481 error($1->loc) << "tag <action> requires a line and col attributes" << endp;
483 unsigned long line = strtoul( lineAttr->value, 0, 10 );
484 unsigned long col = strtoul( colAttr->value, 0, 10 );
488 name = nameAttr->value;
490 cgd->newAction( curAction++, name, line, col, $2->inlineList );
496 InlineList *inlineList;
500 inline_list: inline_list inline_item
502 /* Append the item to the list, return the list. */
503 $1->inlineList->append( $2->inlineItem );
504 $$->inlineList = $1->inlineList;
509 /* Start with empty list. */
510 $$->inlineList = new InlineList;
513 nonterm inline_item_type
515 InlineItem *inlineItem;
518 nonterm inline_item uses inline_item_type;
520 inline_item: tag_text final { $$->inlineItem = $1->inlineItem; };
521 inline_item: tag_goto final { $$->inlineItem = $1->inlineItem; };
522 inline_item: tag_call final { $$->inlineItem = $1->inlineItem; };
523 inline_item: tag_next final { $$->inlineItem = $1->inlineItem; };
524 inline_item: tag_goto_expr final { $$->inlineItem = $1->inlineItem; };
525 inline_item: tag_call_expr final { $$->inlineItem = $1->inlineItem; };
526 inline_item: tag_next_expr final { $$->inlineItem = $1->inlineItem; };
527 inline_item: tag_ret final { $$->inlineItem = $1->inlineItem; };
528 inline_item: tag_break final { $$->inlineItem = $1->inlineItem; };
529 inline_item: tag_pchar final { $$->inlineItem = $1->inlineItem; };
530 inline_item: tag_char final { $$->inlineItem = $1->inlineItem; };
531 inline_item: tag_hold final { $$->inlineItem = $1->inlineItem; };
532 inline_item: tag_exec final { $$->inlineItem = $1->inlineItem; };
533 inline_item: tag_curs final { $$->inlineItem = $1->inlineItem; };
534 inline_item: tag_targs final { $$->inlineItem = $1->inlineItem; };
535 inline_item: tag_il_entry final { $$->inlineItem = $1->inlineItem; };
536 inline_item: tag_init_tokstart final { $$->inlineItem = $1->inlineItem; };
537 inline_item: tag_init_act final { $$->inlineItem = $1->inlineItem; };
538 inline_item: tag_get_tokend final { $$->inlineItem = $1->inlineItem; };
539 inline_item: tag_set_tokstart final { $$->inlineItem = $1->inlineItem; };
540 inline_item: tag_set_tokend final { $$->inlineItem = $1->inlineItem; };
541 inline_item: tag_set_act final { $$->inlineItem = $1->inlineItem; };
542 inline_item: tag_sub_action final { $$->inlineItem = $1->inlineItem; };
543 inline_item: tag_lm_switch final { $$->inlineItem = $1->inlineItem; };
545 nonterm tag_text uses inline_item_type;
546 nonterm tag_goto uses inline_item_type;
547 nonterm tag_call uses inline_item_type;
548 nonterm tag_next uses inline_item_type;
549 nonterm tag_goto_expr uses inline_item_type;
550 nonterm tag_call_expr uses inline_item_type;
551 nonterm tag_next_expr uses inline_item_type;
552 nonterm tag_ret uses inline_item_type;
553 nonterm tag_break uses inline_item_type;
554 nonterm tag_pchar uses inline_item_type;
555 nonterm tag_char uses inline_item_type;
556 nonterm tag_hold uses inline_item_type;
557 nonterm tag_exec uses inline_item_type;
558 nonterm tag_curs uses inline_item_type;
559 nonterm tag_targs uses inline_item_type;
560 nonterm tag_il_entry uses inline_item_type;
561 nonterm tag_init_tokstart uses inline_item_type;
562 nonterm tag_init_act uses inline_item_type;
563 nonterm tag_get_tokend uses inline_item_type;
564 nonterm tag_set_tokstart uses inline_item_type;
565 nonterm tag_set_tokend uses inline_item_type;
566 nonterm tag_set_act uses inline_item_type;
567 nonterm tag_sub_action uses inline_item_type;
568 nonterm tag_lm_switch uses inline_item_type;
570 tag_text: TAG_text '/' TAG_text
572 $$->inlineItem = new InlineItem( InputLoc(), InlineItem::Text );
573 $$->inlineItem->data = $3->tag->content;
576 tag_goto: TAG_goto '/' TAG_goto
578 int targ = strtol( $3->tag->content, 0, 10 );
579 $$->inlineItem = new InlineItem( InputLoc(), InlineItem::Goto );
580 $$->inlineItem->targId = targ;
583 tag_call: TAG_call '/' TAG_call
585 int targ = strtol( $3->tag->content, 0, 10 );
586 $$->inlineItem = new InlineItem( InputLoc(), InlineItem::Call );
587 $$->inlineItem->targId = targ;
590 tag_next: TAG_next '/' TAG_next
592 int targ = strtol( $3->tag->content, 0, 10 );
593 $$->inlineItem = new InlineItem( InputLoc(), InlineItem::Next );
594 $$->inlineItem->targId = targ;
597 tag_goto_expr: TAG_goto_expr inline_list '/' TAG_goto_expr
599 $$->inlineItem = new InlineItem( InputLoc(), InlineItem::GotoExpr );
600 $$->inlineItem->children = $2->inlineList;
603 tag_call_expr: TAG_call_expr inline_list '/' TAG_call_expr
605 $$->inlineItem = new InlineItem( InputLoc(), InlineItem::CallExpr );
606 $$->inlineItem->children = $2->inlineList;
609 tag_next_expr: TAG_next_expr inline_list '/' TAG_next_expr
611 $$->inlineItem = new InlineItem( InputLoc(), InlineItem::NextExpr );
612 $$->inlineItem->children = $2->inlineList;
615 tag_ret: TAG_ret '/' TAG_ret
617 $$->inlineItem = new InlineItem( InputLoc(), InlineItem::Ret );
620 tag_break: TAG_break '/' TAG_break
622 $$->inlineItem = new InlineItem( InputLoc(), InlineItem::Break );
625 tag_pchar: TAG_pchar '/' TAG_pchar
627 $$->inlineItem = new InlineItem( InputLoc(), InlineItem::PChar );
630 tag_char: TAG_char '/' TAG_char
632 $$->inlineItem = new InlineItem( InputLoc(), InlineItem::Char );
635 tag_hold: TAG_hold '/' TAG_hold
637 $$->inlineItem = new InlineItem( InputLoc(), InlineItem::Hold );
640 tag_exec: TAG_exec inline_list '/' TAG_exec
642 $$->inlineItem = new InlineItem( InputLoc(), InlineItem::Exec );
643 $$->inlineItem->children = $2->inlineList;
646 tag_curs: TAG_curs '/' TAG_curs
648 $$->inlineItem = new InlineItem( InputLoc(), InlineItem::Curs );
651 tag_targs: TAG_targs '/' TAG_targs
653 $$->inlineItem = new InlineItem( InputLoc(), InlineItem::Targs );
656 tag_il_entry: TAG_entry '/' TAG_entry
658 int targ = strtol( $3->tag->content, 0, 10 );
659 $$->inlineItem = new InlineItem( InputLoc(), InlineItem::Entry );
660 $$->inlineItem->targId = targ;
663 tag_init_tokstart: TAG_init_tokstart '/' TAG_init_tokstart
665 $$->inlineItem = new InlineItem( InputLoc(), InlineItem::LmInitTokStart );
668 tag_init_act: TAG_init_act '/' TAG_init_act
670 $$->inlineItem = new InlineItem( InputLoc(), InlineItem::LmInitAct );
673 tag_get_tokend: TAG_get_tokend '/' TAG_get_tokend
675 $$->inlineItem = new InlineItem( InputLoc(), InlineItem::LmGetTokEnd );
678 tag_set_tokstart: TAG_set_tokstart '/' TAG_set_tokstart
680 $$->inlineItem = new InlineItem( InputLoc(), InlineItem::LmSetTokStart );
681 cgd->hasLongestMatch = true;
684 tag_set_tokend: TAG_set_tokend '/' TAG_set_tokend
686 $$->inlineItem = new InlineItem( InputLoc(), InlineItem::LmSetTokEnd );
687 $$->inlineItem->offset = strtol( $3->tag->content, 0, 10 );
690 tag_set_act: TAG_set_act '/' TAG_set_act
692 $$->inlineItem = new InlineItem( InputLoc(), InlineItem::LmSetActId );
693 $$->inlineItem->lmId = strtol( $3->tag->content, 0, 10 );
696 tag_sub_action: TAG_sub_action inline_list '/' TAG_sub_action
698 $$->inlineItem = new InlineItem( InputLoc(), InlineItem::SubAction );
699 $$->inlineItem->children = $2->inlineList;
703 tag_lm_switch: TAG_lm_switch lm_action_list '/' TAG_lm_switch
705 $$->inlineItem = new InlineItem( InputLoc(), InlineItem::LmSwitch );
706 $$->inlineItem->children = $2->inlineList;
709 nonterm lm_action_list
711 InlineList *inlineList;
714 lm_action_list: lm_action_list tag_inline_action
716 $$->inlineList = $1->inlineList;
717 $$->inlineList->append( $2->inlineItem );
721 $$->inlineList = new InlineList;
724 nonterm tag_inline_action uses inline_item_type;
726 tag_inline_action: TAG_sub_action inline_list '/' TAG_sub_action
728 $$->inlineItem = new InlineItem( InputLoc(), InlineItem::SubAction );
729 $$->inlineItem->children = $2->inlineList;
731 Attribute *idAttr = $1->tag->findAttr( "id" );
733 unsigned long id = strtoul( idAttr->value, 0, 10 );
734 $$->inlineItem->lmId = id;
742 tag_action_table_list:
743 tag_action_table_list_head action_table_list '/' TAG_action_table_list;
745 tag_action_table_list_head: TAG_action_table_list
747 Attribute *lengthAttr = $1->tag->findAttr( "length" );
748 if ( lengthAttr == 0 ) {
749 error($1->loc) << "tag <action_table_list> requires "
750 "a length attribute" << endp;
753 unsigned long length = strtoul( lengthAttr->value, 0, 10 );
754 cgd->initActionTableList( length );
759 action_table_list: action_table_list tag_action_table;
762 tag_action_table: TAG_action_table '/' TAG_action_table
764 /* Find the length of the action table. */
765 Attribute *lengthAttr = $1->tag->findAttr( "length" );
766 if ( lengthAttr == 0 )
767 error($1->loc) << "tag <at> requires a length attribute" << endp;
769 unsigned long length = strtoul( lengthAttr->value, 0, 10 );
771 /* Collect the action table. */
772 RedAction *redAct = cgd->allActionTables + curActionTable;
773 redAct->actListId = curActionTable;
774 redAct->key.setAsNew( length );
775 char *ptr = $3->tag->content;
777 while ( *ptr != 0 ) {
778 unsigned long actionId = strtoul( ptr, &ptr, 10 );
779 redAct->key[pos].key = 0;
780 redAct->key[pos].value = cgd->allActions+actionId;
784 /* Insert into the action table map. */
785 cgd->redFsm->actionMap.insert( redAct );
795 tag_cond_space_list: tag_cond_space_list_head cond_space_list '/' TAG_cond_space_list;
797 tag_cond_space_list_head: TAG_cond_space_list
799 Attribute *lengthAttr = $1->tag->findAttr( "length" );
800 if ( lengthAttr == 0 ) {
801 error($1->loc) << "tag <cond_space_list> "
802 "requires a length attribute" << endp;
805 ulong length = readLength( lengthAttr->value );
806 cgd->initCondSpaceList( length );
811 cond_space_list: cond_space_list tag_cond_space;
812 cond_space_list: tag_cond_space;
814 tag_cond_space: TAG_cond_space '/' TAG_cond_space
816 Attribute *lengthAttr = $1->tag->findAttr( "length" );
817 Attribute *idAttr = $1->tag->findAttr( "id" );
818 if ( lengthAttr == 0 )
819 error($1->loc) << "tag <cond_space> requires a length attribute" << endp;
821 if ( lengthAttr == 0 )
822 error($1->loc) << "tag <cond_space> requires an id attribute" << endp;
824 unsigned long condSpaceId = strtoul( idAttr->value, 0, 10 );
825 ulong length = readLength( lengthAttr->value );
827 char *td = $3->tag->content;
828 Key baseKey = readKey( td, &td );
830 cgd->newCondSpace( curCondSpace, condSpaceId, baseKey );
831 for ( ulong a = 0; a < length; a++ ) {
832 long actionOffset = readOffsetPtr( td, &td );
833 cgd->condSpaceItem( curCondSpace, actionOffset );
852 int Parser::parseLangEl( int type, const Token *token )
855 return errCount == 0 ? 0 : -1;
859 unsigned long readLength( char *td )
861 return strtoul( td, 0, 10 );
864 Key readKey( char *td, char **end )
866 if ( keyOps->isSigned )
867 return Key( strtol( td, end, 10 ) );
869 return Key( strtoul( td, end, 10 ) );
872 long readOffsetPtr( char *td, char **end )
874 while ( *td == ' ' || *td == '\t' )
883 return strtol( td, end, 10 );
886 ostream &Parser::warning( const InputLoc &loc )
888 cerr << fileName << ":" << loc.line << ":" << loc.col << ": warning: ";
892 ostream &Parser::error( const InputLoc &loc )
895 assert( fileName != 0 );
896 cerr << fileName << ":" << loc.line << ":" << loc.col << ": ";
901 ostream &Parser::parser_error( int tokId, Token &token )
904 assert( fileName != 0 );
905 cerr << fileName << ":" << token.loc.line << ":" << token.loc.col;
906 if ( token.tag != 0 ) {
907 if ( token.tag->tagId == 0 )
908 cerr << ": at unknown tag";
910 cerr << ": at tag <" << token.tag->tagId->name << ">";
917 int Parser::token( int tokenId, Token &tok )
919 int res = parseLangEl( tokenId, &tok );
921 parser_error( tokenId, tok ) << "parse error" << endp;
925 int Parser::token( int tokenId, int col, int line )
931 return token( tokenId, tok );
934 int Parser::token( XMLTag *tag, int col, int line )
941 if ( tag->type == XMLTag::Close ) {
942 int res = token( '/', tok );
948 return token( tag->tagId != 0 ? tag->tagId->id : TAG_unknown, tok );