示例#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 CVar parse(EnegyData ed, VariabelDatabase db, Token token)
        {
            if (token.next().type() != TokenType.LeftBue)
                ed.setError(new ScriptError("Missing ( after while", token.getCache().posision()), db);

            TokenCache scope = ScopeParser.getScope(token, ed, db);
            ArrayList body = BodyParser.parse(token, ed, db);
            token.next();

            //run the code until a boolean false i hit :)
            while (ed.State == RunningState.Normal && new VariabelParser().parseNoEnd(ed, db, scope).toBoolean(new Posision(0, 0), ed, db))
            {
                Interprenter.parse(new TokenCache(body, ed, db), ed, db);
                if(ed.State == RunningState.Continue)
                {
                    ed.setNormal();
                }else if(ed.State == RunningState.Break)
                {
                    ed.setNormal();
                    break;
                }
            }

            return new NullVariabel();
        }
示例#3
0
 private bool build(Token token, EnegyData data)
 {
     //here wee control if it private or public. protected is comming when class system is builder more avancrede
     if (token.getCache().type() == TokenType.Public)
     {
         token.next();
         return isStatic(ClassItemAccessLevel.Public, token, data);
     }
     else if (token.getCache().type() == TokenType.Private)
     {
         token.next();
         return isStatic(ClassItemAccessLevel.Private, token, data);
     }
     else if (token.getCache().type() == TokenType.Protected)
     {
         token.next();
         return isStatic(ClassItemAccessLevel.Protected, token, data);
     }
     else if (token.getCache().type() == TokenType.Variabel && token.getCache().ToString() == builder.GetContainer().Name)
     {
         return buildConstructor(token, data);
     }
     else
     {
         return isStatic(ClassItemAccessLevel.Public, token, data);
     }
 }
示例#4
0
        public static AgumentStack parseAguments(Token token, VariabelDatabase database, EnegyData data)
        {
            hasDefault = false;//be sure :)
            AgumentStack agument = new AgumentStack();
            if(token.getCache().type() != TokenType.LeftBue)
            {
                data.setError(new ScriptError("Excpect ( got: " + token.getCache().ToString(), token.getCache().posision()), database);
                return null;
            }

            //control if wee need to look and parse aguments :)
            if(token.next().type() != TokenType.RightBue)
            {
                //wee need :)
                if (!getSingleAguments(token, agument, database, data))
                    return new AgumentStack();
                while(token.getCache().type() == TokenType.Comma)
                {
                    token.next();
                    if (!getSingleAguments(token, agument, database, data))
                        return new AgumentStack();
                }
            }

            //control wee got to )
            if(token.getCache().type() != TokenType.RightBue)
            {
                data.setError(new ScriptError("Missing ) after function aguments got: " + token.getCache().ToString(), token.getCache().posision()), database);
                return new AgumentStack();
            }

            return agument;
        }
示例#5
0
        private void UnsetNext(Token token, EnegyData data, VariabelDatabase db)
        {
            if(token.next().type() != TokenType.Variabel)
            {
                data.setError(new ScriptError("Missing variabel in 'unset' statmenet", token.getCache().posision()), db);
                return;
            }

            //control wee has the variabel in the variabel database.
            if (!db.isExists(token.getCache().ToString()))
            {
                data.setError(new ScriptError("Unknown variabel: " + token.getCache().ToString(), token.getCache().posision()), db);
                return;
            }

            //is this variabel a global.
            if (!db.allowedOveride(token.getCache().ToString()))
            {
                data.setError(new ScriptError("You can not unset the variabel: " + token.getCache().ToString(), token.getCache().posision()), db);
                return;
            }

            //unset the variabel.
            db.removeVariabel(token.getCache().ToString());
        }
示例#6
0
        public static TokenCache getScope(Token token, EnegyData data, VariabelDatabase db)
        {
            ArrayList cache = new ArrayList();
            TokenBuffer buffer;

            int happens = 1;

            while((buffer = token.next()).type() != TokenType.EOF)
            {
                if (buffer.type() == TokenType.RightBue)
                {
                    happens--;
                    if (happens == 0)
                        return new TokenCache(cache, data, db);

                    cache.Add(buffer);
                    continue;
                }
                else if (buffer.type() == TokenType.LeftBue)
                    happens++;

                cache.Add(buffer);
            }

            data.setError(new ScriptError("Missing ) ", token.getCache().posision()), db);
            return new TokenCache(new ArrayList(), data, db);
        }
