#include <parser.h>
Collaboration diagram for Parser:
Public Methods | |
Parser (istream &is) | |
Constructor, parameter is input stream containing description. More... | |
ref< Fsm > | parse () |
Parse FSM description on is_ , return 0 if syntax error. More... | |
Private Methods | |
bool | parse_states (Fsm::STATES &) |
Parse a set of states. More... | |
bool | parse_syms (Fsm::SYMBOLS &) |
Parse a set of symbols. More... | |
bool | parse_transition (Fsm::STATES &, Fsm::SYMBOLS &, Fsm::STATES &) |
Parse a transition. More... | |
Private Attributes | |
nocommentstream | is_ |
Input stream of parser. More... |
Definition at line 11 of file parser.h.
|
Constructor, parameter is input stream containing description.
Definition at line 5 of file parser.C. 00005 : is_(is) { 00006 } |
|
Parse FSM description on
Definition at line 9 of file parser.C. 00009 { 00010 // Will return 0 if there is a syntax error. 00011 00012 // Parse initial state: just read the string. 00013 00014 Fsm::State initial_state; 00015 if (!(is_ >> initial_state)) 00016 return ref<Fsm>(); 00017 00018 ref<Fsm> fsm = Fsm::create(initial_state); 00019 00020 // Parse set of final states and add them to fsm. 00021 00022 Fsm::STATES final_states; 00023 if (parse_states(final_states)) 00024 for (Fsm::STATES::const_iterator i= final_states.begin(); 00025 i != final_states.end(); ++i) 00026 fsm->add_final_state(*i); 00027 else 00028 return ref<Fsm>(); 00029 00030 // Parse transitions until eof. 00031 00032 while (is_) { 00033 Fsm::STATES from; 00034 Fsm::STATES to; 00035 Fsm::SYMBOLS syms; 00036 00037 if (parse_transition(from,syms,to)) { 00038 // Insert all single transitions from the sets from, syms, to. 00039 for (Fsm::STATES::const_iterator i=from.begin(); i!=from.end(); ++i) 00040 for (Fsm::SYMBOLS::const_iterator j=syms.begin(); j!=syms.end(); ++j) 00041 for (Fsm::STATES::const_iterator k=to.begin(); k!=to.end(); ++k) 00042 fsm->add_transition(*i,*j,*k); 00043 } 00044 else 00045 return ref<Fsm>(); 00046 } 00047 return fsm; 00048 } |
|
Parse a set of states. Syntax is { state state .. } Definition at line 51 of file parser.C. Referenced by parse(), and parse_transition().
00051 { 00052 string s; 00053 if (is_ >> s) { 00054 if (s == "{") { 00055 while ( (is_ >> s) && ( s != "}" ) && ( s != "{" ) ) 00056 states.insert(s); 00057 if (s != "}" ) // syntax error: eof while reading states.. 00058 return false; 00059 else 00060 return true; 00061 } 00062 else 00063 if ( s != "}" ) { 00064 states.insert(s); 00065 return true; 00066 } 00067 else 00068 return false; 00069 } 00070 return true; 00071 } |
|
Parse a set of symbols. Syntax is { symbol symbol .. } Definition at line 74 of file parser.C. Referenced by parse_transition().
00074 { 00075 // Almost identical fo parse_states. 00076 string s; 00077 if (is_ >> s) { 00078 if (s == "{") { 00079 while ( (is_ >> s) && ( s != "}" ) && ( s != "{" ) ) 00080 syms.insert(s); 00081 if (s != "}" ) // syntax error: eof while reading syms.. 00082 return false; 00083 else 00084 return true; 00085 } 00086 else 00087 if ( s != "{") { 00088 syms.insert(s); 00089 return true; 00090 } 00091 else 00092 return false; 00093 } 00094 return true; 00095 } |
|
Parse a transition. Syntax is states symbols states Definition at line 98 of file parser.C. Referenced by parse().
00098 { 00099 return parse_states(from) && parse_syms(syms) && parse_states(to); 00100 } |
|
Input stream of parser.
|