コード例 #1
0
        public override EvaluationResult Evaluate(Env env)
        {
            string value = string.Empty;

            if (initialization.GetType().BaseType == typeof(BaseBinaryExpression))
            {
                initialization.Evaluate(env);
                value = Enviroment2.ReturnCurrentTempVariable();
            }

            else if (initialization.GetType().BaseType == typeof(BaseNumberExpression))
            {
                BaseNumberExpression numberExpression = initialization as BaseNumberExpression;
                value = numberExpression.GetNumber();
            }

            else
            {
                BaseIdentifierExpression identifierExpression = initialization as BaseIdentifierExpression;
                value = identifierExpression.GetIdentifierSymbol();
            }

            var symbol = identifier.GetIdentifierSymbol();

            env.DefineVariable(symbol);
            env.AssignValue(symbol, value);
            Enviroment2.QTable.Add(new Quadruple("=", value, null, symbol));
            return(null);
        }
コード例 #2
0
        private string ObtenerArgumentoTempUno(Env env)
        {
            string temp = string.Empty;

            if (Condition.Left.GetType().BaseType == typeof(BaseBinaryExpression))
            {
                Condition.Left.Evaluate(env);
                temp = Enviroment2.ReturnCurrentTempVariable();
            }
            else if (Condition.Left.GetType().BaseType == typeof(BaseNumberExpression))
            {
                BaseNumberExpression numberExpression = Condition.Left as BaseNumberExpression;
                temp = numberExpression.GetNumber();
            }
            else
            {
                BaseIdentifierExpression identifier = Condition.Left as BaseIdentifierExpression;
                temp = identifier.GetIdentifierSymbol();
            }

            return(temp);
        }
コード例 #3
0
        public override EvaluationResult Evaluate(Env env)
        {
            string argumento1Temp, argumento2Temp;

            if (Condition.Left.GetType().BaseType == typeof(BaseBinaryExpression))
            {
                Condition.Left.Evaluate(env);
                argumento1Temp = Enviroment2.ReturnCurrentTempVariable();
            }
            else if (Condition.Left.GetType().BaseType == typeof(BaseNumberExpression))
            {
                BaseNumberExpression numberExpression = Condition.Left as BaseNumberExpression;
                argumento1Temp = numberExpression.GetNumber();
            }
            else
            {
                BaseIdentifierExpression identifier = Condition.Left as BaseIdentifierExpression;
                argumento1Temp = identifier.GetIdentifierSymbol();
            }

            //optener argumento 2
            if (Condition.Right.GetType().BaseType == typeof(BaseBinaryExpression))
            {
                Condition.Right.Evaluate(env);
                argumento2Temp = Enviroment2.ReturnCurrentTempVariable();
            }
            else if (Condition.Right.GetType().BaseType == typeof(BaseNumberExpression))
            {
                BaseNumberExpression numberExpression = Condition.Right as BaseNumberExpression;
                argumento2Temp = numberExpression.GetNumber();
            }
            else
            {
                BaseIdentifierExpression identifier = Condition.Right as BaseIdentifierExpression;
                argumento2Temp = identifier.GetIdentifierSymbol();
            }

            //crear ontrue para generar siguiente instruccion
            string Operator = "if" + Condition.RELOP;

            Enviroment2.QTable.Add(new Quadruple(Operator, argumento1Temp, argumento2Temp, (Enviroment2.QTable.Count + 2).ToString()));
            Enviroment2.QTable.Add(new Quadruple("goto", null, null, null));
            int indexOfGoto = Enviroment2.QTable.Count - 1; // guardar la posicion del goto (else,final);

            // generar ontrue
            OnTrue.Evaluate(env);
            if (OnFalse == null)
            {
                Enviroment2.QTable[indexOfGoto].result = (Enviroment2.QTable.Count.ToString());// + 1).ToString()
            }
            if (OnFalse != null)
            {
                Enviroment2.QTable[indexOfGoto].result = (Enviroment2.QTable.Count + 1).ToString();// + 1).ToString()
                Enviroment2.QTable.Add(new Quadruple("goto", null, null, null));
                int indexOfGoto2 = Enviroment2.QTable.Count - 1;
                OnFalse.Evaluate(env);
                Enviroment2.QTable[indexOfGoto2].result = Enviroment2.QTable.Count.ToString();
            }

            return(null);
        }