示例#7
0
 public CVar parse(EnegyData ed, VariabelDatabase db, Token token)
 {
     this.token = token;
     this.ed = ed;
     this.db = db;
     begin(false);
     return null;
 }
示例#8
0
 private bool buildBody(ClassItemAccessLevel level, bool isStatic, Token token, EnegyData data)
 {
     if (token.getCache().type() == TokenType.Function) //it is a function :)
     {
         token.next();
         return buildMethod(level, isStatic, token, data);
     }else
         return buildVariabel(level, isStatic, token, data);
 }
示例#9
0
 private bool buildConstructor(Token token, EnegyData data)
 {
     Method cm = new Method(null);
     token.next();
     cm.SetAgumentStack(AgumentParser.parseAguments(token, db, data));
     cm.SetBody(new CallScriptMethod(cm.GetAgumentStack(), BodyParser.parse(token, data, db)).call);
     cm.SetVariabel();
     builder.SetConstructor(cm, data, db, token.getCache().posision());
     token.next();
     return true;
 }
示例#10
0
        public CVar parse(EnegyData ed, VariabelDatabase db, Token token)
        {
            if (token.next().type() != TokenType.End)
            {
                ed.setReturn(new VariabelParser().parse(ed, db, token));
            }
            else {
                token.next();
                ed.setReturn(new NullVariabel());
            }

            return null;
        }
示例#11
0
        public CVar parse(EnegyData ed, VariabelDatabase db, Token token)
        {
            if(token.next().type() != TokenType.End)
            {
                ed.setError(new ScriptError("Missing ; after 'break'", token.getCache().posision()), db);
                return null;
            }

            token.next();

            ed.setBreak();
            return null;
        }
示例#12
0
        public CVar parse(EnegyData ed, VariabelDatabase db, Token token)
        {
            if (token.next().type() != TokenType.LeftBue)
            {
                ed.setError(new ScriptError("Missing ( after 'for'", token.getCache().posision()), db);
                return null;
            }

            //push the tokens until ;
            ArrayList init = getNextBlock(ed, db, token, true);

            if (ed.State != RunningState.Normal)
            {
                return null;
            }

            ArrayList status = getNextBlock(ed, db, token, true);

            if (ed.State != RunningState.Normal)
            {
                return null;
            }

            ArrayList handler = getNextBlock(ed, db, token, false);

            if (ed.State != RunningState.Normal)
            {
                return null;
            }

            ArrayList body = BodyParser.parse(token, ed, db);

            if (ed.State != RunningState.Normal)
            {
                return null;
            }

            //init the data :)
            new VariabelParser().parseNoEnd(ed, db, new TokenCache(init, ed, db));

            while (ed.State == RunningState.Normal && new VariabelParser().parseNoEnd(ed, db, new TokenCache(status, ed, db)).toBoolean(token.getCache().posision(), ed, db))
            {
                Interprenter.parse(new TokenCache(body, ed, db), ed, db);
                if (ed.State == RunningState.Normal)
                    new VariabelParser().parseNoEnd(ed, db, new TokenCache(handler, ed, db));
            }
            token.next();
            return null;
        }
示例#13
0
        public CVar parse(EnegyData ed, VariabelDatabase db, Token token)
        {
            if (token.next().type() != TokenType.LeftBue)
            {
                ed.setError(new ScriptError("Missing ( after repeat", token.getCache().posision()), db);
                return new NullVariabel();
            }

            TokenCache cache = ScopeParser.getScope(token, ed, db);
            token.next();

            while (new VariabelParser().parse(ed, db, cache).toBoolean(token.getCache().posision(), ed, db)) ;

            return new NullVariabel();
        }
示例#14
0
        public CVar parse(EnegyData ed, VariabelDatabase db, Token token)
        {
            UnsetNext(token, ed, db);

            while (token.next().type() == TokenType.Comma)
                UnsetNext(token, ed, db);

            if(token.getCache().type() != TokenType.End)
            {
                ed.setError(new ScriptError("Missing ; in end of unset", token.getCache().posision()), db);
                return null;
            }
            token.next();
            return null;
        }
示例#15
0
 public CVar parse(EnegyData ed, VariabelDatabase db, Token token)
 {
     if (token.next().type() == TokenType.Function)
     {
         functionParser p = new functionParser();
         p.parseFunction(ed, db, token, true, true);
     }else if(token.getCache().type() == TokenType.Class)
     {
         ClassParser p = new ClassParser();
         p.parse(ed, db, token);
     }
     else
     {
         ed.setError(new ScriptError("unknown token after public: " + token.getCache().ToString(), token.getCache().posision()), db);
     }
     return new NullVariabel();
 }
