9 #ifndef FAUDES_PD_PDGENERATOR_H
10 #define FAUDES_PD_PDGENERATOR_H
36 template <
class GlobalAttr,
class StateAttr,
class EventAttr,
class TransAttr>
428 StackSymbolSet::Iterator
FindStackSymbol(
const std::string& rName)
const;
536 bool SetTransition(
const std::string& rX1,
const std::string& rEv,
537 const std::string& rX2);
569 bool SetTransition(
const Transition& rTrans,
const std::vector<StackSymbol>& rPop,
const std::vector<StackSymbol>& rPush);
584 bool SetTransition(
const Transition& trans,
const std::vector<std::string>& rPop,
const std::vector<std::string>& rPush);
620 const std::vector<StackSymbol>& rPop,
const std::vector<StackSymbol>& rPush);
640 const std::vector<Idx>& rPop,
const std::vector<Idx>& rPush);
659 bool SetTransition(
const std::string& rX1,
const std::string& rEv,
const std::string& rX2,
const std::vector<StackSymbol>& rPop,
const std::vector<StackSymbol>& rPush);
680 bool SetTransition(
const std::string& rX1,
const std::string& rEv,
const std::string& rX2,
const std::vector<std::string>& rPop,
const std::vector<std::string>& rPush);
701 bool SetTransition(
Idx x1,
Idx ev,
Idx x2,
const std::vector<std::string>& rPop,
const std::vector<std::string>& rPush);
720 bool SetTransition(
const std::string& rX1,
const std::string& rEv,
const std::string& rX2,
const std::vector<Idx>& rPop,
const std::vector<Idx>& rPush);
746 bool SetTransition(
const std::string& rX1,
const std::string& rEv,
const std::string& rPop,
747 const std::string& rPush,
const std::string& rX2);
771 bool ClrTransition(
const std::string& rX1,
const std::string& rEv,
const std::string& rPop,
772 const std::string& rPush,
const std::string& rX2);
790 bool ClrTransition(
Idx x1,
Idx ev,
Idx x2,
const std::vector<StackSymbol>& rPop,
const std::vector<StackSymbol>& rPush);
826 bool ClrTransition(
Idx x1,
Idx ev,
Idx x2,
const std::vector<std::string>& rPop,
const std::vector<std::string>& rPush);
844 bool ClrTransition(std::string x1, std::string ev, std::string x2,
const std::vector<Idx>& rPop,
const std::vector<Idx>& rPush);
862 bool ClrTransition(std::string x1, std::string ev, std::string x2,
const std::vector<StackSymbol>& rPop,
const std::vector<StackSymbol>& rPush);
880 bool ClrTransition(std::string x1, std::string ev, std::string x2,
const std::vector<std::string>& rPop,
const std::vector<std::string>& rPush);
894 bool ClrTransition(
const Transition& rTrans,
const std::vector<StackSymbol>& rPop,
const std::vector<StackSymbol>& rPush);
908 bool ClrTransition(
const Transition& rTrans,
const std::vector<std::string>& rPop,
const std::vector<std::string>& rPush);
940 const std::string& rX1,
const std::string& rEv,
const std::string& rX2)
const;
1031 bool ExistsTransition(
Idx x1,
Idx ev,
Idx x2,
const std::vector<std::string>& pop,
const std::vector<std::string>& push)
const;
1051 bool ExistsTransition(
Idx x1,
Idx ev,
Idx x2,
const std::vector<StackSymbol>& rPop,
const std::vector<StackSymbol>& rPush)
const;
1071 bool ExistsTransition(
const std::string& x1,
const std::string& ev,
const std::string& x2,
const std::vector<StackSymbol>& pop,
const std::vector<StackSymbol>& push)
const;
1091 bool ExistsTransition(
const std::string& x1,
const std::string& ev,
const std::string& x2,
const std::vector<std::string>& pop,
const std::vector<std::string>& push)
const;
1111 bool ExistsTransition(
const std::string& x1,
const std::string& ev,
const std::string& x2,
const std::vector<Idx>& pop,
const std::vector<Idx>& push)
const;
1127 bool ExistsTransition(
const Transition& rTrans,
const std::vector<StackSymbol>& rPop,
const std::vector<StackSymbol>& rPush)
const;
1143 bool ExistsTransition(
const Transition& rTrans,
const std::vector<std::string>& rPop,
const std::vector<std::string>& rPush)
const;
1183 bool ExistsTransition(
const std::string& x1,
const std::string& ev,
const std::string& pop,
const std::string& push,
const std::string& x2)
const;
1361 virtual bool Valid(
void);
1377 virtual void DotWrite(
const std::string& rFileName)
const;
1400 virtual void DotWrite(
const std::string& rFileName,
bool printInfo,
bool lr)
const;
1419 virtual void DotRead(
const std::string& rFileName);
1434 typedef TpdGenerator<AttributePushdownGlobal, AttributePushdownState,
1441 #define THIS TpdGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
1442 #define BASE TcGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
1443 #define TEMP template <class GlobalAttr, class StateAttr, class EventAttr, class TransAttr>
1448 BASE::pGlobalAttribute->mStackSymbols.Name(
"StackSymbols");
1450 FD_DG(
"PushdownGenerator(" <<
this <<
")::PushdownGenerator() with csymtab "
1451 << (BASE::pGlobalAttribute->mpStackSymbolTable ));
1458 FD_DG(
"PushdownGenerator(" <<
this <<
")::PushdownGenerator(rOtherGen) with csymtab"
1459 <<
"(BASE::pGlobalAttribute->mpStackSymbolTable)" );
1465 BASE::pGlobalAttribute->mStackSymbols.Name(
"StackSymbols");
1467 FD_DG(
"PushdownGenerator(" <<
this <<
")::PushdownGenerator(rOtherGen) with csymtab"
1468 <<
"(BASE::pGlobalAttribute->mpStackSymbolTable)" );
1472 TEMP THIS::TpdGenerator(
const std::string& rFileName) {
1473 FD_DG(
"PushdownGenerator(" <<
this <<
")::PushdownGenerator(" << rFileName <<
") with csymtab"
1474 <<
"(BASE::pGlobalAttribute->mpStackSymbolTable)" );
1475 if(rFileName.substr(rFileName.find_last_of(
".") + 1) ==
"dot")
1478 BASE::pGlobalAttribute->mStackSymbols.Name(
"StackSymbols");
1480 THIS::DotRead(rFileName);
1488 FD_DG(
"TpdGenerator(" <<
this <<
")::StateStr("<< idx <<
"\")");
1489 #ifdef FAUDES_CHECKED
1490 if (! BASE::ExistsState(idx)) {
1491 std::stringstream errstr;
1492 errstr <<
"state \"" << idx <<
"\" not found in generator \""
1493 << BASE::Name() <<
"\"";
1494 throw Exception(
"TpdGenerator::StateStr(idx)", errstr.str(), 89);
1498 std::string str= BASE::StateName(idx);
1505 FD_DG(
"TpdGenerator(" <<
this <<
")::EventStr("<< idx <<
"\")");
1506 #ifdef FAUDES_CHECKED
1507 if (! BASE::ExistsEvent(idx)) {
1508 std::stringstream errstr;
1509 errstr <<
"event \"" << idx <<
"\" not found in generator \""
1510 << BASE::Name() <<
"\"";
1511 throw Exception(
"TpdGenerator::EventStr(idx)", errstr.str(), 89);
1515 std::string str= BASE::EventName(idx);
1527 return BASE::pGlobalAttribute->mpStackSymbolTable;
1533 BASE::pGlobalAttribute->mpStackSymbolTable=pSymTab;
1541 res->EventSymbolTablep(BASE::mpEventSymbolTable);
1542 res->mStateNamesEnabled=BASE::mStateNamesEnabled;
1543 res->mReindexOnWrite=BASE::mReindexOnWrite;
1545 res->StackSymbolTablep(StackSymbolTablep());
1560 THIS res= BASE::NewCGen();
1562 res.StackSymbolTablep(StackSymbolTablep());
1568 return BASE::pGlobalAttribute->mStackSymbols.Size();
1573 return BASE::pGlobalAttribute->mStackSymbols;
1578 return &BASE::pGlobalAttribute->mStackSymbols;
1583 BASE::pGlobalAttribute->mStackSymbols=newstacksymbols;
1584 BASE::pGlobalAttribute->mStackSymbols.
Name(
"StackSymbols");
1588 TEMP std::string THIS::StackSymbolName(
Idx index)
const {
1589 return BASE::pGlobalAttribute->mStackSymbols.SymbolicName(index);
1593 TEMP void THIS::StackSymbolName(
Idx index,
const std::string& rName)
const {
1594 FD_DG(
"TpdGenerator(" <<
this <<
")::StackSymbolName("
1595 << index <<
",\"" << rName <<
"\")");
1596 #ifdef FAUDES_CHECKED
1597 if (! ExistsStackSymbol(index)) {
1598 std::stringstream errstr;
1599 errstr <<
"stack symbol idex \"" << index <<
"\" not found in generator \""
1600 << BASE::Name() <<
"\"";
1601 throw Exception(
"TpdGenerator::StateName(index, name)", errstr.str(), 90);
1604 BASE::pGlobalAttribute->mStackSymbols.SymbolicName(index, rName);
1609 return StackSymbol(BASE::pGlobalAttribute->mStackSymbols.SymbolicName(index));
1613 TEMP Idx THIS::StackSymbolIndex(
const std::string& rName)
const {
1614 return BASE::pGlobalAttribute->mStackSymbols.Index(rName);
1618 TEMP Idx THIS::InsStackSymbol(
const std::string& rName) {
1619 return BASE::pGlobalAttribute->mStackSymbols.Insert(rName);
1624 return BASE::pGlobalAttribute->mStackSymbols.Insert(rSymbol.
Symbol());
1629 BASE::pGlobalAttribute->mStackSymbols.InsertSet(rStackSymbolSet);
1633 TEMP Idx THIS::SetStackBottom(
const std::string& rName) {
1634 Idx i = BASE::pGlobalAttribute->mStackSymbols.Insert(rName);
1635 BASE::pGlobalAttribute->mStackBottom = i;
1641 Idx i = BASE::pGlobalAttribute->mStackSymbols.Insert(rSymbol.
Symbol());
1642 BASE::pGlobalAttribute->mStackBottom = i;
1648 if(!ExistsStackSymbol(idx)) {
1649 std::stringstream errstr;
1650 errstr <<
"stack symbol with index " << idx <<
" not found in generator. " << std::endl;
1651 throw Exception(
"PushdownGenerator::SetStackBottom(idx)", errstr.str(), 200);
1653 BASE::pGlobalAttribute->mStackBottom =
StackSymbol(StackSymbolName(idx));
1659 return BASE::pGlobalAttribute->mStackBottom;
1664 FD_DG(
"PushdownGenerator(" <<
this <<
")::DelStackSymbol(" << index <<
")");
1665 return BASE::pGlobalAttribute->mStackSymbols.Erase(index);
1669 TEMP bool THIS::DelStackSymbol(
const std::string& rName) {
1670 Idx index=BASE::pGlobalAttribute->mStackSymbols.Index(rName);
1671 return DelStackSymbol(index);
1676 StackSymbolSet::Iterator it=StackSymbolsBegin();
1677 while(it!=StackSymbolsEnd()){
1678 DelStackSymbol(*(it++));
1683 TEMP bool THIS::ExistsStackSymbol(
Idx index)
const {
1684 return BASE::pGlobalAttribute->mStackSymbols.Exists(index);
1689 const std::string& rName)
const {
1690 return BASE::pGlobalAttribute->mStackSymbols.Exists(rName);
1694 TEMP StackSymbolSet::Iterator THIS::FindStackSymbol(
Idx index)
const {
1695 return BASE::pGlobalAttribute->mStackSymbols.Find(index);
1699 TEMP StackSymbolSet::Iterator THIS::FindStackSymbol(
const std::string& rName)
const {
1700 return BASE::pGlobalAttribute->mStackSymbols.Find(rName);
1704 TEMP std::string THIS::StackSymbolStr(
Idx idx)
const{
1705 FD_DG(
"TpdGenerator(" <<
this <<
")::StackSymbolStr("<< idx <<
"\")");
1706 #ifdef FAUDES_CHECKED
1707 if (! ExistsStackSymbol(idx)) {
1708 std::stringstream errstr;
1709 errstr <<
"stack symbol \"" << idx <<
"\" not found in generator \""
1710 << BASE::Name() <<
"\"";
1711 throw Exception(
"TpdGenerator::StackSymbolStr(idx)", errstr.str(), 89);
1714 std::string str= THIS::StackSymbolName(idx);
1720 TEMP std::string THIS::UniqueStackSymbolName(
const std::string& rName)
const {
1721 FD_DG(
"PushdownGenerator(" <<
this <<
")::UniqueStackSymbolName(" << rName <<
")");
1722 std::string name=rName;
1723 if(name==
"") name=
"s";
1724 return BASE::pGlobalAttribute->mpStackSymbolTable->UniqueSymbol(name) ;
1728 TEMP StackSymbolSet::Iterator THIS::StackSymbolsBegin(
void)
const {
1729 return BASE::pGlobalAttribute->mStackSymbols.Begin();
1733 TEMP StackSymbolSet::Iterator THIS::StackSymbolsEnd(
void)
const {
1734 return BASE::pGlobalAttribute->mStackSymbols.End();
1737 TEMP std::vector<Idx> THIS::StackSymbolsToIndices(
const std::vector<StackSymbol> symbols)
const{
1738 std::vector<StackSymbol>::const_iterator ssit;
1739 std::vector<Idx> rV;
1740 for(ssit = symbols.begin(); ssit != symbols.end(); ssit++){
1741 rV.push_back(StackSymbolIndex(ssit->Symbol()));
1747 TEMP std::vector<Idx> THIS::StackSymbolNamesToIndices(
const std::vector<std::string> symbolnames)
const{
1748 std::vector<std::string>::const_iterator ssit;
1749 std::vector<Idx> rV;
1750 for(ssit = symbolnames.begin(); ssit != symbolnames.end(); ssit++){
1751 rV.push_back(StackSymbolIndex(*ssit));
1759 StateSet::Iterator stateit;
1761 PopPushSet::iterator ppit1, ppit2;
1764 for(stateit = BASE::StatesBegin(); stateit != BASE::StatesEnd(); ++stateit){
1766 for(transit1 = BASE::TransRelBegin(*stateit); transit1 != BASE::TransRelEnd(*stateit); ++transit1){
1767 for(transit2 = transit1; transit2 != BASE::TransRelEnd(*stateit); ++transit2){
1769 if((transit1->Ev == transit2->Ev) ||
1770 THIS::IsEventLambda(transit2->Ev) ||
1771 THIS::IsEventLambda(transit1->Ev)){
1776 for(ppit1 = THIS::PopPushBegin(*transit1); ppit1 != THIS::PopPushEnd(*transit1); ++ppit1){
1777 for(ppit2 = THIS::PopPushBegin(*transit2); ppit2 != THIS::PopPushEnd(*transit2); ++ppit2){
1778 if(ppit1->first == ppit2->first)
1781 if(transit1 == transit2){
1800 for(transit = BASE::TransRelBegin(); transit != BASE::TransRelEnd(); transit++){
1801 s += PopPush(*transit).size();
1807 TEMP bool THIS::SetTransition(
const std::string& rX1,
const std::string& rEv,
const std::string& rX2) {
1808 return BASE::SetTransition(rX1,rEv,rX2);
1814 return BASE::SetTransition(
Transition(x1,ev,x2));
1818 TEMP bool THIS::SetTransition(
const Transition& rTransition,
const TransAttr& rAttr) {
1819 return BASE::SetTransition(rTransition,rAttr);
1823 TEMP bool THIS::SetTransition(
const Transition& rTrans,
const std::vector<StackSymbol>& rPop,
const std::vector<StackSymbol>& rPush) {
1824 return SetTransition(rTrans, StackSymbolsToIndices(rPop), StackSymbolsToIndices(rPush));
1827 TEMP bool THIS::SetTransition(
const Transition& rTrans,
const std::vector<Idx>& rPop,
const std::vector<Idx>& rPush) {
1828 FD_DG(
"PushdownGenerator(" <<
this <<
")::SetTransition(" << (BASE::TStr(rTrans)) <<
", " <<
1829 ", PopVector" <<
", " <<
"PushVector" <<
") const");
1830 #ifdef FAUDES_CHECKED
1831 EmptyVectorPopPush(rPop);
1832 EmptyVectorPopPush(rPush);
1834 BASE::SetTransition(rTrans);
1837 if(BASE::TransAttributep(rTrans) != 0){
1838 attr = *BASE::TransAttributep(rTrans);
1840 std::pair<std::vector<Idx>, std::vector<Idx> > popPushPair;
1841 popPushPair.first = rPop;
1842 popPushPair.second = rPush;
1844 attr.mPopPush.insert(popPushPair);
1845 #ifdef FAUDES_CHECKED
1846 ConsistentVectorStackSymbol(rPop);
1847 ConsistentVectorStackSymbol(rPush);
1849 return BASE::SetTransition(rTrans,attr);
1853 TEMP bool THIS::SetTransition(
Idx x1,
Idx ev,
Idx x2,
const std::vector<StackSymbol>& rPop,
const std::vector<StackSymbol>& rPush) {
1854 return SetTransition(
Transition(x1,ev,x2),rPop,rPush);
1858 TEMP bool THIS::SetTransition(
Idx x1,
Idx ev,
Idx x2,
const std::vector<Idx>& rPop,
const std::vector<Idx>& rPush) {
1859 return SetTransition(
Transition(x1,ev,x2),rPop,rPush);
1862 TEMP bool THIS::SetTransition(
const Transition& rTrans,
const std::vector<std::string>& rPop,
const std::vector<std::string>& rPush) {
1863 return SetTransition(rTrans,StackSymbolNamesToIndices(rPop),StackSymbolNamesToIndices(rPush));
1867 TEMP bool THIS::SetTransition(
const std::string& rX1,
const std::string& rEv,
const std::string& rX2,
const std::vector<StackSymbol>& rPop,
const std::vector<StackSymbol>& rPush) {
1868 FD_DG(
"PushdownGenerator(" <<
this <<
")::SetTransition(" << rX1 <<
" " << rEv <<
" " << rX2 <<
1869 ", PopVector" <<
", " <<
"PushVector" <<
") const");
1871 bool res=BASE::SetTransition(rX1,rEv,rX2);
1873 Transition rTrans = *(BASE::FindTransition(rX1,rEv,rX2));
1874 #ifdef FAUDES_CHECKED
1875 EmptyVectorPopPush(rPop);
1876 EmptyVectorPopPush(rPush);
1880 if(BASE::TransAttributep(rTrans) != 0){
1881 attr = *BASE::TransAttributep(rTrans);
1883 std::pair<std::vector<Idx>, std::vector<Idx> > popPushPair;
1884 popPushPair.first = StackSymbolsToIndices(rPop);
1885 popPushPair.second = StackSymbolsToIndices(rPush);
1887 attr.mPopPush.insert(popPushPair);
1888 #ifdef FAUDES_CHECKED
1889 ConsistentVectorStackSymbol(rPop);
1890 ConsistentVectorStackSymbol(rPush);
1892 BASE::TransAttribute(
Transition(BASE::StateIndex(rX1),BASE::EventIndex(rEv),BASE::StateIndex(rX2)),attr);
1897 TEMP bool THIS::SetTransition(
Idx x1,
Idx ev,
Idx x2,
const std::vector<std::string>& rPop,
const std::vector<std::string>& rPush) {
1898 return SetTransition(
Transition(x1,ev,x2),rPop,rPush);
1902 TEMP bool THIS::SetTransition(
const std::string& rX1,
const std::string& rEv,
const std::string& rX2,
const std::vector<std::string>& rPop,
const std::vector<std::string>& rPush) {
1903 return SetTransition(
Transition(BASE::StateIndex(rX1),BASE::EventIndex(rEv),BASE::StateIndex(rX2)),rPop,rPush);
1907 TEMP bool THIS::SetTransition(
const std::string& rX1,
const std::string& rEv,
const std::string& rX2,
const std::vector<Idx>& rPop,
const std::vector<Idx>& rPush) {
1908 return SetTransition(
Transition(BASE::StateIndex(rX1),BASE::EventIndex(rEv),BASE::StateIndex(rX2)),rPop,rPush);
1912 TEMP std::vector<std::string> THIS::ParseStackSymbolNames(
const std::string& rStr)
const{
1913 std::string::size_type end_position,pos= 0;
1914 std::vector<std::string> syms;
1915 std::string s = rStr;
1918 s.erase(std::remove_if(s.begin(), s.end(), ::isspace), s.end());
1922 if (pos != std::string::npos)
1925 end_position = s.find(
"]",++pos);
1926 if (end_position != std::string::npos)
1929 std::string found_text = s.substr(pos, end_position-pos);
1931 if (!found_text.empty()) {
1932 std::string::size_type curr = 0, end = 0;
1938 while ((end = found_text.find(
",", curr)) != std::string::npos) {
1939 sub = found_text.substr(curr, end - curr);
1940 syms.push_back(sub);
1945 if (curr < found_text.size())
1946 syms.push_back(found_text.substr(curr));
1949 #ifdef FAUDES_CHECKED
1951 std::stringstream errstr;
1952 errstr <<
" Missing ']' for pop or push ." << std::endl;
1953 throw Exception(
"TpdGenerator::parsePPString", errstr.str(), 200);
1957 #ifdef FAUDES_CHECKED
1959 std::stringstream errstr;
1960 errstr <<
" Missing '[' for pop or push ." << std::endl;
1961 throw Exception(
"TpdGenerator::parsePPString", errstr.str(), 200);
1973 TEMP bool THIS::SetTransition(
const std::string& rX1,
const std::string& rEv,
const std::string& rPop,
1974 const std::string& rPush,
const std::string& rX2){
1975 return SetTransition(rX1,rEv,rX2,ParseStackSymbolNames(rPop),ParseStackSymbolNames(rPush));
1979 TEMP bool THIS::ClrTransition(
Idx x1,
Idx ev,
Idx x2,
const std::vector<Idx>& rPop,
const std::vector<Idx>& rPush){
1980 return ClrTransition(
Transition(x1,ev,x2),rPop,rPush);
1984 TEMP bool THIS::ClrTransition(
Idx x1,
Idx ev,
Idx x2,
const std::vector<StackSymbol>& rPop,
const std::vector<StackSymbol>& rPush){
1985 return ClrTransition(
Transition(x1,ev,x2),rPop,rPush);
1989 TEMP bool THIS::ClrTransition(
Idx x1,
Idx ev,
Idx x2,
const std::vector<std::string>& rPop,
const std::vector<std::string>& rPush){
1990 return ClrTransition(
Transition(x1,ev,x2),rPop,rPush);
1994 TEMP bool THIS::ClrTransition(std::string x1, std::string ev, std::string x2,
const std::vector<Idx>& rPop,
const std::vector<Idx>& rPush){
1995 return ClrTransition(
Transition(BASE::StateIndex(x1),BASE::EventIndex(ev),BASE::StateIndex(x2)),rPop,rPush);
1999 TEMP bool THIS::ClrTransition(std::string x1, std::string ev, std::string x2,
const std::vector<StackSymbol>& rPop,
const std::vector<StackSymbol>& rPush){
2000 return ClrTransition(
Transition(BASE::StateIndex(x1),BASE::EventIndex(ev),BASE::StateIndex(x2)),rPop,rPush);
2004 TEMP bool THIS::ClrTransition(std::string x1, std::string ev, std::string x2,
const std::vector<std::string>& rPop,
const std::vector<std::string>& rPush){
2005 return ClrTransition(
Transition(BASE::StateIndex(x1),BASE::EventIndex(ev),BASE::StateIndex(x2)),rPop,rPush);
2009 TEMP bool THIS::ClrTransition(
const Transition& rTrans,
const std::vector<StackSymbol>& rPop,
const std::vector<StackSymbol>& rPush){
2010 return ClrTransition(rTrans,StackSymbolsToIndices(rPop),StackSymbolsToIndices(rPush));
2014 TEMP bool THIS::ClrTransition(
const Transition& rTrans,
const std::vector<std::string>& rPop,
const std::vector<std::string>& rPush){
2015 return ClrTransition(rTrans,StackSymbolNamesToIndices(rPop),StackSymbolNamesToIndices(rPush));
2019 TEMP bool THIS::ClrTransition(
const Transition& rTrans,
const std::vector<Idx>& rPop,
const std::vector<Idx>& rPush){
2021 if(!BASE::ExistsTransition(rTrans)){
2026 if(!BASE::pTransRel->Attributep(rTrans)->ClrPopPush(rPop, rPush)){
2031 if(PopPush(rTrans).empty()){
2032 BASE::ClrTransition(rTrans);
2039 TEMP bool THIS::ClrTransition(
const std::string& rX1,
const std::string& rEv,
const std::string& rPop,
const std::string& rPush,
const std::string& rX2){
2040 return ClrTransition(rX1,rEv,rX2,ParseStackSymbolNames(rPop),ParseStackSymbolNames(rPush));
2044 TEMP bool THIS::ExistsTransition(
const std::string& rX1,
const std::string& rEv,
const std::string& rX2)
const{
2045 return BASE::ExistsTransition(rX1,rEv,rX2);
2050 return BASE::ExistsTransition(x1,ev,x2);
2055 return BASE::ExistsTransition(rTrans);
2060 return BASE::ExistsTransition(x1, ev);
2065 return BASE::ExistsTransition(x1);
2069 TEMP bool THIS::ExistsTransition(
Idx x1,
Idx ev,
Idx x2,
const std::vector<Idx>& pop,
const std::vector<Idx>& push)
const{
2070 return THIS::ExistsTransition(
Transition(x1, ev, x2),pop,push);
2074 TEMP bool THIS::ExistsTransition(
Idx x1,
Idx ev,
Idx x2,
const std::vector<std::string>& pop,
const std::vector<std::string>& push)
const{
2075 return THIS::ExistsTransition(
Transition(x1, ev, x2),pop,push);
2079 TEMP bool THIS::ExistsTransition(
Idx x1,
Idx ev,
Idx x2,
const std::vector<StackSymbol>& rPop,
const std::vector<StackSymbol>& rPush)
const{
2080 return ExistsTransition(
Transition(x1,ev,x2),rPop,rPush);
2084 TEMP bool THIS::ExistsTransition(
const std::string& x1,
const std::string& ev,
const std::string& x2,
const std::vector<StackSymbol>& pop,
const std::vector<StackSymbol>& push)
const{
2085 return THIS::ExistsTransition(
Transition(BASE::StateIndex(x1), BASE::EventIndex(ev), BASE::StateIndex(x2)),pop,push);
2089 TEMP bool THIS::ExistsTransition(
const std::string& x1,
const std::string& ev,
const std::string& x2,
const std::vector<std::string>& pop,
const std::vector<std::string>& push)
const{
2090 return THIS::ExistsTransition(
Transition(BASE::StateIndex(x1), BASE::EventIndex(ev), BASE::StateIndex(x2)),pop,push);
2094 TEMP bool THIS::ExistsTransition(
const std::string& x1,
const std::string& ev,
const std::string& x2,
const std::vector<Idx>& pop,
const std::vector<Idx>& push)
const{
2095 return THIS::ExistsTransition(
Transition(BASE::StateIndex(x1), BASE::EventIndex(ev), BASE::StateIndex(x2)),pop,push);
2099 TEMP bool THIS::ExistsTransition(
const Transition& rTrans,
const std::vector<StackSymbol>& rPop,
const std::vector<StackSymbol>& rPush)
const{
2100 return ExistsTransition(rTrans,StackSymbolsToIndices(rPop),StackSymbolsToIndices(rPush));
2104 TEMP bool THIS::ExistsTransition(
const Transition& rTrans,
const std::vector<std::string>& rPop,
const std::vector<std::string>& rPush)
const{
2105 return ExistsTransition(rTrans,StackSymbolNamesToIndices(rPop),StackSymbolNamesToIndices(rPush));
2109 TEMP bool THIS::ExistsTransition(
const Transition& rTrans,
const std::vector<Idx>& rPop,
const std::vector<Idx>& rPush)
const{
2110 if(BASE::ExistsTransition(rTrans)){
2113 std::pair<std::vector<Idx>, std::vector<Idx> > popPushPair;
2114 popPushPair.first = rPop;
2115 popPushPair.second = rPush;
2117 return popPushSet.find(popPushPair) != popPushSet.end();
2124 TEMP bool THIS::ExistsTransition(
const std::string& rX1,
const std::string& rEv,
const std::string& rPop,
2125 const std::string& rPush,
const std::string& rX2)
const{
2127 return ExistsTransition(rX1,rEv,rX2,ParseStackSymbolNames(rPop),ParseStackSymbolNames(rPush));
2132 #ifdef FAUDES_CHECKED
2133 if(!BASE::ExistsTransition(rTrans)) {
2134 std::stringstream errstr;
2135 errstr <<
"transition " << BASE::TStr(rTrans) <<
" not found ";
2136 errstr << std::endl;
2137 throw Exception(
"PushdownGenerator::PopPush(trans)", errstr.str(), 200);
2140 return BASE::pTransRel->Attribute(rTrans).PopPush();
2145 return BASE::pTransRel->Attribute(rTrans).PopPush().begin();
2150 return BASE::pTransRel->Attribute(rTrans).PopPush().end();
2162 TEMP bool THIS::IsStackSymbolLambda(
Idx index)
const{
2180 FD_DG(
"PushdownGenerator(" <<
this <<
")::ConsistentStackSymbol(rStackSymbol)");
2181 if(!StackSymbols().Exists(rStackSymbol.
Symbol())) {
2182 std::stringstream errstr;
2183 errstr <<
"stack symbol table mismatch (symbol " << rStackSymbol.
mSymbol <<
" does not exist)" << std::endl;
2184 throw Exception(
"PushdownGenerator::ConsistentStackSymbol", errstr.str(), 1001);
2186 FD_DG(
"PushdownGenerator(" <<
this <<
")::ConsistentStackSymbol(rStackSymbol): ok");
2190 TEMP void THIS::ConsistentStackSymbol(
Idx idx)
const {
2191 FD_DG(
"PushdownGenerator(" <<
this <<
")::ConsistentStackSymbol(idx)");
2192 if(!StackSymbols().Exists(idx)) {
2193 std::stringstream errstr;
2194 errstr <<
"stack symbol table mismatch (symbol with idx " << idx <<
" does not exist)" << std::endl;
2195 throw Exception(
"PushdownGenerator::ConsistentStackSymbol", errstr.str(), 1001);
2197 FD_DG(
"PushdownGenerator(" <<
this <<
")::ConsistentStackSymbol(idx): ok");
2201 TEMP void THIS::ConsistentVectorStackSymbol(
const std::vector<StackSymbol>& rVector)
const {
2202 FD_DG(
"PushdownGenerator(" <<
this <<
")::ConsistentVectorStackSymbol(rVector)");
2203 std::vector<StackSymbol>::const_iterator it;
2204 it = rVector.begin();
2205 for ( ; it < rVector.end(); it++){
2206 if(!StackSymbols().Exists(it->Symbol())) {
2207 std::stringstream errstr;
2208 errstr <<
"stack symbol table mismatch (symbol " << it->mSymbol <<
" does not exist)" <<std::endl;
2209 throw Exception(
"PushdownGenerator::ConsistentVectorStackSymbol", errstr.str(), 1001);
2212 FD_DG(
"PushdownGenerator(" <<
this <<
")::ConsistentVectorStackSymbol(rVector): ok");
2216 TEMP void THIS::ConsistentVectorStackSymbol(
const std::vector<Idx>& rVector)
const {
2217 FD_DG(
"PushdownGenerator(" <<
this <<
")::ConsistentVectorStackSymbol(rVector)");
2218 std::vector<Idx>::const_iterator it;
2219 it = rVector.begin();
2220 for ( ; it < rVector.end(); it++){
2221 if(!StackSymbols().Exists(*it)) {
2222 std::stringstream errstr;
2223 errstr <<
"stack symbol table mismatch (symbol with index " << *it <<
" does not exist)" <<std::endl;
2224 throw Exception(
"PushdownGenerator::ConsistentVectorStackSymbol", errstr.str(), 1001);
2227 FD_DG(
"PushdownGenerator(" <<
this <<
")::ConsistentVectorStackSymbol(rVector): ok");
2231 TEMP void THIS::EmptyVectorPopPush(
const std::vector<StackSymbol>& rVector)
const {
2232 FD_DG(
"PushdownGenerator(" <<
this <<
")::EmptyVector(rVector)");
2233 if(rVector.empty()) {
2234 std::stringstream errstr;
2235 errstr <<
"empty vector not allowed in pop or push" <<std::endl;
2236 throw Exception(
"PushdownGenerator::EmptyVector", errstr.str(), 1001);
2238 FD_DG(
"PushdownGenerator(" <<
this <<
")::EmptyVectorPopPush(rVector): ok");
2242 TEMP void THIS::EmptyVectorPopPush(
const std::vector<Idx>& rVector)
const {
2243 FD_DG(
"PushdownGenerator(" <<
this <<
")::EmptyVector(rVector)");
2244 if(rVector.empty()) {
2245 std::stringstream errstr;
2246 errstr <<
"empty vector not allowed in pop or push" <<std::endl;
2247 throw Exception(
"PushdownGenerator::EmptyVector", errstr.str(), 1001);
2249 FD_DG(
"PushdownGenerator(" <<
this <<
")::EmptyVectorPopPush(rVector): ok");
2255 Idx index=BASE::StateIndex(stateName);
2256 BASE::pStates->Attributep(index)->SetMerge(rMerge);
2261 BASE::pStates->Attributep(index)->SetMerge(rMerge);
2266 return BASE::pStates->Attributep(index)->Merge();
2270 TEMP void THIS::SetDfaState(
const std::string& stateName,
Idx dfaIndex){
2271 Idx index=BASE::StateIndex(stateName);
2272 BASE::pStates->Attributep(index)->DfaState(dfaIndex);
2277 BASE::pStates->Attributep(index)->DfaState(dfaIndex);
2282 return BASE::pStates->Attributep(index)->DfaState();
2287 FD_DV(
"PushdownGenerator(" <<
this <<
")::Valid()");
2289 if(!BASE::Valid())
return false;
2301 TEMP void THIS::DotWrite(
const std::string& rFileName,
bool printInfo,
bool lr)
const {
2302 FD_DG(
"TpdGenerator(" <<
this <<
")::DotWrite(" << rFileName <<
","<< printInfo <<
"," << lr <<
")");
2304 BASE::SetMinStateIndexMap();
2305 StateSet::Iterator sit;
2306 EventSet::Iterator eit;
2308 StackSymbolSet::Iterator ssit;
2310 PopPushSet::iterator ppit;
2311 std::vector<Idx>::iterator pit;
2314 std::ofstream stream;
2315 stream.exceptions(std::ios::badbit|std::ios::failbit);
2316 stream.open(rFileName.c_str());
2317 stream <<
"// dot output generated by libFAUDES TpdGenerator" << std::endl;
2318 stream <<
"digraph \"" << BASE::Name() <<
"\" {";
2319 stream << std::endl;
2321 if(lr) stream <<
" rankdir=LR" << std::endl;
2324 std::string initState =
"_", stackbottom =
"_";
2325 if(BASE::ExistsState(BASE::InitState()))
2326 initState = StateStr(BASE::InitState());
2327 if(ExistsStackSymbol(StackBottom()))
2328 stackbottom = StackSymbolStr(StackBottom());
2336 stream <<
" \"\" [shape = none " << std::endl;
2337 stream <<
" label = < " << std::endl;
2340 stream <<
" M=(Q, Σ , Γ , "<< initState <<
" , "<< stackbottom <<
", δ, Qm) <br align=\"LEFT\"/>" << std::endl;
2342 stream <<
" Σ = Σc ∪ Σuc <br align=\"LEFT\"/>" << std::endl;
2343 std::stringstream ConEv,UnConEv;
2344 for(eit = BASE::AlphabetBegin(); eit != BASE::AlphabetEnd(); ++eit)
2345 if(BASE::Controllable(*eit)){
2346 if(!IsEventLambda(*eit))
2347 ConEv <<
" "<< EventStr(*eit) <<
",";
2351 if(!IsEventLambda(*eit))
2352 UnConEv <<
" "<< EventStr(*eit) <<
",";
2355 std::string evstr = ConEv.str();
2356 if(!evstr.empty()) evstr.resize(evstr.size()-1);
2357 stream <<
" Σc = {"<< evstr <<
" } <br align=\"LEFT\"/>" << std::endl;
2359 evstr = UnConEv.str();
2360 if(!evstr.empty()) evstr.resize(evstr.size()-1);
2361 stream <<
" Σuc = {"<< evstr <<
" } <br align=\"LEFT\"/>" << std::endl;
2363 stream <<
" Γ = { ";
2364 int countSymbols = 0;
2365 for(ssit = StackSymbolsBegin(); ssit != StackSymbolsEnd(); ++ssit){
2366 if(!IsStackSymbolLambda(*ssit)){
2367 if(countSymbols % 10 == 9){
2368 stream <<
"<br align=\"LEFT\"/>" << std::endl;
2371 if(countSymbols != 0)
2373 stream << StackSymbolStr(*ssit);
2377 stream <<
" } <br align=\"LEFT\"/>" << std::endl;
2378 stream <<
" >];" << std::endl;
2379 stream << std::endl;
2381 stream <<
" node [shape=circle];" << std::endl;
2382 stream << std::endl;
2385 stream <<
" // initial states" << std::endl;
2387 for (sit = BASE::InitStatesBegin(); sit != BASE::InitStatesEnd(); ++sit) {
2388 stream <<
" dot_dummyinit_" << i <<
" [shape=none, label=\"\", width=\"0.0\", height=\"0.0\" ];" << std::endl;
2389 stream <<
" dot_dummyinit_" << i <<
" -> \"" << StateStr(*sit) <<
"\";" << std::endl;
2392 stream << std::endl;
2395 stream <<
" // stackbottom" << std::endl;
2396 if(stackbottom !=
"")
2397 stream <<
" \"" << stackbottom <<
"\" [style=\"invis\", attr=\"stackbottom\"];" <<std::endl;
2399 stream << std::endl;
2402 stream <<
" // mstates" << std::endl;
2403 for (sit = BASE::MarkedStatesBegin(); sit != BASE::MarkedStatesEnd(); ++sit)
2404 stream <<
" \"" << StateStr(*sit) <<
"\" [shape=doublecircle];" << std::endl;
2406 stream << std::endl;
2409 stream <<
" // rest of stateset" << std::endl;
2410 for (sit = BASE::StatesBegin(); sit != BASE::StatesEnd(); ++sit) {
2411 if (! (BASE::ExistsInitState(*sit) || BASE::ExistsMarkedState(*sit)) )
2412 stream <<
" \"" << StateStr(*sit) <<
"\";" << std::endl;
2414 stream << std::endl;
2417 stream <<
" // events" << std::endl;
2419 if(!THIS::IsEventLambda(*eit)){
2421 stream <<
" \"" <<EventStr(*eit) <<
"\" [style=\"invis\", attr=\"";
2422 stream << (BASE::Controllable(*eit)?
"C" :
"c");
2423 stream << (BASE::Observable(*eit)?
"O" :
"o");
2424 stream << (BASE::Forcible(*eit)?
"F" :
"f");
2425 stream << (BASE::Highlevel(*eit)?
"A" :
"a");
2426 stream <<
"\"];" << std::endl;
2429 stream << std::endl;
2432 stream <<
" // transition relation" << std::endl;
2433 for(tit = BASE::TransRelBegin(); tit != BASE::TransRelEnd(); ++tit) {
2434 std::string eventname;
2436 eventname =
"λ";
2438 eventname = EventStr(tit->Ev);
2440 if(PopPush(*tit).empty()){
2441 stream <<
" \"" << StateStr(tit->X1) <<
"\" -> \"" << StateStr(tit->X2)
2442 <<
"\" [label=\"" << eventname <<
" \"];" << std::endl;
2444 for (ppit = PopPushBegin(*tit); ppit != PopPushEnd(*tit); ++ppit) {
2445 std::vector<Idx> vPop = (*ppit).first;
2446 std::vector<Idx> vPush = (*ppit).second;
2449 stream <<
" \"" << StateStr(tit->X1) <<
"\" -> \"" << StateStr(tit->X2)
2450 <<
"\" [label=\"" << eventname <<
",";
2454 for (pit = vPop.begin(); pit != vPop.end(); ++pit) {
2455 if(!IsStackSymbolLambda(*pit))
2456 stream << StackSymbolName(*pit);
2458 stream <<
"λ";
2460 if(pit+1 != vPop.end()) stream <<
",";
2466 for (pit = vPush.begin(); pit != vPush.end(); ++pit) {
2467 if(!IsStackSymbolLambda(*pit))
2468 stream << StackSymbolName(*pit);
2470 stream <<
"λ";
2472 if(pit+1 != vPush.end()) stream <<
",";
2478 if(!BASE::Controllable(tit->Ev))
2479 stream <<
" style=\"dashed\"";
2481 stream <<
" ];" << std::endl;
2484 stream <<
"}" << std::endl;
2487 catch (std::ios::failure&) {
2489 "Exception opening/writing dotfile \""+rFileName+
"\"", 2);
2494 TEMP void THIS::DotWrite(
const std::string& rFileName)
const {
2495 FD_DG(
"TpdGenerator(" <<
this <<
")::DotWrite(" << rFileName <<
")");
2496 DotWrite(rFileName,
true,
true);
2503 TEMP void THIS::DotRead(
const std::string& rFileName) {
2504 FD_DG(
"TpdGenerator(" <<
this <<
")::DotRead(" << rFileName <<
")");
2509 std::stringstream errstr;
2510 errstr <<
"Unable to parse "<< rFileName << std::endl;
2511 throw Exception(
"TpdGenerator::DotRead", errstr.str(), 200);