CA input (done); initial state missing
This commit is contained in:
24
ctx_aut.cc
24
ctx_aut.cc
@@ -1,6 +1,12 @@
|
||||
|
||||
#include "ctx_aut.hh"
|
||||
|
||||
CtxAut::CtxAut(Options *opts, RctSys *parent_rctsys)
|
||||
{
|
||||
setOptions(opts);
|
||||
this->parent_rctsys = parent_rctsys;
|
||||
}
|
||||
|
||||
bool CtxAut::hasState(std::string name)
|
||||
{
|
||||
if (states_names.find(name) == states_names.end())
|
||||
@@ -18,6 +24,12 @@ State CtxAut::getStateID(std::string name)
|
||||
return states_names[name];
|
||||
}
|
||||
|
||||
std::string CtxAut::getStateName(State state_id)
|
||||
{
|
||||
assert(state_id < states_ids.size());
|
||||
return states_ids[state_id];
|
||||
}
|
||||
|
||||
void CtxAut::addState(std::string name)
|
||||
{
|
||||
if (!hasState(name))
|
||||
@@ -34,6 +46,7 @@ void CtxAut::addState(std::string name)
|
||||
void CtxAut::printAutomaton(void)
|
||||
{
|
||||
showStates();
|
||||
showTransitions();
|
||||
}
|
||||
|
||||
void CtxAut::showStates(void)
|
||||
@@ -58,6 +71,17 @@ void CtxAut::addTransition(std::string srcStateName, std::string dstStateName)
|
||||
new_transition.ctx = tmpEntities;
|
||||
tmpEntities.clear();
|
||||
new_transition.dst_state = getStateID(dstStateName);
|
||||
transitions.push_back(new_transition);
|
||||
}
|
||||
|
||||
void CtxAut::showTransitions(void)
|
||||
{
|
||||
cout << "# Context Automaton Transitions:" << endl;
|
||||
for (const auto &t : transitions)
|
||||
{
|
||||
cout << " * [" << getStateName(t.src_state) << " -> " << getStateName(t.dst_state)
|
||||
<< "]: {" << parent_rctsys->entitiesToStr(t.ctx) << "}" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
/** EOF **/
|
||||
|
||||
11
ctx_aut.hh
11
ctx_aut.hh
@@ -15,6 +15,7 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <cstdlib>
|
||||
#include "rs.hh"
|
||||
#include "types.hh"
|
||||
#include "macro.hh"
|
||||
#include "options.hh"
|
||||
@@ -22,24 +23,30 @@
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
class RctSys;
|
||||
|
||||
class CtxAut
|
||||
{
|
||||
public:
|
||||
CtxAut(Options *opts) { setOptions(opts); }
|
||||
CtxAut(Options *opts, RctSys *parent_rctsys);
|
||||
bool hasState(std::string name);
|
||||
void addState(std::string stateName);
|
||||
State getStateID(std::string name);
|
||||
std::string getStateName(State state_id);
|
||||
void printAutomaton(void);
|
||||
void showStates(void);
|
||||
void addTransition(std::string srcStateName, std::string dstStateName);
|
||||
void showTransitions(void);
|
||||
void pushContextEntity(Entity entity_id);
|
||||
void setOptions(Options *opts) { this->opts = opts; }
|
||||
|
||||
private:
|
||||
RctSys *parent_rctsys;
|
||||
Options *opts;
|
||||
StatesById states_ids;
|
||||
StatesByName states_names;
|
||||
Entities tmpEntities;
|
||||
Entities tmpEntities;
|
||||
Transitions transitions;
|
||||
};
|
||||
|
||||
#endif /* RS_CTX_AUT_HH */
|
||||
|
||||
15
rs.cc
15
rs.cc
@@ -181,7 +181,7 @@ void RctSys::printSystem(void)
|
||||
void RctSys::ctxAutEnable(void)
|
||||
{
|
||||
assert(ctx_aut == nullptr);
|
||||
ctx_aut = new CtxAut(opts);
|
||||
ctx_aut = new CtxAut(opts, this);
|
||||
}
|
||||
|
||||
void RctSys::ctxAutAddState(std::string stateName)
|
||||
@@ -189,3 +189,16 @@ void RctSys::ctxAutAddState(std::string stateName)
|
||||
assert(ctx_aut != nullptr);
|
||||
ctx_aut->addState(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)
|
||||
{
|
||||
assert(ctx_aut != nullptr);
|
||||
Entity entity_id = getEntityID(entity_name);
|
||||
ctx_aut->pushContextEntity(entity_id);
|
||||
}
|
||||
|
||||
4
rs.hh
4
rs.hh
@@ -24,6 +24,8 @@
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
class CtxAut;
|
||||
|
||||
class RctSys
|
||||
{
|
||||
friend class SymRS;
|
||||
@@ -69,6 +71,8 @@ class RctSys
|
||||
|
||||
void ctxAutEnable(void);
|
||||
void ctxAutAddState(std::string stateName);
|
||||
void ctxAutAddTransition(std::string srcStateName, std::string dstStateName);
|
||||
void ctxAutPushNamedContextEntity(std::string entity_name);
|
||||
|
||||
private:
|
||||
Reactions reactions;
|
||||
|
||||
@@ -210,7 +210,11 @@ auttransitions:
|
||||
| auttrans SEMICOL auttransitions
|
||||
;
|
||||
|
||||
auttrans: LCB contextset RCB COL autstate RARR autstate
|
||||
auttrans: LCB contextset RCB COL IDENTIFIER RARR IDENTIFIER {
|
||||
driver.getReactionSystem()->ctxAutAddTransition(*$5, *$7);
|
||||
free($5);
|
||||
free($7);
|
||||
}
|
||||
;
|
||||
|
||||
contextset:
|
||||
@@ -219,7 +223,8 @@ contextset:
|
||||
;
|
||||
|
||||
ctxentity: IDENTIFIER {
|
||||
//
|
||||
driver.getReactionSystem()->ctxAutPushNamedContextEntity(*$1);
|
||||
free($1);
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user