Beispiel #1
0
        public override IElement CreateCopy()
        {
            VarName e = new VarName();

            e.AddChildren(this.CopyChildren());
            return(e);
        }
Beispiel #2
0
        // TODO: dokončiť!
        // zostupne podľa priority vyhľadávania
        // konštanty sa pridružujú k iným operandom a určujú sa podľa kontextu!

        // "string"
        // "string".member
        // "string"[i]

        // &"FILE_LOCALIZED_STRING"

        // 56 | -56 | +56

        // []

        // { 1, 2, 3 }

        // (0,1,2)
        // (0,1,2)[i]

        // (subExpression)
        // (subExpression).member
        // (subExpression)[i]

        // true
        // false
        // undefined

        // thread

        // ::func
        // path::func | path::const

        // var | const
        // var.member
        // var[i]


        // as operators

        // = Expression

        // lastOperand [[delegate]]()
        // lastOperand [[delegate]]().member
        // lastOperand [[delegate]]()[i]

        // lastOperand func()
        // lastOperand func().member
        // lastOperand func()[i]
        // lastOperand path::func()
        // lastOperand path::func().member
        // lastOperand path::func()[i]

        public static bool Check(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo, ref bool isSingleOperand, bool isArrayContentDefEnabled, bool isArrayDefEnabled)
        {
            if ((isArrayDefEnabled && (ArrayDef.Check(parentInfo, parsingInfo, scriptInfo))) || // []
                (isArrayContentDefEnabled && ArrayContentDef.Check(parentInfo, parsingInfo, scriptInfo)))    // { 0,1,2 }
            {
                isSingleOperand = IsSingle(parentInfo, parsingInfo);
                return(true);
            }

            if (StringArray.Check(parentInfo, parsingInfo, scriptInfo) || // "str" | "str".member | "str"[]
                LocalizedString.Check(parentInfo, parsingInfo, scriptInfo) || // &"str"
                SignedNumber.Check(parentInfo, parsingInfo, scriptInfo) || // 56 | -56 | +56
                Vector.Check(parentInfo, parsingInfo, scriptInfo) || // (0,1,2) | (0,1,2)[]
                SubExpression.Check(parentInfo, parsingInfo, scriptInfo) || // (exp) | (exp).member* | (exp)[]*
                Literal.Check(parentInfo, parsingInfo, scriptInfo) || // true | false | undefined
                FuncCallModifier.Check(parentInfo, parsingInfo, scriptInfo) || // thread
                DelegateCall.Check(parentInfo, parsingInfo, scriptInfo) || // // [[delegate]](funcArgs) | [[d]]().member* | [[d]]()[]*
                FuncCall.Check(parentInfo, parsingInfo, scriptInfo) || // f() | path::f() | f().member* | f()[i]*
                DelegateDef.Check(parentInfo, parsingInfo, scriptInfo) || // ::func | path::func
                VarName.Check(parentInfo, parsingInfo, scriptInfo)    // var | var.member* | var[i]*
                )
            {
                isSingleOperand = IsSingle(parentInfo, parsingInfo);
                return(true);
            }

            return(false);
        }
Beispiel #3
0
        private static void CheckOutParam(ParsingInfo parsingInfo, Expression exp, MoveInfo parentInfo)
        {
            if (parsingInfo.OutParamFuncCall != null)
            {
                FuncInfo funcInfo = parsingInfo.OutParamFuncInfo;
                if (parsingInfo.OutParamFuncArgIndex < funcInfo.Parameters.Count)
                {
                    if (funcInfo.Parameters[parsingInfo.OutParamFuncArgIndex].IsOut)
                    {
                        // check exp content
                        List <IElement> expChildren = exp.GetChildren();
                        if (expChildren.Count != 0 && (expChildren[0] is VarName) &&
                            ((VarName)expChildren[0]).GetChildren().Count == 1)
                        {
                            VarName varName    = (VarName)expChildren[0];
                            string  varNameStr = varName.ToString();

                            parsingInfo.CurrentFunc.LocalVars.Add(new LocalVarInfo(parsingInfo.SF, varNameStr, varName.CharIndex, varName.CharLength, null, varName));
                        }
                        else
                        {
                            throw new SyntaxException("Only VarName is allowed as out parameter", parentInfo.GetErrorInfo());
                        }
                    }
                }

                parsingInfo.OutParamFuncArgIndex++;
            }
        }
