MpsGuiValue::MpsGuiValue(int maxpid, const std::string &session, int pid, const MpsExp &name, const MpsExp &value, const MpsTerm &succ) // {{{ : mySession(session), myMaxpid(maxpid), myPid(pid) { mySucc = succ.Copy(); myValue = value.Copy(); myName = name.Copy(); } // }}}
MpsAssign::MpsAssign(const string &id, const MpsExp &exp, const MpsMsgType &type, const MpsTerm &succ) // {{{ { myId = id; myExp = exp.Copy(); myType = type.Copy(); mySucc = succ.Copy(); } // }}}
int main(int argc, char** argv) { if (argc!=2) { cerr << "Syntax: " << argv[0] << " EXP" << endl; return 1; } Parser p; p.DefToken("","[ \t\r\n][ \t\r\n]*",10); p.DefToken("id","[a-z][a-z0-9]*",10); p.DefKeywordToken("=>",2); p.DefKeywordToken("<=",2); p.DefKeywordToken("<=>",1); p.DefToken("AND","AND+and+&",1); p.DefToken("OR","OR+or+|",1); p.DefToken("NOT","NOT+not+~",1); p.DefToken("T","T+true",1); p.DefToken("F","F+false",1); p.DefKeywordToken("(",1); p.DefKeywordToken(")",1); p.DefType("exp ::= exp <=> exp2 | exp2"); p.DefType("exp2 ::= exp2 => exp3 | exp3"); p.DefType("exp3 ::= exp3 <= exp4 | exp4"); p.DefType("exp4 ::= exp4 AND exp5 | exp5"); p.DefType("exp5 ::= exp5 OR exp6 | exp6"); p.DefType("exp6 ::= NOT exp6 | exp7"); p.DefType("exp7 ::= T | F | id | ( exp )"); parsed_tree *tree=p.Parse(argv[1]); MpsExp *e = Create(tree); vector<const MpsExp*> hyps; // double lk_start=gettime(); // cout << "LK: " << e->ValidExp_LK(hyps) << endl; // double lk_end=gettime(); // cout << "LK-TIME: " << lk_end-lk_start << endl; double cflkf_start=gettime(); cout << "CFLKF: " << e->ValidExp_CFLKF(hyps) << endl; double cflkf_end=gettime(); cout << "CFLKF-TIME: " << cflkf_end-cflkf_start << endl; // cout << e->ToString() << endl; // MpsExp *cnf_e = e->MakeCNF(); delete e; // cout << cnf_e->ToString() << endl; // cout << "CNF: " << cnf_e->ValidCNF() << endl; // delete cnf_e; return 0; }
bool MpsAssign::TypeCheck(const MpsExp &Theta, const MpsMsgEnv &Gamma, const MpsProcEnv &Omega, const set<pair<string,int> > &pureStack, const string &curPure, PureState pureState, bool checkPure) // * Check exp has correct type, and check succ in updated sigma {{{ { if (checkPure) { // Check purity constraints if (pureState!=CPS_IMPURE && pureState!=CPS_PURE) return PrintTypeError("Error in implementation of pure participant " + curPure + ". Pure implementations must conform with the structure \n * local X()\n * ( global s=new ch(p of n);\n * X();\n * |\n * P\n * )\n * local StartX(Int i)\n * ( if i<=0\n * then X();\n * else X(); | StartX(i-1);\n * )\n * StartX( E ); |" ,*this,Theta,Gamma,Omega); } MpsMsgType *exptype=myExp->TypeCheck(Gamma); // Is exp typed if (dynamic_cast<const MpsMsgNoType*>(exptype)) return PrintTypeError((string)"Expression does not typecheck",*this,Theta,Gamma,Omega); if (dynamic_cast<const MpsMsgNoType*>(myType)==NULL) { // Compare types bool exptypematch = exptype->Equal(Theta,*myType); delete exptype; if (not exptypematch) return PrintTypeError((string)"Expression does not have type: " + myType->ToString(),*this,Theta,Gamma,Omega); } else { // Store type delete myType; myType = exptype->Copy(); } // Verify assign if (dynamic_cast<MpsDelegateMsgType*>(myType)!=NULL) return PrintTypeError("Assignment type cannot be a session, because it breaks linearity",*this,Theta,Gamma,Omega); // Check no session is eclipsed MpsMsgEnv::const_iterator var=Gamma.find(myId); if (var!=Gamma.end() && dynamic_cast<const MpsDelegateMsgType*>(var->second)!=NULL) return PrintTypeError((string)"Session eclipsed by assignment: " + myId,*this,Theta,Gamma,Omega); // Make new environment string newId = MpsExp::NewVar(myId); MpsExp *tmpTheta=Theta.Rename(myId,newId); MpsExp *newTheta; if (myType->ToString()=="Bool") { MpsExp *eq1 = new MpsVarExp(myId,MpsMsgNoType()); MpsExp *eq2 = myExp->Rename(myId,newId); MpsExp *neq1=new MpsUnOpExp("not",*eq1); MpsExp *neq2=new MpsUnOpExp("not",*eq2); MpsExp *leftExp=new MpsBinOpExp("or",*eq1,*neq2,MpsMsgNoType(),MpsMsgNoType()); MpsExp *rightExp=new MpsBinOpExp("or",*neq1,*eq2,MpsMsgNoType(),MpsMsgNoType()); MpsExp *addTheta=new MpsBinOpExp("and",*leftExp,*rightExp,MpsMsgNoType(),MpsMsgNoType()); newTheta=new MpsBinOpExp("and",*tmpTheta,*addTheta,MpsMsgNoType(),MpsMsgNoType()); delete eq1; delete eq2; delete neq1; delete neq2; delete leftExp; delete rightExp; delete addTheta; delete tmpTheta; } else newTheta=tmpTheta; MpsMsgEnv newGamma; for (MpsMsgEnv::const_iterator it=Gamma.begin(); it!=Gamma.end(); ++it) if (it->first!=myId) newGamma[it->first]=it->second->ERename(myId,newId); newGamma[myId]=myType->Copy(); // Check new Successor bool result = mySucc->TypeCheck(*newTheta,newGamma,Omega,pureStack,curPure, pureState, checkPure); delete newTheta; DeleteMap(newGamma); return result; } // }}}
MpsCond::MpsCond(const MpsExp &cond, const MpsTerm &truebranch, const MpsTerm &falsebranch) // {{{ { myCond = cond.Copy(); myTrueBranch = truebranch.Copy(); myFalseBranch = falsebranch.Copy(); } // }}}