Exemple #1
0
        public override void EnterVar_decl([NotNull] GrammarParser.Var_declContext context)
        {
            var variableName = context.GetChild(1).GetText();
            var expression   = context.GetChild(3).GetText();

            Console.WriteLine(context.GetChild(3).GetText());

            if (!LookUpScope(variableName))
            {
                currentScope.SymbolTable.Add(variableName, expression);
            }
            else
            {
                throw new Exception("Variable already exists in local or parent scopes!");
            }

            base.EnterVar_decl(context);
        }
        public override bool VisitVar_decl([NotNull] GrammarParser.Var_declContext context)
        {
            Console.WriteLine("Variable Declaration ");
            DataTable dt = new DataTable();



            string expression = context.GetChild(3).GetText();

            expression = SearchAndReplace(expression);


            /*
             * if ((!MainScopeClass.MainScope.ContainsKey(context.GetChild(1).GetText())))
             * {
             *  if ((!MainScopeClass.MainScope.ContainsKey(context.GetChild(1).GetText())))
             *   {
             *      MainScopeClass.MainScope.Add(context.GetChild(1).GetText(), dt.Compute(expression, ""));
             *      Console.WriteLine($"HERE: {context.GetChild(1).GetText()} {dt.Compute(expression, "")}");
             *   }
             *  else
             *          {
             *      //Something
             *
             *          }
             *
             * }
             * else
             * {
             *  throw new Exception("Variable already exists!");
             * }
             */
            if (scopeCount != 0)
            {
                scopeCount--;
            }
            if (scopeCount == 0)
            {
                //Something?
            }


            return(base.VisitVar_decl(context));
        }