示例#16
0
        private ArrayList getNextBlock(EnegyData data, VariabelDatabase db, Token token, bool isEnd)
        {
            TokenBuffer buffer;
            ArrayList b = new ArrayList();
            while ((buffer = token.next()).type() != TokenType.EOF && buffer.type() != (isEnd ? TokenType.End : TokenType.RightBue))
            {
                b.Add(buffer);
            }

            if (token.getCache().type() != (isEnd ? TokenType.End : TokenType.RightBue))
            {
                data.setError(new ScriptError("Missing " + (isEnd ? ";" : ")") + " got: " + token.getCache().ToString(), token.getCache().posision()), db);
                return new ArrayList();
            }

            return b;
        }
示例#17
0
        private void includePlugin(string name, EnegyData ed, VariabelDatabase db, Token token)
        {
            //control if the plugin exists in the system
            if (ed.Plugin.exists(name))
            {
                //wee has the plugin and load it :)
                ed.Plugin.open(db, name, ed, token.getCache().posision());
            }
            else
            {
                if (ed.Config.get("file.enabled", "false") == "false")
                {
                    ed.setError(new ScriptError("It is not allow to use file in use. 'file.enabled' is not set.", token.getCache().posision()), db);
                    return;
                }

                parseFile(ed, db, token.getCache().posision(), name);
            }
        }
示例#18
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);
                }
            }
        }
示例#19
0
        private bool buildMethod(ClassItemAccessLevel level, bool isStatic, Token token, EnegyData data)
        {
            //control if there are is name after function :)
            if (token.getCache().type() != TokenType.Variabel)
            {
                data.setError(new ScriptError("A method should have a name", token.getCache().posision()), db);
                return false;
            }

            string type = null;

            //okay the name can be a type so wee control it here :)
            if (Types.IsType(token.getCache().ToString(), db))
            {
                type = token.getCache().ToString();

                if(token.next().type() != TokenType.Variabel)
                {
                    data.setError(new ScriptError("A method should have a name", token.getCache().posision()), db);
                    return false;
                }
            }

            Method method = new Method(token.getCache().ToString());

            token.next();

            if (isStatic)
                method.SetStatic();

            method.SetAgumentStack(AgumentParser.parseAguments(token, db, data));
            method.SetBody(new CallScriptMethod(method.GetAgumentStack(), BodyParser.parse(token, data, db)).call);
            method.SetVariabel();//in this way the script can use agument as name :)
            method.setLevel(level);

            builder.SetMethod(method, data, db, token.getCache().posision());
            token.next();
            return true;
        }
示例#20
0
        public CVar parse(EnegyData ed, VariabelDatabase db, Token token)
        {
            token.next();

            includePlugin(new VariabelParser().parseNoEnd(ed, db, token).toString(token.getCache().posision(), ed, db), ed, db, token);

            while (token.getCache().type() == TokenType.Comma)
            {
                token.next();
                includePlugin(new VariabelParser().parseNoEnd(ed, db, token).toString(token.getCache().posision(), ed, db), ed, db, token);
            }

            if(token.getCache().type() != TokenType.End)
            {
                ed.setError(new ScriptError("Missing ; in end of use. got: "+token.getCache().ToString(), token.getCache().posision()), db);
                return null;
            }

            token.next();

            return new NullVariabel();
        }
示例#21
0
        public static ArrayList parse(Token token, EnegyData data, VariabelDatabase db, bool needTubor = false)
        {
            ArrayList cache = new ArrayList();
            //wee control the next token to see if it {
            if(token.next().type() == TokenType.LeftTuborg)
            {
                int happens = 1;
                TokenBuffer buffer;
                while((buffer = token.next()).type() != TokenType.EOF)
                {
                    if (buffer.type() == TokenType.RightTuborg)
                    {
                        happens--;
                        if (happens == 0)
                            break;
                    }
                    else if (buffer.type() == TokenType.LeftTuborg)
                        happens++;

                    cache.Add(buffer);
                }

                if(token.getCache().type() != TokenType.RightTuborg)
                {
                    data.setError(new ScriptError("Missing } got " + token.getCache().ToString(), token.getCache().posision()), db);
                    return new ArrayList();
                }
            }
            else
            {
                if (needTubor)
                {
                    data.setError(new ScriptError("Missing {", token.getCache().posision()), db);
                    return new ArrayList();
                }
            }

            return cache;
        }
