示例#1
0
        public static LTLFormula parse(ltl2ba.Node LTLHeadNode, APSet predefined_apset)
        {
            //    boost::char_separator<char> sep(" ");
            //ltl_seperator sep; tokenizer tokens(formula, sep);

            APSet apset = new APSet();

            //tokenizer::iterator it = tokens.begin();

            //LTLNode ltl = parse(apset, predefined_apset);

            //if (it != tokens.end())
            //{
            //    THROW_EXCEPTION(Exception, "Unexpected character(s) at end of LTL formula: '" + *it + "'");
            //}


            LTLNode ltl = TranslateLTL(LTLHeadNode, apset, predefined_apset);

            APSet apset_ = predefined_apset ?? apset;

            return(new LTLFormula(ltl, apset_));
        }
示例#2
0
        public static bool HasSyntaxSafeOperator(ltl2ba.Node CurrentNode)
        {
            if (CurrentNode == null)
            {
                return(true);
            }

            bool currentSafe = true;

            switch ((Operator)CurrentNode.ntyp)
            {
            case Operator.ALWAYS:
                break;

            case Operator.AND:
                break;

            case Operator.EQUIV:
                break;

            case Operator.EVENTUALLY:
                currentSafe = false;
                break;

            case Operator.FALSE:
                break;

            case Operator.IMPLIES:
                if (CurrentNode.lft != null)
                {
                    if ((Operator)CurrentNode.lft.ntyp != Operator.PREDICATE)
                    {
                        currentSafe = false;
                    }
                }
                break;

            case Operator.NOT:
                Debug.Assert(CurrentNode.rgt == null);

                if (CurrentNode.lft != null)
                {
                    if ((Operator)CurrentNode.lft.ntyp != Operator.PREDICATE)
                    {
                        currentSafe = false;
                    }
                }
                break;

            case Operator.OR:
                break;

            case Operator.TRUE:
                break;

            case Operator.U_OPER:
                currentSafe = false;
                break;

            case Operator.V_OPER:
                break;

            case Operator.NEXT:
                break;

            case Operator.PREDICATE:
                break;

            default:
                break;
            }

            if (currentSafe)
            {
                return(HasSyntaxSafeOperator(CurrentNode.lft) && HasSyntaxSafeOperator(CurrentNode.rgt));
            }
            return(false);
        }
示例#3
0
        private static LTLNode TranslateLTL(ltl2ba.Node CurrentNode, APSet apset, APSet predefined_apset)
        {
            if (CurrentNode == null)
            {
                return(null);
            }

            type_t nodeType = type_t.T_TRUE;

            switch ((Operator)CurrentNode.ntyp)
            {
            case Operator.ALWAYS:
                nodeType = type_t.T_GLOBALLY;
                break;

            case Operator.AND:
                nodeType = type_t.T_AND;
                break;

            case Operator.EQUIV:
                nodeType = type_t.T_EQUIV;
                break;

            case Operator.EVENTUALLY:
                nodeType = type_t.T_FINALLY;
                break;

            case Operator.FALSE:
                nodeType = type_t.T_FALSE;
                break;

            case Operator.IMPLIES:
                nodeType = type_t.T_IMPLICATE;
                break;

            case Operator.NOT:
                nodeType = type_t.T_NOT;
                break;

            case Operator.OR:
                nodeType = type_t.T_OR;
                break;

            case Operator.TRUE:
                nodeType = type_t.T_TRUE;
                break;

            case Operator.U_OPER:
                nodeType = type_t.T_UNTIL;
                break;

            case Operator.V_OPER:
                nodeType = type_t.T_RELEASE;
                break;

            case Operator.NEXT:
                nodeType = type_t.T_NEXTSTEP;
                break;

            case Operator.PREDICATE:
                nodeType = type_t.T_AP;

                string ap = CurrentNode.sym.name;
                char   ch = ap[0];

                if (ch == '"')
                {
                    //	std::cerr << ap << std::endl;
                    Debug.Assert(ap[ap.Length - 1] == '"');     // last char is "

                    if (ap.Length <= 2)
                    {
                        // empty ap!
                        throw new Exception("LTL-Parse-Error: empty quoted string");
                    }


                    ap = ap.Substring(1, ap.Length - 2);     // cut quotes
                }
                else if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
                {
                    // nop
                }
                else
                {
                    throw new Exception("LTL-Parse-Error");
                }

                int ap_i;     // the AP index

                if (predefined_apset != null)
                {
                    if ((ap_i = predefined_apset.find(ap)) != -1)
                    {
                        return(new LTLNode(ap_i));
                    }
                    else
                    {
                        // not found in predefined APSet!
                        //std::cerr << "[" << (int)s[2] << "]" << std::endl;
                        throw new Exception("Can't parse formula with this APSet!");
                    }
                }
                else
                {
                    if ((ap_i = apset.find(ap)) != -1)
                    {
                        // AP exists already
                        return(new LTLNode(ap_i));
                    }
                    else
                    {
                        // create new AP
                        ap_i = apset.addAP(ap);
                        return(new LTLNode(ap_i));
                    }
                }
                break;


            default:
                break;
            }



            LTLNode newNode = new LTLNode(nodeType, TranslateLTL(CurrentNode.lft, apset, predefined_apset),
                                          TranslateLTL(CurrentNode.rgt, apset, predefined_apset));


            return(newNode);
        }
示例#4
0
 /**
  * Parse the formula and return an LTLFormula_ptr
  * @param formula the formula string
  * @param predefined_apset if specified, use this APSet and don't
  *                         add new atomic propositions
  * @return the LTLFormula_ptr
  */
 public static LTLFormula parse(ltl2ba.Node LTLHeadNode)
 {
     return(parse(LTLHeadNode, null));
 }