CA initial state

This commit is contained in:
Artur Meski
2018-03-04 15:32:16 +00:00
parent 18004b916e
commit f55d433791
6 changed files with 36 additions and 3 deletions

View File

@@ -40,8 +40,22 @@ void CtxAut::addState(std::string name)
states_ids.push_back(name);
states_names[name] = new_state_id;
if (!init_state_defined)
{
setInitState(name);
}
}
}
void CtxAut::setInitState(std::string name)
{
VERB_L2("Setting initial CA state: " << name);
State state_id = getStateID(name);
VERB_L2("Got initial CA state ID: index=" << state_id);
init_state_id = state_id;
init_state_defined = true;
}
void CtxAut::printAutomaton(void)
{
@@ -52,6 +66,7 @@ void CtxAut::printAutomaton(void)
void CtxAut::showStates(void)
{
cout << "# Context Automaton States:" << endl;
cout << " = Init state: " << getStateName(init_state_id) << endl;
for (const auto &s : states_ids)
cout << " * " << s << endl;
}

View File

@@ -31,6 +31,7 @@ class CtxAut
CtxAut(Options *opts, RctSys *parent_rctsys);
bool hasState(std::string name);
void addState(std::string stateName);
void setInitState(std::string stateName);
State getStateID(std::string name);
std::string getStateName(State state_id);
void printAutomaton(void);
@@ -45,6 +46,8 @@ class CtxAut
Options *opts;
StatesById states_ids;
StatesByName states_names;
State init_state_id;
bool init_state_defined;
Entities tmpEntities;
Transitions transitions;
};

10
rs.cc
View File

@@ -190,15 +190,21 @@ void RctSys::ctxAutAddState(std::string stateName)
ctx_aut->addState(stateName);
}
void RctSys::ctxAutSetInitState(std::string stateName)
{
assert(ctx_aut != nullptr);
ctx_aut->setInitState(stateName);
}
void RctSys::ctxAutAddTransition(std::string srcStateName, std::string dstStateName)
{
assert(ctx_aut != nullptr);
ctx_aut->addTransition(srcStateName, dstStateName);
}
void RctSys::ctxAutPushNamedContextEntity(std::string entity_name)
void RctSys::ctxAutPushNamedContextEntity(std::string entityName)
{
assert(ctx_aut != nullptr);
Entity entity_id = getEntityID(entity_name);
Entity entity_id = getEntityID(entityName);
ctx_aut->pushContextEntity(entity_id);
}

1
rs.hh
View File

@@ -71,6 +71,7 @@ class RctSys
void ctxAutEnable(void);
void ctxAutAddState(std::string stateName);
void ctxAutSetInitState(std::string stateName);
void ctxAutAddTransition(std::string srcStateName, std::string dstStateName);
void ctxAutPushNamedContextEntity(std::string entity_name);

View File

@@ -47,6 +47,7 @@ blank [ \t]
"context-automaton" return token::CONTEXTAUTOMATON;
"transitions" return token::TRANSITIONS;
"states" return token::STATES;
"init-state" return token::INITSTATE;
"rsctl-property" return token::RSCTLFORM;
"{" return token::LCB;
"}" return token::RCB;

View File

@@ -46,7 +46,7 @@ class rsin_driver;
%token OPTIONS USE_CTX_AUT USE_CONCENTRATIONS
%token REACTIONS INITIALCONTEXTS CONTEXTENTITIES RSCTLFORM
%token CONTEXTAUTOMATON STATES TRANSITIONS
%token CONTEXTAUTOMATON STATES INITSTATE TRANSITIONS
%token LCB RCB LRB RRB LSB RSB LAB RAB COL SEMICOL COMMA RARR
%token AND OR XOR IMPLIES NOT
%token EX EU EF EG AX AU AF AG E A X U F G EMPTY
@@ -191,6 +191,7 @@ actentity: IDENTIFIER {
ctxaut:
| STATES LCB autstates RCB ctxaut
| INITSTATE LCB autinitstate RCB ctxaut
| TRANSITIONS LCB auttransitions RCB ctxaut
;
@@ -205,6 +206,12 @@ autstates:
| autstate COMMA autstates
;
autinitstate: IDENTIFIER {
driver.getReactionSystem()->ctxAutSetInitState(*$1);
free($1);
}
;
auttransitions:
| auttrans
| auttrans SEMICOL auttransitions