示例#22
0
        private static bool getSingleAguments(Token token, AgumentStack agument, VariabelDatabase database, EnegyData data)
        {
            string type = null;
            string name = null;
            CVar value = null;

            //wee control if it is function :)
            if(token.getCache().ToString() == "function")
            {
                if(token.next().type() == TokenType.Greater)
                {
                    //it is a function with return type :)
                    if (!database.isType(token.next().ToString()))
                    {
                        data.setError(new ScriptError("Unknown type: " + token.getCache().ToString(), token.getCache().posision()), database);
                        return false;
                    }

                    type = "function<" + token.getCache().ToString() + ">";

                    if(token.next().type() != TokenType.Less)
                    {
                        data.setError(new ScriptError("Missing > in end of function return type agument", token.getCache().posision()), database);
                    }

                    token.next();
                }
                else
                {
                    type = "function";
                }

                //okay let try to find the name
                if (token.getCache().type() != TokenType.Variabel)
                {
                    data.setError(new ScriptError("After type there must be a variabel", token.getCache().posision()), database);
                    return false;
                }

                name = token.getCache().ToString();
            }
            else if (database.isType(token.getCache().ToString()))
            {
                //yes it is a type :)
                type = token.getCache().ToString();

                //okay let try to find the name
                if (token.next().type() != TokenType.Variabel)
                {
                    data.setError(new ScriptError("After type there must be a variabel", token.getCache().posision()), database);
                    return false;
                }

                name = token.getCache().ToString();
            }
            else
            {
                if (token.getCache().type() != TokenType.Variabel)
                {
                    data.setError(new ScriptError("Unknown agument token: " + token.getCache().ToString(), token.getCache().posision()), database);
                    return false;
                }
                name = token.getCache().ToString();
            }

            if (token.next().type() == TokenType.Assigen)
            {
                token.next();
                value = new VariabelParser().parseNoEnd(data, database, token);
                hasDefault = true;
            }
            else
            {
                if (hasDefault)
                {
                    data.setError(new ScriptError("You can not put non default after a defualt variabel!", token.getCache().posision()), database);
                    return false;
                }
            }

            agument.push(type, name, value);
            return true;
        }
示例#23
0
        public CVar parse(EnegyData ed, VariabelDatabase db, Token token)
        {
            if (token.next().type() != TokenType.LeftBue)
            {
                ed.setError(new ScriptError("Missing ( after foreach", token.getCache().posision()), db);
                return new NullVariabel();
            }

            token.next();

            CVar agument = new VariabelParser().parseNoEnd(ed, db, token);

            if (!(agument is ArrayVariabel))
            {
                ed.setError(new ScriptError("Foreach first agument must be a array!", token.getCache().posision()), db);
                return new NullVariabel();
            }

            if (token.getCache().type() != TokenType.As)
            {
                ed.setError(new ScriptError("After array in foreach there must be a 'as'", token.getCache().posision()), db);
                return new NullVariabel();
            }

            if (token.next().type() != TokenType.Variabel)
            {
                ed.setError(new ScriptError("After 'as' there must be variabel", token.getCache().posision()), db);
                return new NullVariabel();
            }

            string firstVariabel = token.getCache().ToString();
            string secondVariabel = null;

            //wee see if the next token is :
            if(token.next().type() == TokenType.DublePunk)
            {
                if (token.next().type() != TokenType.Variabel)
                {
                    ed.setError(new ScriptError("After : in foreach there must be a variabel.", token.getCache().posision()), db);
                    return new NullVariabel();
                }

                secondVariabel = token.getCache().ToString();
                token.next();
            }

            if (token.getCache().type() != TokenType.RightBue)
            {
                ed.setError(new ScriptError("Missing ) in end of Foreach scope. got " + token.getCache().ToString(), token.getCache().posision()), db);
                return new NullVariabel();
            }

            ArrayList body = BodyParser.parse(token, ed, db);

            ArrayVariabel array = (ArrayVariabel)agument;

            foreach(string key in array.Keys())
            {
                if (ed.State != RunningState.Normal)
                    break;

                db.push(firstVariabel, (secondVariabel != null ? Types.toString(key, ed, db, token.getCache().posision()) : array.get(key, token.getCache().posision(), ed, db)), ed);
                if (secondVariabel != null)
                    db.push(secondVariabel, array.get(key, token.getCache().posision(), ed, db), ed);
                Interprenter.parse(new TokenCache(body, ed, db), ed, db);

                if (ed.State == RunningState.Break)
                {
                    //a token in this foreach is 'break' so wee stop this and continue outside the body of this foreach
                    ed.setNormal();
                    break;
                }
                else if (ed.State == RunningState.Continue)
                    ed.setNormal();
            }

            token.next();
            return null;
        }
