Beispiel #1
0
        /// <summary>
        /// primitive value of one level expression could be split into sequence of operations regarding operator priorities
        /// results are stored into Level.m_operations
        /// </summary>
        /// <param name="level">level to work with</param>
        private static void TraceLevel(Level level)
        {
            List <string>            levelsTrace         = new List <string>();
            Dictionary <int, string> operationByPriority = new Dictionary <int, string> {
                { 2, "+-><=" }, { 1, "&" }, { 0, "|" }
            };
            int operationCounter = 0;

            foreach (int priority in operationByPriority.Keys)
            {
                for (int i = 1; i + 1 < level.PrimitiveValue.Length; i++)
                {
                    if (operationByPriority[priority].Contains(level.PrimitiveValue[i]))
                    {
                        string leftIntersection, rightIntersection;
                        level.IntersectionToOperation(i, out leftIntersection, out rightIntersection);
                        PrimitiveOperation operation = new PrimitiveOperation
                        {
                            Start = i - (leftIntersection == "" ? DistanceToLeftOperation(level.PrimitiveValue, i) : leftIntersection.Length),
                            End   = i + (rightIntersection == "" ? DistanceToRightOperation(level.PrimitiveValue, i) : rightIntersection.Length)
                        };

                        operation.Value           = level.PrimitiveValue.Substring(operation.Start, operation.End - operation.Start + 1);
                        operation.SequentalNumber = operationCounter++;

                        level.AddOperation(operation);
                    }
                }
            }

            //// development check
            //Console.WriteLine("for level {0} we have the sequence: ", level.Value);
            //foreach (var operation in level.OperationSequence())
            //{
            //	Console.WriteLine(operation.Value);
            //}
        }
Beispiel #2
0
 public void AddOperation(PrimitiveOperation operation)
 {
     m_operations.Add(operation);
 }
        /// <summary>
        /// primitive value of one level expression could be split into sequence of operations regarding operator priorities
        /// results are stored into Level.m_operations
        /// </summary>
        /// <param name="level">level to work with</param>
        private static void TraceLevel(Level level)
        {
            List<string> levelsTrace = new List<string>();
            Dictionary<int, string> operationByPriority = new Dictionary<int, string> { { 2, "+-><=" }, { 1, "&" }, { 0, "|" } };
            int operationCounter = 0;
            foreach (int priority in operationByPriority.Keys)
            {
                for (int i = 1; i + 1 < level.PrimitiveValue.Length; i++)
                {
                    if (operationByPriority[priority].Contains(level.PrimitiveValue[i]))
                    {
                        string leftIntersection, rightIntersection;
                        level.IntersectionToOperation(i, out leftIntersection, out rightIntersection);
                        PrimitiveOperation operation = new PrimitiveOperation
                        {
                            Start = i - (leftIntersection == "" ? DistanceToLeftOperation(level.PrimitiveValue, i) : leftIntersection.Length),
                            End = i + (rightIntersection == "" ? DistanceToRightOperation(level.PrimitiveValue, i) : rightIntersection.Length)
                        };

                        operation.Value = level.PrimitiveValue.Substring(operation.Start, operation.End - operation.Start + 1);
                        operation.SequentalNumber = operationCounter++;

                        level.AddOperation(operation);
                    }
                }
            }

            //// development check
            //Console.WriteLine("for level {0} we have the sequence: ", level.Value);
            //foreach (var operation in level.OperationSequence())
            //{
            //	Console.WriteLine(operation.Value);
            //}
        }