Beispiel #4
0
        public static FuncDefParam Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            FuncDefParam param = new FuncDefParam();

            MoveInfo moveInfo = new MoveInfo(parentInfo);

            MoveInfo wordMoveInfo = moveInfo;
            IElement wordTry      = moveInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible);
            int      startIndex   = moveInfo.CurrentIndex;

            if (wordTry == null)
            {
                throw new SyntaxException("Could not parse FuncDef param", parentInfo.GetErrorInfo());
            }

            if (wordTry is SQBracketGroup)
            {
                param._group   = (SQBracketGroup)wordTry;
                param.Optional = true;

                MoveInfo bracketInfo = new MoveInfo((SQBracketGroup)wordTry, SearchTree.ContentBlock, 0, moveInfo);
                wordTry      = bracketInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible);
                wordMoveInfo = bracketInfo;
            }

            if (wordTry == null || !wordTry.IsTT(TokenType.Word))
            {
                throw new SyntaxException("Could not parse FuncDef param", parentInfo.GetErrorInfo());
            }

            VarName.Parse(wordMoveInfo, parsingInfo, scriptInfo);
            param.VarName = (VarName)wordMoveInfo.Current;

            param.Name = wordTry.ToString();
            param.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, moveInfo.CurrentIndex - startIndex + 1));
            parentInfo.Replace((moveInfo.CurrentIndex + 1) - startIndex, param);
            return(param);
        }
Beispiel #5
0
        public static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            VarName varName = new VarName();

            MoveInfo moveInfo = new MoveInfo(parentInfo);

            int startIndex = parentInfo.CurrentIndex;
            int length;

            // find members and arrayIndexers
            IElement next = null;

            do
            {
                length = (moveInfo.CurrentIndex + 1) - startIndex;
                next   = moveInfo.FindNextBlack(SearchDirection.LeftToRight);
            }while (next != null &&
                    (ArrayIndexer.Check(moveInfo, parsingInfo, scriptInfo) ||
                     DataMember.Check(moveInfo, parsingInfo, scriptInfo)));

            varName.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));
            parentInfo.Replace(length, varName);
        }
Beispiel #6
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            ForEachStatement foreachStatement = new ForEachStatement();
            MoveInfo         moveInfo         = new MoveInfo(parentInfo);

            foreachStatement._foreachKeyword = (Token)moveInfo.Current;

            // expression
            IElement expGroupTry = moveInfo.FindNextBlack(SearchDirection.LeftToRight);

            if (expGroupTry == null || !(expGroupTry is ParenthesesGroup))
            {
                throw new SyntaxException("Could not find foreach expression", parentInfo.GetErrorInfo());
            }

            ParenthesesGroup expGroup     = (ParenthesesGroup)expGroupTry;
            MoveInfo         expGroupInfo = new MoveInfo(expGroup, SearchTree.ContentBlock, 0, parentInfo);

            foreachStatement._foreachGroup = expGroup;

            // var define
            IElement tryVar = expGroupInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible);

            if (tryVar == null || !tryVar.IsTT(TokenType.Word))
            {
                throw new SyntaxException("Could not parse foreach var", parentInfo.GetErrorInfo());
            }

            VarName.Parse(expGroupInfo, parsingInfo, scriptInfo);
            VarName varName = (VarName)expGroupInfo.Current;

            LocalVarInfo localVar = parsingInfo.CurrentFunc.LocalVars.Find(a => a.Name.EqualCode(tryVar.ToString()));     // there is already var with this name...

            if (localVar == null)
            {
                parsingInfo.CurrentFunc.LocalVars.Add(new LocalVarInfo(scriptInfo.SF, tryVar.ToString(), tryVar.CharIndex, tryVar.CharLength, null, varName));
            }

            foreachStatement._currentVar = varName;

            // in keyword
            IElement tryIn = expGroupInfo.FindNextBlack(SearchDirection.LeftToRight);

            if (tryIn == null || !tryIn.IsTT(TokenType.Word) || !tryIn.ToString().EqualCode("in"))
            {
                throw new SyntaxException("Could not find foreach 'in'", parentInfo.GetErrorInfo());
            }

            // array
            IElement   tryArray    = expGroupInfo.FindNextBlack(SearchDirection.LeftToRight);
            Expression tryArrayExp = Expression.Parse(expGroupInfo, parsingInfo, scriptInfo);

            if (tryArrayExp == null || expGroupInfo.FindNextBlack(SearchDirection.LeftToRight) != null)
            {
                throw new SyntaxException("Could not parse foreach array", parentInfo.GetErrorInfo());
            }

            foreachStatement._array = tryArrayExp;

            // statement
            moveInfo.FindNextBlack(SearchDirection.LeftToRight);
            if (!Statement.Check(moveInfo, parsingInfo, scriptInfo))
            {
                throw new SyntaxException("Could not parse foreach statement", parentInfo.GetErrorInfo());
            }

            foreachStatement._statement = (Statement)moveInfo.Current;

            // build
            int startIndex = parentInfo.CurrentIndex;
            int length     = (moveInfo.CurrentIndex + 1) - startIndex;

            foreachStatement.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));
            parentInfo.Replace(length, foreachStatement);
        }
