Exemplo n.º 1
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);
        }
Exemplo n.º 2
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;
        }