private static Formule parseNode(Node n)
        {
            if(String.Equals(n.Name, "FORMULE"))
            {

                Node child1 = n.GetChildAt(0);
                List<Formule> list = new List<Formule>();

                if (String.Equals(child1.Name, "NOT"))
                {
                    if (n.GetChildAt(1).GetChildAt(0).Name == "PREDICAT") /* Le not s'applique seulement au predicat qui le suit */
                    {
                        Formule f = parseNode(n.GetChildAt(1));
                        return f.encapsuleNot();
                    }
                    else /* Le not s'applique sur tout le reste de la formule */
                    {
                        list.Add(parseNode(n.GetChildAt(1)));
                        return new Formule(Formule.Formule_Type.neg, "empty", list);
                    }
                }
                else if(String.Equals(child1.Name, "FORALL"))
                {
                    Node varNode = n.GetChildAt(1);
                    list.Add(new Formule(Formule.Formule_Type.variable, ""+formule_str[varNode.StartColumn-1], null));
                    list.Add(parseNode(n.GetChildAt(2)));
                    return new Formule(Formule.Formule_Type.forall, "empty", list);
                }
                else if(String.Equals(child1.Name, "EXISTS"))
                {
                    Node varNode = n.GetChildAt(1);
                    list.Add(new Formule(Formule.Formule_Type.variable, "" + formule_str[varNode.StartColumn-1], null));
                    list.Add(parseNode(n.GetChildAt(2)));
                    return new Formule(Formule.Formule_Type.exists, "empty", list);
                }
                else if(String.Equals(child1.Name, "PREDICAT"))
                {
                    Node pred = child1.GetChildAt(0);
                    Formule formPred = formuleFromPred(pred);

                    if(n.GetChildCount() == 1)
                    {
                        return formPred;
                    }
                    else
                    {
                        Node child2 = n.GetChildAt(1);
                        Node connecteur = child2.GetChildAt(0);
                        Formule.Formule_Type type;
                        if (String.Equals(connecteur.Name, "AND"))
                            type = Formule.Formule_Type.and;
                        else if (String.Equals(connecteur.Name, "OR"))
                            type = Formule.Formule_Type.or;
                        else /* IMPLY */
                            type = Formule.Formule_Type.impl;
                        list.Add(formPred);
                        list.Add(parseNode(child2.GetChildAt(1)));
                        return new Formule(type, "empty", list);
                    }
                }
                else /* equals "(" */
                {
                    Node child3 = n.GetChildAt(2);
                    Node connecteur = child3.GetChildAt(0);

                    if(connecteur.Name == "RIGHT_PAREN")
                    {
                        return parseNode(n.GetChildAt(1));
                    }
                    /* Si connecteur */
                    Formule.Formule_Type type;
                    if (String.Equals(connecteur.Name, "AND"))
                        type = Formule.Formule_Type.and;
                    else if (String.Equals(connecteur.Name, "OR"))
                        type = Formule.Formule_Type.or;
                    else /* IMPLY */
                        type = Formule.Formule_Type.impl;
                    list.Add(parseNode(n.GetChildAt(1)));
                    list.Add(parseNode(child3.GetChildAt(1)));
                    return new Formule(type, "empty", list);
                }
            }
            Console.WriteLine("Erreur cas inconnu FormuleFactory");
            return null;
        }
Exemple #2
0
        public STObject GetWordArrayLiteral(Node literal)
        {
            // word_array = '#' '('
            //	 ( IDENT | STRING | NUM | CHAR | '#' ( IDENT | word_array ) )
            // ')' ;

            List<object> values = new List<object>();
            for (int i = 2, max = literal.GetChildCount() - 1; i < max; ++i) {
                Node child = literal.GetChildAt(i);

                if (child.Name == "IDENT")
                    values.Add (STSymbol.Get((child as Token).Image));
                else if (child.Name == "STRING")
                    values.Add (GetStringLiteral(child as Token));
                else if (child.Name == "NUM")
                    values.Add (GetNumberLiteral(child as Token));
                else if (child.Name == "CHAR")
                    values.Add (GetCharLiteral(child as Token));
                else if (child.Name == "HASH") {
                    child = literal.GetChildAt(++i);
                    if (child.Name == "IDENT")
                        values.Add (STSymbol.Get((child as Token).Image));
                    else if (child.Name == "word_array")
                        values.Add (GetWordArrayLiteral(child));
                    else
                        throw new Exception ("Unhandled path in grammar");
                } else
                    throw new Exception ("Unhandled path in grammar");
            }

            return new Irontalk.Array(values.ToArray());
        }
Exemple #3
0
        public STObject EvaluateExpression(Node expression, Context context)
        {
            STObject receiver = EvaluateReceiver (expression.GetChildAt(0), context);

            for (int i = 1, max = expression.GetChildCount(); i < max; ++i) {
                receiver = EvaluateSend(receiver, expression.GetChildAt(i), context);
            }

            receiver = receiver.Dereference();

            return receiver;
        }
Exemple #4
0
        public STObject EvaluateKeywordSend(STObject receiver, Node keywordSend, Context context)
        {
            receiver = receiver.Dereference();
            // keyword_send		= ( KEYWORD receiver simple_send* )+;
            string keyword = null;
            STObject parm = null;
            StringBuilder selectorBuffer = new StringBuilder();
            List<STObject> parms = new List<STObject>();

            for (int i = 0, max = keywordSend.GetChildCount(); i < max; ++i) {
                var item = keywordSend.GetChildAt(i);
                if (item.Name == "KEYWORD") {
                    if (keyword != null) {
                        selectorBuffer.Append(keyword);
                        parms.Add (parm);
                    }

                    keyword = (item as Token).Image;
                    parm = EvaluateReceiver(keywordSend.GetChildAt(++i), context).Dereference();
                } else if (item.Name == "simple_send") {
                    parm = EvaluateSimpleSend(parm, item, context);
                }
            }

            selectorBuffer.Append(keyword);
            parms.Add (parm);
            STSymbol selector = STSymbol.Get(selectorBuffer.ToString());

            return receiver.Send(selector, parms.ToArray());
        }
Exemple #5
0
        public STObject EvaluateBinarySend(STObject receiver, Node binarySend, Context context)
        {
            STObject other = EvaluateReceiver(binarySend.GetChildAt(1), context).Dereference();
            receiver = receiver.Dereference();

            for (int i = 2, max = binarySend.GetChildCount(); i < max; ++i)
                other = EvaluateUnarySend(other, binarySend.GetChildAt(i), context);
            return receiver.Send(STSymbol.Get((binarySend.GetChildAt(0) as Token).Image), other);
        }