Exemple #1
0
        public void PFormula(ref string s, out Node D) // операции отношения
        {
            s = s.Trim();
            if (s.Length != 0)
            {
                Expression(ref s, out D);
                s = s.Trim();
                Operation chRelation = SetChRelation(s);
                if (chRelation != Operation.NONE)
                {
                    switch (chRelation)
                    {
                    case Operation.LESS:
                    case Operation.MORE:
                        Pop(ref s, 1); break;

                    case Operation.EQUALLY:
                    case Operation.NOTEQUALLY:
                    case Operation.LESSEQUALLY:
                    case Operation.MOREEQUALLY:
                        Pop(ref s, 2);
                        break;
                    }
                    Node D2;
                    Expression(ref s, out D2);
                    Node D1 = D;
                    D = new NodeOperation(chRelation, D1, D2);
                }
            }
            else
            {
                D = null; throw new NodeException(5, "ошибка в операциях отношения");
            }
        }
Exemple #2
0
        public void Expression(ref string s, out Node D) // + - |
        {
            s = s.Trim();
            if (s.Length != 0)
            {
                string sign = "+";
                if ((Peek(ref s) == '+') | (Peek(ref s) == '-'))
                {
                    sign = Pop(ref s, 1);
                }
                Term(ref s, out D);
                if (sign == "-")
                {
                    Node D1 = D;
                    Node D2 = D1;
                    D = new NodeFunc(7, D1, D2);
                }
                s = s.Trim();
                while ((s.Length > 0) && ((Peek(ref s) == '+') | (Peek(ref s) == '-') | (Peek(ref s) == '|')))
                {
                    sign = Pop(ref s, 1);
                    if (s.Length != 0)
                    {
                        if ((Peek(ref s) == '+') | (Peek(ref s) == '-') | (Peek(ref s) == '|'))
                        {
                            throw new NodeException(7, "лишний знак");
                        }
                    }
                    else
                    {
                        throw new NodeException(7, "после знака ничего не оказалось");
                    }
                    Node D2;
                    Term(ref s, out D2);
                    Node D1 = D;

                    Operation t = Operation.PLUS;
                    switch (sign[0])
                    {
                    case '+': t = Operation.PLUS; break;

                    case '-': t = Operation.MINUS; break;

                    case '|': t = Operation.OR; break;
                    }
                    D = new NodeOperation(t, D1, D2);
                }
            }
            else
            {
                D = null; throw new NodeException(6, "нехватка данных");
            }
        }
Exemple #3
0
        void Term(ref string s, out Node D) // * / & ^
        {
            s = s.Trim();
            if (s.Length != 0)
            {
                Factor(ref s, out D);
                while ((s.Length != 0) && ((Peek(ref s) == '*') | (Peek(ref s) == '/') | (Peek(ref s) == '&') | (Peek(ref s) == '^')))
                {
                    string znak = Pop(ref s, 1);
                    if (s.Length == 0)
                    {
                        throw new NodeException(8, "после знака ничего не оказалось");
                    }
                    Node D2;
                    Factor(ref s, out D2);
                    Node D1 = D;

                    Operation t = Operation.MULTIPLY;
                    switch (znak)
                    {
                    case "*": t = Operation.MULTIPLY; break;

                    case "/": t = Operation.DIVIDE; break;

                    case "&": t = Operation.AND; break;

                    case "^": t = Operation.POWER; break;
                    }
                    D = new NodeOperation(t, D1, D2);
                }
            }
            else
            {
                D = null; throw new NodeException(8, "нехватка данных");
            }
        }