Example #1
0
 public static string CreateTempVariable(Env env)
 {
     temp = "T" + QTable.Count.ToString();
     env.DefineVariable(temp);
     env.AssignValue(temp, null);
     return temp;
 }
        public override EvaluationResult Evaluate(Env env)
        {
            //identifier.AssignValue(env, assignment.Evaluate(env));

            if (assignment.GetType().BaseType == typeof(BaseNumberExpression))
            {
                Enviroment2.QTable.Add(new Quadruple("=", assignment.Evaluate(env).Result, null, identifier.GetIdentifierSymbol()));
            }

            else
            {
                Enviroment2.QTable.Add(new Quadruple("=", Enviroment2.ReturnCurrentTempVariable(), null, identifier.GetIdentifierSymbol()));
            }
            return null;
        }
Example #3
0
        static void Main(string[] args)
        {
            #region QTable
            Console.WriteLine("Insert Expression: ");
            string expression = Console.ReadLine();
            Parser parser = new Parser();
            var lollipop = parser.Parse(expression) as BlockStatement;
            Env ambiente = new Env();
            MemoryStream stream = new MemoryStream();
            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(jaja));
            DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(Dictionary<string, string>));

            foreach (var item in lollipop.children)
            {
                item.Evaluate(ambiente);
            }

            //code
            jaja eljaja = new jaja(Enviroment2.QTable);
            ser.WriteObject(stream, eljaja);
            stream.Position = 0;
            StreamReader sr = new StreamReader(stream);
            string resultstring = sr.ReadToEnd();
            resultstring = resultstring.Substring(0, resultstring.Length - 1) + ", \"env\":{";

            foreach (var item in ambiente.variables)
            {
               if(item.Key[0]=='T')
                   resultstring += string.Format("{7}{0}{7}:{1}{7}{2}{7}:{7}{3}{7},{7}{4}{7}:{5}{6}{8}", item.Key, "{", "type", "int", "temp", "true", "}", "\"", ",");
               else
                   resultstring += string.Format("{7}{0}{7}:{1}{7}{2}{7}:{7}{3}{7},{7}{4}{7}:{5}{6}{8}", item.Key, "{", "type", "int", "temp", "false", "}", "\"", ",");
            }

            resultstring = resultstring.Substring(0, resultstring.Length - 1);
            resultstring += "}}";
            Console.WriteLine(resultstring);
            #endregion

            #region JSON
            var resultado= PostJSON(resultstring);
            Console.WriteLine(resultado);
            Console.ReadKey(true);
            #endregion
        }
Example #4
0
 public abstract EvaluationResult Evaluate(Env env);