예제 #1
0
        //When a variable is deleted.
        public override object VisitStat_deletevar([NotNull] algoParser.Stat_deletevarContext context)
        {
            //Checking if the disregard wants to delete all variables or only one.
            if (context.IDENTIFIER() != null)
            {
                //Get variable name.
                string varname = Particles.StitchVariableName(context, context.IDENTIFIER().GetText(), context.particle());

                //Check if variable exists.
                if (!Scopes.VariableExists(varname))
                {
                    //Maybe it's a library?
                    if (Scopes.LibraryExists(varname))
                    {
                        //Okay, just disregard the library.
                        Scopes.RemoveLibrary(varname);
                        return(null);
                    }

                    //Not a library, so doesn't exist.
                    Error.Fatal(context, "Invalid variable name given to disregard.");
                    return(null);
                }

                //Remove variable.
                Scopes.RemoveVariable(varname);
            }
            else
            {
                //Reset all scopes.
                Scopes.Reset();
            }

            return(null);
        }