Ejemplo n.º 1
0
        private void Branch(Statement st, ref List <Solution> solution_list)
        {
            OrStmt os;

            os = st as OrStmt;
            List <Statement> body_list;

            // if left hand side is a block insert all the statements to the new body list
            if (os.Blhs != null)
            {
                body_list = ReplaceCurrentAtomic(os.Blhs);
                solution_list.Add(CreateTactic(body_list));
            }
            else // generate new updatestmt and insert it to body list
            {
                UpdateStmt lhs = GenUpdateStmt(os.Lhss as ApplySuffix);
                Contract.Assert(lhs != null);
                body_list = ReplaceCurrentAtomic(lhs);
                StatementRegister.Atomic type = StatementRegister.GetAtomicType(lhs);
                switch (type)
                {
                case StatementRegister.Atomic.ID:
                    solution_list.Add(CreateTactic(body_list, false));
                    return;

                case StatementRegister.Atomic.FAIL:
                    break;

                case StatementRegister.Atomic.UNDEFINED:
                //return "OR: undefined lhs statement";
                default:
                    solution_list.Add(CreateTactic(body_list));
                    break;
                }
            }

            if (os.Brhs != null)
            {
                body_list = ReplaceCurrentAtomic(os.Brhs);
                solution_list.Add(CreateTactic(body_list));
            }
            else
            {
                UpdateStmt rhs = GenUpdateStmt(os.Rhs as ApplySuffix);
                Contract.Assert(rhs != null);
                body_list = ReplaceCurrentAtomic(rhs);
                StatementRegister.Atomic type = StatementRegister.GetAtomicType(rhs);
                switch (type)
                {
                case StatementRegister.Atomic.ID:
                    break;

                case StatementRegister.Atomic.FAIL:
                    break;

                case StatementRegister.Atomic.UNDEFINED:
                //return "OR: undefined rhs statement";
                default:
                    solution_list.Add(CreateTactic(body_list));
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Parses the input for specified parent.
        /// </summary>
        /// <param name="parent">The parent.</param>
        /// <param name="input">The input.</param>
        /// <returns></returns>
        /// <exception cref="System.FormatException">
        /// Unexpected ']'!
        /// or
        /// Unexpected ')'!
        /// or
        /// Unexpected input:  + input + !
        /// </exception>
        private bool Parse(ref StatementBlock parent, ref string input)
        {
            if (string.IsNullOrEmpty(input))
            {
                return(false);
            }

            if (input[0] == '[')
            {
                var sb = new StatementRead();
                sb.Parent = parent;
                parent.Statements.Add(sb);
                parent = sb;

                input = input.Substring(1);
                return(true);
            }

            if (input[0] == ']')
            {
                if (parent == this.Root || !(parent is StatementRead))
                {
                    throw new FormatException("Unexpected ']'!");
                }
                var sb = parent;
                parent = parent.Parent;
                sb.Finish();
                input = input.Substring(1);
                return(true);
            }

            if (input[0] == '(')
            {
                var sb = new StatementGroup();
                sb.Parent = parent;
                parent.Statements.Add(sb);
                parent = sb;

                input = input.Substring(1);
                return(true);
            }

            if (input[0] == ')')
            {
                if (parent == this.Root || !(parent is StatementGroup))
                {
                    throw new FormatException("Unexpected ')'!");
                }
                var sb = parent;
                parent = parent.Parent;
                sb.Finish();
                input = input.Substring(1);
                return(true);
            }

            int       len     = 0;
            Statement created = StatementOperator.Create(input, ref len);

            if (created != null)
            {
                input = input.Substring(len);
                parent.Statements.Add(created);
                return(true);
            }

            created = StatementRegister.Create(input, ref len);
            if (created != null)
            {
                input = input.Substring(len);
                parent.Statements.Add(created);
                return(true);
            }

            created = StatementModule.Create(this.Modules, input, ref len);
            if (created != null)
            {
                input = input.Substring(len);
                parent.Statements.Add(created);
                return(true);
            }

            created = StatementConstant.Create(input, ref len);
            if (created != null)
            {
                input = input.Substring(len);
                parent.Statements.Add(created);
                return(true);
            }

            throw new FormatException("Unexpected input: " + input + "!");
        }