Beispiel #1
0
    void CreateOrRecipe(Expression left, Expression right)
    {
        OrExpressionComposite new_or = new OrExpressionComposite();

        new_or.left  = left;
        new_or.right = right;

        AddRecipe(new_or);

        //Debug.Log ("Rule created: " + new_and.ToString());
    }
Beispiel #2
0
    public static void LoadRules(List <Rule> Rules, TextAsset content)
    {
        using (StringReader reader = new StringReader(content.text))
        {
            //Debug.Log ("#Arquivo OK");
            //Leitura---------------------------------------
            string line;
            while ((line = reader.ReadLine()) != null)
            {
                // Do something with the line.
                string[] parts = line.Split(' ');
                if (parts[0] == "#RULE" || parts[0] == "#Rule")
                {
                    List <Expression> list_exp = new List <Expression>();

                    for (int i = 3; i < parts.Length; i++)
                    {
                        if (parts[i] == "+")
                        {
                            AndExpressionComposite aux_and = new AndExpressionComposite();
                            if (parts[i - 1] != ")")
                            {
                                Number numb_aux = new Number();
                                numb_aux.value = System.Convert.ToInt32(parts[i - 1]);
                                aux_and.left   = numb_aux;
                            }
                            if (parts[i + 1] != "(")
                            {
                                Number numb_aux = new Number();
                                numb_aux.value = System.Convert.ToInt32(parts[i + 1]);
                                aux_and.right  = numb_aux;
                            }
                            list_exp.Add(aux_and);
                        }

                        if (parts[i] == "|")
                        {
                            OrExpressionComposite aux_or = new OrExpressionComposite();
                            if (parts[i - 1] != ")")
                            {
                                Number numb_aux = new Number();
                                numb_aux.value = System.Convert.ToInt32(parts[i - 1]);
                                aux_or.left    = numb_aux;
                            }
                            if (parts[i + 1] != "(")
                            {
                                Number numb_aux = new Number();
                                numb_aux.value = System.Convert.ToInt32(parts[i + 1]);
                                aux_or.right   = numb_aux;
                            }
                            list_exp.Add(aux_or);
                        }

                        if (parts[i] == "=")
                        {
                            ImplicationExpressionComposite aux_imp = new ImplicationExpressionComposite();
                            if (parts[i - 1] != ")")
                            {
                                Number numb_aux = new Number();
                                numb_aux.value = System.Convert.ToInt32(parts[i - 1]);
                                aux_imp.left   = numb_aux;
                            }
                            list_exp.Add(aux_imp);
                        }
                    }


                    int Index_list = 0;
                    for (int i = 3; i < parts.Length; i++)
                    {
                        if (parts[i] == "+")
                        {
                            AndExpressionComposite aux_and = (AndExpressionComposite)list_exp[Index_list];
                            if (parts[i - 1] == ")")
                            {
                                aux_and.left = list_exp[Index_list - 1];
                            }
                            if (parts[i + 1] == "(")
                            {
                                aux_and.right = list_exp[Index_list + 1];
                            }
                            Index_list++;
                        }

                        if (parts[i] == "|")
                        {
                            OrExpressionComposite aux_or = new OrExpressionComposite();
                            if (parts[i - 1] == ")")
                            {
                                aux_or.left = list_exp[Index_list - 1];
                            }
                            if (parts[i + 1] == "(")
                            {
                                aux_or.right = list_exp[Index_list + 1];
                            }
                            Index_list++;
                        }

                        if (parts[i] == "=")
                        {
                            ImplicationExpressionComposite aux_imp = (ImplicationExpressionComposite)list_exp[Index_list];
                            if (parts[i - 1] == ")")
                            {
                                aux_imp.left = list_exp[Index_list - 1];
                            }
                            Number res_aux = new Number();
                            int    bla     = System.Convert.ToInt32(parts[i + 1]);
                            res_aux.value = bla;
                            aux_imp.right = res_aux;
                            Index_list++;
                        }
                    }
                    Rule aux_rule = new Rule(parts[1], (ImplicationExpressionComposite)list_exp[list_exp.Count - 1], System.Convert.ToInt32(parts[2]));
                    Rules.Add(aux_rule);
                }
            }
        }
    }
Beispiel #3
0
        public static Expression ImterpretaString(string line, List <Rule> Rules)
        {
            Expression aux_exp = null;

            string[] parts = line.Split(' ');

            if (parts[0] == "#RULE" || parts[0] == "#Rule" || parts[0] == "#R" || parts[0] == "#r")
            {
                for (int i = 2; i < parts.Length; i++)
                {
                    if (parts[i] == "+")
                    {
                        AndExpressionComposite aux_and = new AndExpressionComposite();
                        if (parts[i - 1].Length == 1)
                        {
                            Number numb_aux = new Number();
                            numb_aux.value = System.Convert.ToInt32(parts[i - 1]);
                            aux_and.left   = numb_aux;
                        }
                        else
                        {
                            foreach (Rule rule in Rules)
                            {
                                if (parts[i - 1] == rule.Name)
                                {
                                    aux_and.left = rule.Expression;
                                    break;
                                }
                            }
                        }
                        if (parts[i + 1].Length == 1)
                        {
                            Number numb_aux = new Number();
                            numb_aux.value = System.Convert.ToInt32(parts[i + 1]);
                            aux_and.right  = numb_aux;
                        }
                        else
                        {
                            foreach (Rule rule in Rules)
                            {
                                if (parts[i + 1] == rule.Name)
                                {
                                    aux_and.right = rule.Expression;
                                    break;
                                }
                            }
                        }
                        aux_exp = aux_and;
                    }

                    if (parts[i] == "|")
                    {
                        OrExpressionComposite aux_or = new OrExpressionComposite();
                        if (parts[i - 1] != ")")
                        {
                            Number numb_aux = new Number();
                            numb_aux.value = System.Convert.ToInt32(parts[i - 1]);
                            aux_or.left    = numb_aux;
                        }
                        if (parts[i + 1] != "(")
                        {
                            Number numb_aux = new Number();
                            numb_aux.value = System.Convert.ToInt32(parts[i + 1]);
                            aux_or.right   = numb_aux;
                        }
                        aux_exp = aux_or;
                    }

                    if (parts[i] == "=")
                    {
                        ImplicationExpressionComposite aux_imp = new ImplicationExpressionComposite();
                        if (parts[i - 1].Length == 1)
                        {
                            Number numb_aux = new Number();
                            numb_aux.value = System.Convert.ToInt32(parts[i - 1]);
                            aux_imp.left   = numb_aux;
                        }
                        else
                        {
                            foreach (Rule rule in Rules)
                            {
                                if (parts[i - 1] == rule.Name)
                                {
                                    aux_imp.left = rule.Expression;
                                    break;
                                }
                            }
                        }
                        if (parts[i + 1].Length >= 1)
                        {
                            Number numb_aux = new Number();
                            numb_aux.value = System.Convert.ToInt32(parts[i + 1]);
                            aux_imp.right  = numb_aux;
                        }
                        aux_exp = aux_imp;
                    }
                }
            }
            return(aux_exp);
        }