Пример #1
0
        public static void parseFile(Token token, EnegyData data, VariabelDatabase db)
        {
            if (parsers == null)
                setParser();

            token.next();
            while(data.State == RunningState.Normal && token.getCache().type() != TokenType.EOF)
            {
                ParserInterface p;

                switch (token.getCache().type())
                {
                    case TokenType.Use:
                    case TokenType.Class:
                    case TokenType.Function:
                        p = parsers[token.getCache().type()];
                        break;
                    case TokenType.Public:
                        p = pp;
                        break;
                    default:
                        data.setError(new ScriptError("In file you are only allow to use 'use', 'public', 'class' or 'function'", token.getCache().posision()), db);
                        return;
                }

                p.parse(data, db, token);
            }
        }
Пример #2
0
        public static CVar convert(object c, EnegyData data, VariabelDatabase db)
        {
            if (c is string)
            {
                return Types.toString((string)c, data, db, new Posision(0,0));
            }
            else if (c is bool)
            {
                return new BooleanVariabel((bool)c);
            }
            else if (c is FunctionVariabel)
            {
                return (FunctionVariabel)c;
            }
            else if (c is double)
            {
                return Types.toInt((double)c, data, db, new Posision(0,0));
            }
            else if (c is int)
            {
                return Types.toInt(Convert.ToDouble((int)c), data, db, new Posision(0,0));
            }
            else if (c is ObjectVariabel)
                return (ObjectVariabel)c;
            else if(c is ClassVariabel)
            {
                return (ClassVariabel)c;
            }

            data.setError(new ScriptError("Unkown type: " + c.GetType().Name, new Posision(0, 0)), db);
            return new NullVariabel();
        }
Пример #3
0
        public void controleOveride(string name, EnegyData data)
        {
            if (!global.ContainsKey(name))
                return;

            CVar var = global[name];
            data.setError(new ScriptError("You can´t convert " + name + " becuse it is " + var.type(), new Posision(0, 0)), this);
        }
Пример #4
0
        public static int getAgumentSize(EnegyData data)
        {
            int size;

            if(int.TryParse(data.Config.get("agument.buffer.size", "20"), out size))
            {
                return size;
            }

            return 20;
        }
Пример #5
0
        public Energy()
        {
            Data = new EnegyData()
            {
                Config = new ScriptConfig()
            };

            //set the impontans config so the script not can change it!
            Data.Config.append("tcp.enable",         "false", false);
            Data.Config.append("file.system.enable", "false", false);

            VariabelDatabase = new VariabelDatabase();
            StartItems.CreateStartItems(Data, VariabelDatabase);
        }
Пример #6
0
        public static void parse(Token token, EnegyData data, VariabelDatabase db)
        {
            if(parsers == null)
            {
                setParser();
            }

            token.next();
            TokenType type;
            while (data.State == RunningState.Normal && (type = token.getCache().type()) != TokenType.EOF)
            {
                if (parsers.ContainsKey(type))
                {
                    parsers[type].parse(data, db, token);
                }
                else
                {
                    new VariabelParser().parse(data, db, token);
                }
            }
        }
Пример #7
0
 private static CVar Print_call(CVar[] stack, VariabelDatabase db, EnegyData data, Posision pos)
 {
     Console.WriteLine(stack[0].toString(pos, data, db));
     return null;
 }
Пример #8
0
        private static CVar Useage_call(CVar[] stack, VariabelDatabase db, EnegyData data, Posision pos)
        {
            Console.WriteLine("----container----");
            foreach(string co in db.ContainerKeys())
            {
                Console.WriteLine("-" + co);
            }

            Console.WriteLine("------Global-----");
            foreach(string go in db.GlobalsKey())
            {
                Console.WriteLine("-" + go);
            }

            return new NullVariabel();
        }
Пример #9
0
 public void pushFunction(Function function, EnegyData data)
 {
     controleOveride(function.Name, data);
     global.Add(function.Name, new FunctionVariabel(function));
     garbageContainer.Add(function.Name);
 }
Пример #10
0
 public void pushClass(Class c, EnegyData data)
 {
     controleOveride(c.GetContainer().Name, data);
     types.Add(c.GetContainer().Name);//now is this class a types :)
     garbageType.Add(c.GetContainer().Name);
     global.Add(c.GetContainer().Name, new ClassVariabel(c));
     garbageContainer.Add(c.GetContainer().Name);
 }
Пример #11
0
 public CVar push(string name, CVar variabel, EnegyData data)
 {
     controleOveride(name, data);
     if (container.ContainsKey(name)) container.Remove(name);
     container.Add(name, variabel);
     return variabel;
 }
Пример #12
0
        public CVar get(string name, EnegyData data)
        {
            if (global.ContainsKey(name))
                return global[name];

            if (container.ContainsKey(name))
                return container[name];

            data.setError(new ScriptError("Unknown variabel: " + name, new Posision(0, 0)), this);
            return new NullVariabel();
        }