Пример #1
0
        //assigens value to variable
        static object Be_Fu(SymbolTable s)
        {
            if (!(s.GetVariable(new Id("~id")) is Id))
                throw new Exception("invalid ID");
            Id name = (s.GetVariable(new Id("id")) as Id);
            object value = s.GetVariable(new Id("~value"));

            while (value is Id)
                value = s.GetVariable(value as Id);
            //Console.WriteLine("variable \"" + name + "\" has been assigend with the value \"" + value.ToString() + "\"");
            return s.SetVariable(name, value);
        }
Пример #2
0
        //assigens value to variable
        static object Be_Fu(SymbolTable s)
        {
            if (!(s.GetVariable(new Id("~id")) is Id))
            {
                throw new Exception("invalid ID");
            }
            Id     name  = (s.GetVariable(new Id("id")) as Id);
            object value = s.GetVariable(new Id("~value"));

            while (value is Id)
            {
                value = s.GetVariable(value as Id);
            }
            //Console.WriteLine("variable \"" + name + "\" has been assigend with the value \"" + value.ToString() + "\"");
            return(s.SetVariable(name, value));
        }
Пример #3
0
        public object SetVariable(Id id, object value)
        {
            try {
                if (id.Length > 1)
                {
                    SymbolTable scope = (SymbolTable)this.GetVariable(new Id(id.Head));
                    id.Path.RemoveFirst();
                    return(scope.SetVariable(id, value));
                }

                _symbols[id.Head] = value;
                return(value);
            }
            catch {
                if (Perent == null)
                {
                    throw new Exception("Variable \"" + id + "\" is undefined");
                }
                return(this.Perent.SetVariable(id, value));
            }
        }