示例#24
0
 public ClassVariabel parseNoName(EnegyData data, VariabelDatabase db, Token token)
 {
     return (ClassVariabel)p(data, db, token, false);
 }
示例#25
0
 public CVar parse(EnegyData ed, VariabelDatabase db, Token token)
 {
     return p(ed, db, token, true);
 }
示例#26
0
        private CVar p(EnegyData ed, VariabelDatabase db, Token token, bool name)
        {
            this.db = db;

            if (name)
            {
                if (token.next().type() != TokenType.Variabel)
                {
                    ed.setError(new ScriptError("Missing class name after 'class'", token.getCache().posision()), db);
                    return new NullVariabel();
                }

                builder = new Class(token.getCache().ToString());
            }
            else
            {
                builder = new Class();
            }

            if(token.next().type() == TokenType.Extends)
            {
                if(token.next().type() != TokenType.Variabel)
                {
                    ed.setError(new ScriptError("Missing variabel after extends", token.getCache().posision()), db);
                    return new NullVariabel();
                }

                //control if the variabel exteis in the variabel database
                if (!db.isExists(token.getCache().ToString()))
                {
                    ed.setError(new ScriptError("Unknown variabel: " + token.getCache().ToString(), token.getCache().posision()), db);
                    return new NullVariabel();
                }

                CVar buffer = db.get(token.getCache().ToString(), ed);

                if(!(buffer is ClassVariabel))
                {
                    ed.setError(new ScriptError(token.getCache().ToString() + " is not a class", token.getCache().posision()), db);
                    return new NullVariabel();
                }

                builder.Extends((ClassVariabel)buffer);
                token.next();
            }

            if(token.getCache().type() != TokenType.LeftTuborg)
            {
                ed.setError(new ScriptError("Missing { after class name", token.getCache().posision()), db);
                return new NullVariabel();
            }

            token.next();

            while (ed.State == RunningState.Normal && run(token.getCache().type()))
                build(token, ed);

            if(token.getCache().type() != TokenType.RightTuborg)
            {
                ed.setError(new ScriptError("Missing } in end of class building", token.getCache().posision()), db);
                return new NullVariabel();
            }

            token.next();
            if (name)
            {
                db.pushClass(builder, ed);
                if (db is FileVariabelDatabase)
                {
                    builder.SetExtraVariabelDatabase(db);
                    ((FileVariabelDatabase)db).VariabelDatabase.pushClass(builder, ed);
                }
                return null;
            }
            else
            {
                return new ClassVariabel(builder);
            }
        }
示例#27
0
 private bool isStatic(ClassItemAccessLevel level, Token token, EnegyData data)
 {
     if(token.getCache().type() == TokenType.Static)
     {
         token.next();
         return buildBody(level, true, token, data);
     }else
         return buildBody(level, false, token, data);
 }
示例#28
0
        private bool buildVariabel(ClassItemAccessLevel level, bool isStatic, Token token, EnegyData data)
        {
            //it is a variabel :)
            //okay it is a variabel ?
            if (token.getCache().type() != TokenType.Variabel) {
                data.setError(new ScriptError("1 Unknown token in class (" + builder.GetContainer().Name + ") body: " + token.getCache().ToString() + " | " + token.getCache().type().ToString(), token.getCache().posision()), db);
                return false;
            }

            Pointer pointer = new Pointer(token.getCache().ToString());

            if(token.next().type() == TokenType.Assigen)
            {
                token.next();
                pointer.SetDefault(new VariabelParser().parse(data, db, token));
            }else if(token.getCache().type() == TokenType.End)
            {
                token.next();
            }
            else
            {
                data.setError(new ScriptError("2 Unknown token in class ("+builder.GetContainer().Name+") body: " + token.getCache().ToString(), token.getCache().posision()), db);
                return false;
            }

            if (isStatic)
                pointer.SetStatic();

            pointer.SetLevel(level);

            builder.SetPointer(pointer, data, db, token.getCache().posision());
            return true;
        }