From 03718a6eb002e4a775c4dcbf361bb5332020783a Mon Sep 17 00:00:00 2001 From: thurston Date: Sat, 3 Feb 2007 21:48:19 +0000 Subject: [PATCH] Fixed error from last commit: The frontend should emit states with numbers starting at 0. The state numbers in the XML file are now read and used to set the state id. They are currently overwritten, but this should change when the frontend is able to decide if an error state is needed. git-svn-id: http://svn.complang.org/ragel/trunk@70 052ea7fc-9027-0410-9066-f65837a77df0 --- ragel/parsedata.cpp | 2 +- redfsm/gendata.cpp | 6 ++++++ redfsm/gendata.h | 1 + redfsm/xmlparse.kl | 8 ++++++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ragel/parsedata.cpp b/ragel/parsedata.cpp index 9d16c2f..2352bb8 100644 --- a/ragel/parsedata.cpp +++ b/ragel/parsedata.cpp @@ -1318,7 +1318,7 @@ void ParseData::prepareMachineGen( GraphDictEl *graphDictEl ) sectionGraph->depthFirstOrdering(); sectionGraph->sortStatesByFinal(); - sectionGraph->setStateNumbers( 1 ); + sectionGraph->setStateNumbers( 0 ); } void ParseData::generateXML( ostream &out ) diff --git a/redfsm/gendata.cpp b/redfsm/gendata.cpp index 7498d90..db5b8da 100644 --- a/redfsm/gendata.cpp +++ b/redfsm/gendata.cpp @@ -183,6 +183,12 @@ void CodeGenData::finishTransList( int snum ) } } +void CodeGenData::setId( int snum, int id ) +{ + RedStateAp *curState = allStates + snum; + curState->id = id; +} + void CodeGenData::setFinal( int snum ) { RedStateAp *curState = allStates + snum; diff --git a/redfsm/gendata.h b/redfsm/gendata.h index 6849977..ec22e15 100644 --- a/redfsm/gendata.h +++ b/redfsm/gendata.h @@ -84,6 +84,7 @@ struct CodeGenData void initStateList( unsigned long length ); void setStartState( unsigned long startState ); void addEntryPoint( char *name, unsigned long entryState ); + void setId( int snum, int id ); void setFinal( int snum ); void initTransList( int snum, unsigned long length ); void newTrans( int snum, int tnum, Key lowKey, Key highKey, diff --git a/redfsm/xmlparse.kl b/redfsm/xmlparse.kl index a25859b..78d895e 100644 --- a/redfsm/xmlparse.kl +++ b/redfsm/xmlparse.kl @@ -279,6 +279,14 @@ state_list: ; tag_state: TAG_state state_item_list '/' TAG_state final { + Attribute *idAttr = $1->tag->findAttr( "id" ); + if ( idAttr == 0 ) + error($1->loc) << "tag requires an id attribute" << endl; + else { + int id = atoi( idAttr->value ); + cgd->setId( curState, id ); + } + Attribute *lengthAttr = $1->tag->findAttr( "final" ); if ( lengthAttr != 0 ) cgd->setFinal( curState ); -- 2.7.4