コード例 #1
0
ファイル: IfParser.cs プロジェクト: Cowscript/CowScript
        private void begin(bool befor)
        {
            //if token ( now ?
            if(token.next().type() != TokenType.LeftBue)
            {
                ed.setError(new ScriptError("Missing ( after if", token.getCache().posision()), db);
                return;
            }

            if(token.next().type() == TokenType.RightBue)
            {
                //it is a empty scope :)
                ed.setError(new ScriptError("You can not use a if whit empty scope", token.getCache().posision()), db);
                return;
            }

            //get context :)
            CVar scope = new VariabelParser().parseNoEnd(ed, db, token);

            //control if wee got a )
            if(token.getCache().type() != TokenType.RightBue)
            {
                //wee missing )
                ed.setError(new ScriptError("Missing ) got: " + token.getCache().ToString(), token.getCache().posision()), db);
                return;
            }

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

            if(!befor && scope.toBoolean(token.getCache().posision(), ed, db) && ed.State == RunningState.Normal)
            {
                Interprenter.parse(new TokenCache(body, ed, db), ed, db);
                befor = true;
            }

            //control if next is elseif :)
            if(token.getCache().type() == TokenType.Elseif && ed.State == RunningState.Normal)
            {
                begin(befor);
            }else if(token.getCache().type() == TokenType.Else && ed.State == RunningState.Normal)
            {
                doElse(befor);
            }
        }
コード例 #2
0
ファイル: AgumentParser.cs プロジェクト: Cowscript/CowScript
        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;
        }
コード例 #3
0
ファイル: ForeachParser.cs プロジェクト: Cowscript/CowScript
        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;
        }