Beispiel #7
0
        public IElement GetCompiledStatements(VarName varName)
        {
            BallOfMud statements = new BallOfMud();

            statements.AddChildren(new List <IElement> {
                Token.ScopeOpen, Token.Space
            });

            Dictionary <Queue <StrIntIndex>, IElement> indexesForValues = new Dictionary <Queue <StrIntIndex>, IElement>();

            GetIndexesAndValues(this, ref indexesForValues, null);

            foreach (Queue <StrIntIndex> queue in indexesForValues.Keys)
            {
                IElement  value     = indexesForValues[queue];
                BallOfMud statement = new BallOfMud(new List <IElement> {
                    varName
                });
                foreach (StrIntIndex curIndex in queue)
                {
                    Token index = null;
                    if (curIndex.Index is String)
                    {
                        index = new Token(TokenType.String, (string)curIndex.Index);
                    }
                    else
                    {
                        index = new Token(TokenType.Number, (int)curIndex.Index);
                    }

                    statement.AddChildren(new List <IElement> {
                        Token.SQBracketOpen, index, Token.SQBracketClose
                    });
                }
                statement.AddChildren(new List <IElement> {
                    Token.Space, Token.Assign, Token.Space, value, Token.SemiColon, Token.Space
                });
                statements.AddChildren(statement);
            }

            statements.AddChildren(Token.ScopeClose);
            return(statements);

            /*
             * numbers = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
             *  numbers[0] = 0;
             *  numbers[1] = 1;
             *  etc...
             *
             *  vectors = { {0, 0, 0}, {5, 10, 2}, {487, 516, 487486} };
             *  vector[0][0] = 0;
             *  vector[0][1] = 0;
             *  vector[0][2] = 0;
             *  vector[1][0] = 5;
             *  vector[1][1] = 10;
             *  vector[1][2] = 2;
             *  vector[2][0] = 487;
             *  vector[2][1] = 516;
             *  vector[2][2] = 487486;
             *
             *  menus = { { {"Item0_0_0", "Item0_0_1"}, {"Item0_1_0", "Item0_1_1"} }, { {"Item1_0_0", "Item1_0_1"}, {"Item1_1_0", "Item1_1_1"} } };
             *  menus[0][0][0] = "Item0_0_0";
             *  menus[0][0][1] = "Item0_0_1";
             *  menus[0][1][0] = "Item0_1_0";
             *  menus[0][1][1] = "Item0_1_1";
             *  menus[1][0][0] = "Item1_0_0";
             *  menus[1][0][1] = "Item1_0_1";
             *  menus[1][1][0] = "Item1_1_0";
             *  menus[1][1][1] = "Item1_1_1";
             *
             *  personWithoutHobbys = {Name = "Peter", Age = 17, Hobbys = {}};
             *  personWithoutHobbys = {Name = "Peter", Age = 17, Hobbys = []};
             *  personWithoutHobbys["Name"] = "Peter";
             *  personWithoutHobbys["Age"] = 17;
             *  personWithoutHobbys["Hobbys"] = [];
             *
             *  person = {Name = "Peter", Age = 17, Hobbys = {"PC", "Skiing"} };
             *  person["Name"] = "Peter";
             *  person["Age"] = 17;
             *  person["Hobbys"][0] = "PC";
             *  person["Hobbys"][1] = "Skiing";
             *
             *  persons = { {Name = "Peter", Age = 17, Hobbys = {"PC", "Skiing"} }, {Name = "Andrea", Age = 21, Hobbys = {"Diving", "Cooking"} } };
             *  persons[0]["Name"] = "Peter";
             *  persons[0]["Age"] = 17;
             *  persons[0]["Hobbys"][0] = "PC";
             *  persons[0]["Hobbys"][1] = "Skiing";
             *  persons[1]["Name"] = "Andrea";
             *  persons[1]["Age"] = 21;
             *  persons[1]["Hobbys"][0] = "Diving";
             *  persons[1]["Hobbys"][1] = "Cooking";
             */
        }