Beispiel #1
0
        /// <summary>
        /// Creates an expression quadruple.
        /// </summary>
        /// <param name="operators">Operators.</param>
        private static void CreateExpressionQuadruple(
            Operators[] operators)
        {
            // Get index of fake bottom
            int index = (hierarchyStack.Count > 0) ? hierarchyStack.Peek() : 0;

            if (operatorStack.Count > index &&
                operators.Contains(operatorStack.Peek()))
            {
                // Pop types
                GraphicFooType t2 = typeStack.Pop();
                GraphicFooType t1 = typeStack.Pop();

                if (t1 != GraphicFooType.Invalid &&
                    t2 != GraphicFooType.Invalid)
                {
                    // Pop operands
                    string id2 = operandStack.Pop();
                    string id1 = operandStack.Pop();

                    // Find variables
                    Variable v1 = ProgramMemory.FindVariable(scope, id1);
                    Variable v2 = ProgramMemory.FindVariable(scope, id2);

                    // Pop operator
                    Operators op = operatorStack.Pop();

                    // Check association rules
                    GraphicFooType resultingType =
                        AssociationRules.GetOperationType(op, t1, t2);

                    // Create new temporary variable
                    Variable temp;
                    if (scope == null)
                    {
                        temp = ProgramMemory.AddGlobalTemporary(resultingType);
                    }
                    else
                    {
                        temp = scope.AddTemporaryVariable(resultingType);
                    }
                    // Push temp
                    operandStack.Push(temp.name);
                    typeStack.Push(temp.type);

                    // Create quadruple
                    Quadruple qudruple = new Quadruple(
                        op,
                        v1,
                        v2,
                        temp
                        );
                    PushQuadruple(qudruple);
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// Initialize this instance.
 /// </summary>
 public static void Initialize()
 {
     // Stacks
     operandStack   = new Stack <string> ();
     typeStack      = new Stack <GraphicFooType> ();
     operatorStack  = new Stack <Operators> ();
     hierarchyStack = new Stack <int> ();
     jumpStack      = new Stack <int> ();
     quadruples     = new Dictionary <int, Quadruple> ();
     AssociationRules.Initialize();
 }