示例#1
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            WaitStatement waitStatement = new WaitStatement();
            MoveInfo      moveInfo      = new MoveInfo(parentInfo);

            IElement tryExp = moveInfo.FindNextBlack(SearchDirection.LeftToRight);

            if (tryExp == null)
            {
                throw new SyntaxException("Could not find wait expression", parentInfo.GetErrorInfo());
            }

            Expression exp = Expression.Parse(moveInfo, parsingInfo, scriptInfo);

            if (exp == null)
            {
                throw new SyntaxException("Could not parse wait expression", parentInfo.GetErrorInfo());
            }

            IElement terminalTry = moveInfo.FindNextBlack(SearchDirection.LeftToRight);

            // terminal
            if (terminalTry == null || !terminalTry.IsTT(TokenType.SemiColon))
            {
                throw new SyntaxException("Missing directive ';'?", parentInfo.GetErrorInfo());
            }

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

            waitStatement.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));
            parentInfo.Replace(length, waitStatement);
        }
示例#2
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            DoWhileStatement doWhileStatement = new DoWhileStatement();
            MoveInfo         moveInfo         = new MoveInfo(parentInfo);

            doWhileStatement._doKeyword = (Token)moveInfo.Current;

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

            doWhileStatement._statement = (Statement)moveInfo.Current;

            // while
            IElement tryWhile = moveInfo.FindNextBlack(SearchDirection.LeftToRight);

            if (tryWhile == null || !tryWhile.IsTT(TokenType.Word) || !tryWhile.ToString().EqualCode("while"))
            {
                throw new SyntaxException("Could not find do-while while part", parentInfo.GetErrorInfo());
            }

            doWhileStatement._whileKeyword = (Token)tryWhile;

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

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

            ParenthesesGroup expGroup     = (ParenthesesGroup)tryExpGroup;
            MoveInfo         expGroupInfo = new MoveInfo(expGroup, SearchTree.ContentBlock, 0, parentInfo);
            Expression       exp          = Expression.Parse(expGroupInfo, parsingInfo, scriptInfo);

            if (exp == null || expGroupInfo.FindNextBlack(SearchDirection.LeftToRight) != null)
            {
                throw new SyntaxException("Could not parse do-while expression", parentInfo.GetErrorInfo());
            }

            doWhileStatement._expParentGroup = expGroup;

            // terminal
            IElement tryTerminal = moveInfo.FindNextBlack(SearchDirection.LeftToRight);

            if (tryTerminal == null || !tryTerminal.IsTT(TokenType.SemiColon))
            {
                throw new SyntaxException("Missing directive ';'?", parentInfo.GetErrorInfo());
            }

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

            doWhileStatement.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));
            parentInfo.Replace(length, doWhileStatement);
        }
示例#3
0
        private static void ParseExtern(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            DelegateDef delegDef = new DelegateDef();

            MoveInfo moveInfo = new MoveInfo(parentInfo);
            Path     path     = Path.Parse(moveInfo, parsingInfo, scriptInfo);

            if (path == null)
            {
                throw new SyntaxException("Bad path", parentInfo.GetErrorInfo());
            }

            delegDef._pathOrUsing = path.ToString();
            delegDef._pathElem    = path;

            // ::
            moveInfo.FindNextBlack(SearchDirection.LeftToRight);
            delegDef._nameSpaceElem = (Token)moveInfo.Current;

            // name
            moveInfo.FindNextBlack(SearchDirection.LeftToRight);
            delegDef._name = moveInfo.Current.ToString();

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

            delegDef.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));
            parentInfo.Replace(length, delegDef);
        }
示例#4
0
        public static bool Check(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            if (parentInfo.Current.IsTT(TokenType.Word))
            {
                // local function
                MoveInfo localInfo  = new MoveInfo(parentInfo);
                IElement behindName = localInfo.FindNextBlack(SearchDirection.LeftToRight);
                if (behindName is ParenthesesGroup)
                {
                    ParseLocal(parentInfo, parsingInfo, scriptInfo);
                    return(true);
                }

                // extern function
                MoveInfo externInfo = new MoveInfo(parentInfo);
                Path.MoveToEnd(externInfo, SearchDirection.LeftToRight);
                IElement behindPath = externInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible);
                if (behindPath.IsTT(TokenType.Namespace))
                {
                    IElement name = externInfo.FindNextBlack(SearchDirection.LeftToRight);
                    if (name.IsTT(TokenType.Word))
                    {
                        IElement args = externInfo.FindNextBlack(SearchDirection.LeftToRight);
                        if (args is ParenthesesGroup)
                        {
                            ParseExtern(parentInfo, parsingInfo, scriptInfo);
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
示例#5
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            IfElseStatement ifElse = new IfElseStatement();

            MoveInfo moveInfo = new MoveInfo(parentInfo);

            IElement expTry = moveInfo.FindNextBlack(SearchDirection.LeftToRight);

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

            ParenthesesGroup expGroup = (ParenthesesGroup)expTry;
            MoveInfo         expInfo  = new MoveInfo(expGroup, SearchTree.ContentBlock, 0, moveInfo);

            Expression exp = Expression.Parse(expInfo, parsingInfo, scriptInfo);

            if (exp == null)
            {
                throw new SyntaxException("Could not find if expression", parentInfo.GetErrorInfo());
            }

            if (expInfo.FindNextBlack(SearchDirection.LeftToRight) != null)
            {
                throw new SyntaxException("Could not parse if expression", parentInfo.GetErrorInfo());
            }

            moveInfo.Move(SearchDirection.LeftToRight);

            if (!Statement.Check(moveInfo, parsingInfo, scriptInfo))
            {
                throw new SyntaxException("Could not find statement", parentInfo.GetErrorInfo());
            }

            int endIndex = moveInfo.CurrentIndex;

            IElement tryElse = moveInfo.FindNextBlack(SearchDirection.LeftToRight);

            if (tryElse != null && tryElse.IsTT(TokenType.Word) && moveInfo.Current.ToString() == "else")
            {
                moveInfo.Move(SearchDirection.LeftToRight);
                if (!Statement.Check(moveInfo, parsingInfo, scriptInfo))
                {
                    throw new SyntaxException("Could not find statement", parentInfo.GetErrorInfo());
                }

                endIndex = moveInfo.CurrentIndex;
            }

            int             totalLength = (endIndex + 1) - parentInfo.CurrentIndex;
            List <IElement> children    = parentInfo.CurrentElements.GetRange(parentInfo.CurrentIndex, totalLength);

            ifElse.AddChildren(children);

            parentInfo.Replace(totalLength, ifElse);
        }
示例#6
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            FuncArgs funcArgs = new FuncArgs();

            ParenthesesGroup group     = (ParenthesesGroup)parentInfo.Current;
            MoveInfo         groupInfo = new MoveInfo(group, SearchTree.ContentBlock, 0, parentInfo);

            IElement next = groupInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible);

            while (next != null)
            {
                Expression exp = Expression.Parse(groupInfo, parsingInfo, scriptInfo);
                next = groupInfo.FindNextBlack(SearchDirection.LeftToRight); // jump behind funcArg
                if (exp == null ||
                    (next != null && !next.IsTT(TokenType.Comma)))
                {
                    throw new SyntaxException("Could not parse funcArg", parentInfo.GetErrorInfo());
                }

                if (next != null)
                {
                    next = groupInfo.FindNextBlack(SearchDirection.LeftToRight); // jump behind ,
                    if (next == null)
                    {
                        throw new SyntaxException("Could not parse funcArg", parentInfo.GetErrorInfo());
                    }
                }

                CheckOutParam(parsingInfo, exp, parentInfo);

                if (parsingInfo.CurrentCall != null &&
                    parsingInfo.CurrentCallArgIndex != null)
                {
                    if (parsingInfo.CurrentCall is FuncCall)
                    {
                        ((FuncCall)parsingInfo.CurrentCall).Arguments.Add(exp);
                        parsingInfo.CurrentCallArgIndex++;
                    }
                    else if (parsingInfo.CurrentCall is DelegateCall)
                    {
                        ((DelegateCall)parsingInfo.CurrentCall).Arguments.Add(exp);
                        parsingInfo.CurrentCallArgIndex++;
                    }
                    else
                    {
                        throw new ArgumentException("parsingInfo.CurrentCall");
                    }
                }
            }

            funcArgs.AddChildren(group);
            parentInfo.Replace(1, funcArgs);
        }
示例#7
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            SubExpression subExp = new SubExpression();

            ParenthesesGroup group     = (ParenthesesGroup)parentInfo.Current;
            MoveInfo         groupInfo = new MoveInfo(group, SearchTree.ContentBlock, 0, parentInfo);
            Expression       exp       = Expression.Parse(groupInfo, parsingInfo, scriptInfo);

            if (exp == null ||
                groupInfo.FindNextBlack(SearchDirection.LeftToRight) != null)
            {
                throw new SyntaxException("Could not parse subExpression", parentInfo.GetErrorInfo());
            }

            int startIndex = parentInfo.CurrentIndex;
            int length     = 1;

            MoveInfo moveInfo = new MoveInfo(parentInfo);
            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)));

            subExp.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));
            parentInfo.Replace(length, subExp);
        }
示例#8
0
        public static bool Check(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            // local
            if (parentInfo.Current.IsTT(TokenType.Namespace))
            {
                MoveInfo localInfo = new MoveInfo(parentInfo);
                IElement next      = localInfo.FindNextBlack(SearchDirection.LeftToRight);
                if (next.IsTT(TokenType.Word))
                {
                    ParseLocal(parentInfo, parsingInfo, scriptInfo);
                    return(true);
                }
            }

            // extern
            if (parentInfo.Current.IsTT(TokenType.Word))
            {
                MoveInfo externInfo = new MoveInfo(parentInfo);
                Path.MoveToEnd(externInfo, SearchDirection.LeftToRight);
                IElement next = externInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible);
                if (next.IsTT(TokenType.Namespace))
                {
                    next = externInfo.FindNextBlack(SearchDirection.LeftToRight);
                    if (next.IsTT(TokenType.Word))
                    {
                        ParseExtern(parentInfo, parsingInfo, scriptInfo);
                        return(true);
                    }
                }
            }

            return(false);
        }
示例#9
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            PostfixIncDec postfixIncDec = new PostfixIncDec();

            int startIndex = parentInfo.CurrentIndex;
            int length;

            // find operand
            MoveInfo operandInfo = new MoveInfo(parentInfo);
            IElement operand     = operandInfo.FindNextBlack(SearchDirection.RightToLeft);

            if (operand != null && operand is ExpressionOperand)
            {
                startIndex = operandInfo.CurrentIndex;
            }
            else
            {
                throw new SyntaxException("Could not find PostfixIncDec operand", parentInfo.GetErrorInfo());
            }

            // build
            length = (parentInfo.CurrentIndex + 1) - startIndex;
            postfixIncDec.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));

            parentInfo.MoveToIndex(startIndex);
            parentInfo.Replace(length, postfixIncDec);
        }
示例#10
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            Assign assign = new Assign();

            int startIndex;
            int length;

            // find var define
            MoveInfo varInfo = new MoveInfo(parentInfo);
            IElement var     = varInfo.FindNextBlack(SearchDirection.RightToLeft);

            if (var == null || !(var is ExpressionOperand) || !(var is VarName))
            {
                throw new SyntaxException("Could not parse Assign VarName", parentInfo.GetErrorInfo());
            }

            assign.VarName = (VarName)var;

            startIndex = varInfo.CurrentIndex;

            // parse expression
            MoveInfo moveInfo = new MoveInfo(parentInfo);

            moveInfo.FindNextBlack(SearchDirection.LeftToRight); // move behind =
            Expression exp = Expression.Parse(moveInfo, parsingInfo, scriptInfo, false, true, true);

            if (exp == null)
            {
                throw new SyntaxException("Could not parse Assign Expression", parentInfo.GetErrorInfo());
            }

            assign.Exp = exp;

            // build
            length = (moveInfo.CurrentIndex + 1) - startIndex;
            assign.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));

            parentInfo.MoveToIndex(startIndex);
            parentInfo.Replace(length, assign);

            // add local var def
            IElement baseVar     = ((VarName)var).GetChildren()[0];
            string   baseVarName = baseVar.ToString();

            foreach (string tStr in ScriptManager.GlobalVariables)
            {
                if (baseVarName.EqualCode(tStr))
                {
                    return;
                }
            }

            LocalVarInfo tryVarInfo = parsingInfo.CurrentFunc.LocalVars.Find(a => a.Name.EqualCode(baseVarName)); // there is maybe var with this name...

            if (tryVarInfo == null)
            {
                parsingInfo.CurrentFunc.LocalVars.Add(new LocalVarInfo(parsingInfo.SF, baseVarName, baseVar.CharIndex, baseVar.CharLength, assign, (VarName)var));
            }
        }
示例#11
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            CaseSwitchStatement caseSwitch = new CaseSwitchStatement();
            MoveInfo            moveInfo   = new MoveInfo(parentInfo);

            // expression
            IElement   next = moveInfo.FindNextBlack(SearchDirection.LeftToRight);
            Expression exp  = Expression.Parse(moveInfo, parsingInfo, scriptInfo);

            if (exp == null)
            {
                throw new SyntaxException("Could not parse case expression", parentInfo.GetErrorInfo());
            }

            // terminal
            IElement tryTerminal = moveInfo.FindNextBlack(SearchDirection.LeftToRight);

            if (tryTerminal == null || !tryTerminal.IsTT(TokenType.Colon))
            {
                throw new SyntaxException("Missing directive ':'?", parentInfo.GetErrorInfo());
            }

            // statements
            IElement nextStatement = moveInfo.FindNextBlack(SearchDirection.LeftToRight);

            while (nextStatement != null) // end of switch
            {
                if (CaseSwitchStatement.Check(moveInfo, parsingInfo, scriptInfo, false) ||
                    DefaultSwitchStatement.Check(moveInfo, parsingInfo, scriptInfo, false))
                {
                    break;
                }

                Statement.Check(moveInfo, parsingInfo, scriptInfo);

                nextStatement = moveInfo.FindNextBlack(SearchDirection.LeftToRight);
            }

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

            caseSwitch.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));
            parentInfo.Replace(length, caseSwitch);
        }
示例#12
0
        /// <summary>
        /// Nájde modifier, kt. sa nachádza pred pozíciou moveInfo
        /// </summary>
        /// <param name="moveInfo"></param>
        /// <returns></returns>
        public static SealedModifier GetModifier(MoveInfo moveInfo)
        {
            IElement modifierTry = moveInfo.FindNextBlack(SearchDirection.RightToLeft);

            if (modifierTry != null && modifierTry is SealedModifier)
            {
                return((SealedModifier)moveInfo.Current);
            }

            return(null);
        }
示例#13
0
        private static void ParseSigned(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            MoveInfo moveInfo = new MoveInfo(parentInfo);

            moveInfo.FindNextBlack(SearchDirection.LeftToRight);

            int          length = ((moveInfo.CurrentIndex + 1) - parentInfo.CurrentIndex);
            SignedNumber n      = new SignedNumber(parentInfo.CurrentElements.GetRange(parentInfo.CurrentIndex, length));

            parentInfo.Replace(length, n);
        }
示例#14
0
        public override void CheckSemantic(MoveInfo treeInfo, ScriptInfo scriptInfo, CheckingInfo checkingInfo)
        {
            // unreachable code
            MoveInfo blockInfo = new MoveInfo(treeInfo.CurrentBlock, SearchTree.ContentBlock, treeInfo.CurrentIndex, treeInfo);
            IElement nextTry   = blockInfo.FindNextBlack(SearchDirection.LeftToRight);

            if (nextTry != null && nextTry is Statement)
            {
                scriptInfo.SF.Errors.Add(
                    new WarningError("Unreachable code detected",
                                     blockInfo.GetErrorInfo(nextTry)));
            }
        }
示例#15
0
        /// <summary>
        /// Nájde modifier, kt. sa nachádza pred pozíciou moveInfo
        /// </summary>
        /// <param name="moveInfo"></param>
        /// <returns></returns>
        public static AccessModifier GetModifier(MoveInfo moveInfo, out MemberAccess access)
        {
            access = MemberAccess.Public;
            IElement modifierTry = moveInfo.FindNextBlack(SearchDirection.RightToLeft);

            if (modifierTry != null && modifierTry is AccessModifier)
            {
                AccessModifier modifier = (AccessModifier)moveInfo.Current;
                access = modifier.Type;
                return(modifier);
            }
            return(null);
        }
示例#16
0
 public static new bool Check(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
 {
     if (parentInfo.Current is SQBracketGroup)
     {
         MoveInfo groupInfo = new MoveInfo((SQBracketGroup)parentInfo.Current, SearchTree.ContentBlock, 0, parentInfo);
         IElement first     = groupInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible);
         if (first is SQBracketGroup && groupInfo.FindNextBlack(SearchDirection.LeftToRight) == null)
         {
             Parse(parentInfo, parsingInfo, scriptInfo);
             return(true);
         }
     }
     return(false);
 }
示例#17
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            MoveInfo moveInfo = new MoveInfo(parentInfo);

            moveInfo.FindNextBlack(SearchDirection.LeftToRight);

            int             startIndex = parentInfo.CurrentIndex;
            int             length     = (moveInfo.CurrentIndex + 1) - startIndex;
            List <IElement> children   = parentInfo.CurrentElements.GetRange(startIndex, length);

            LocalizedString s = new LocalizedString(children);

            parentInfo.Replace(length, s);
        }
示例#18
0
 public static bool Check(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
 {
     if (parentInfo.Current.IsTT(TokenType.Word))
     {
         MoveInfo moveInfo  = new MoveInfo(parentInfo);
         IElement assignTry = moveInfo.FindNextBlack(SearchDirection.LeftToRight);
         if (assignTry != null && assignTry.IsTT(TokenType.Assign))
         {
             Parse(parentInfo, parsingInfo, scriptInfo);
             return(true);
         }
     }
     return(false);
 }
示例#19
0
 public static bool Check(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
 {
     if (parentInfo.Current.IsTT(TokenType.BitAND))
     {
         MoveInfo moveInfo = new MoveInfo(parentInfo);
         IElement next     = moveInfo.FindNextBlack(SearchDirection.LeftToRight);
         if (next != null && next.IsTT(TokenType.String))
         {
             Parse(parentInfo, parsingInfo, scriptInfo);
             return(true);
         }
     }
     return(false);
 }
示例#20
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            ReturnStatement returnStatement = new ReturnStatement();
            MoveInfo        moveInfo        = new MoveInfo(parentInfo);

            IElement tryExp = moveInfo.FindNextBlack(SearchDirection.LeftToRight);

            if (tryExp == null)
            {
                throw new SyntaxException("Missing directive ';'?", parentInfo.GetErrorInfo());
            }

            // expression defined
            if (!tryExp.IsTT(TokenType.SemiColon))
            {
                Expression exp = Expression.Parse(moveInfo, parsingInfo, scriptInfo, false, false, true);
                if (exp == null)
                {
                    throw new SyntaxException("Could not parse return expression", parentInfo.GetErrorInfo());
                }

                moveInfo.FindNextBlack(SearchDirection.LeftToRight);
            }

            // terminal
            if (moveInfo.Current == null || !moveInfo.Current.IsTT(TokenType.SemiColon))
            {
                throw new SyntaxException("Missing directive ';'?", parentInfo.GetErrorInfo());
            }

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

            returnStatement.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));
            parentInfo.Replace(length, returnStatement);
        }
示例#21
0
        public static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            MoveInfo moveInfo = new MoveInfo(parentInfo);
            IElement next     = moveInfo.FindNextBlack(SearchDirection.LeftToRight);

            if (next == null || !next.IsTT(TokenType.Word))
            {
                throw new SyntaxException("Could not find member", parentInfo.GetErrorInfo());
            }

            int        length = (moveInfo.CurrentIndex + 1) - parentInfo.CurrentIndex;
            DataMember m      = new DataMember(parentInfo.CurrentElements.GetRange(parentInfo.CurrentIndex, length));

            parentInfo.Replace(length, m);
        }
示例#22
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            WhileStatement whileStatement = new WhileStatement();
            MoveInfo       moveInfo       = new MoveInfo(parentInfo);

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

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

            ParenthesesGroup expGroup     = (ParenthesesGroup)expGroupTry;
            MoveInfo         expGroupInfo = new MoveInfo(expGroup, SearchTree.ContentBlock, 0, parentInfo);
            Expression       exp          = Expression.Parse(expGroupInfo, parsingInfo, scriptInfo);

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

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

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

            whileStatement.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));
            parentInfo.Replace(length, whileStatement);
        }
示例#23
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            ArrayIndexer aI = new ArrayIndexer();

            SQBracketGroup SQGroup     = (SQBracketGroup)parentInfo.Current;
            MoveInfo       SQGroupInfo = new MoveInfo(SQGroup, SearchTree.ContentBlock, 0, parentInfo);
            Expression     exp         = Expression.Parse(SQGroupInfo, parsingInfo, scriptInfo);

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

            aI.AddChildren(SQGroup);
            parentInfo.Replace(1, aI);
        }
示例#24
0
        public static bool Check(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo, bool isTerminated)
        {
            ExpressionStatement expStatement = new ExpressionStatement();

            Expression exp = Expression.Parse(parentInfo, parsingInfo, scriptInfo, true, false, false);

            if (exp == null)
            {
                return(false);
            }

            expStatement._exp = exp;

            // exp content
            string   error   = "Only Assign, FuncCall, DelegateCall and PostfixIncDec is allowed as statement";
            MoveInfo expInfo = new MoveInfo(exp, SearchTree.ChildrenBlock, 0, parentInfo);

            if (!((expInfo.Current is Assign ||
                   expInfo.Current is FuncCall ||
                   expInfo.Current is DelegateCall ||
                   expInfo.Current is PostfixIncDec
                   ) && expInfo.FindNextBlack(SearchDirection.LeftToRight) == null))
            {
                throw new SyntaxException(error, parentInfo.GetErrorInfo());
            }

            // next token
            MoveInfo moveInfo = new MoveInfo(parentInfo);

            if (isTerminated)
            {
                IElement terminal = moveInfo.FindNextBlack(SearchDirection.LeftToRight);
                if (terminal == null || !terminal.IsTT(TokenType.SemiColon))
                {
                    throw new SyntaxException("Missing directive ';'?", parentInfo.GetErrorInfo());
                }
            }

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

            expStatement.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));
            parentInfo.Replace(length, expStatement);

            return(true);
        }
示例#25
0
        private static void ParseLocal(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            DelegateDef delegDef = new DelegateDef();

            MoveInfo moveInfo = new MoveInfo(parentInfo);

            delegDef._nameSpaceElem = (Token)moveInfo.Current;

            moveInfo.FindNextBlack(SearchDirection.LeftToRight); // jump behind ::
            delegDef._name = moveInfo.Current.ToString();

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

            delegDef.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));
            parentInfo.Replace(length, delegDef);
        }
示例#26
0
        public override void CheckSemantic(MoveInfo treeInfo, ScriptInfo scriptInfo, CheckingInfo checkingInfo)
        {
            if (!treeInfo.IsIn <IterationStatement>())
            {
                throw new SyntaxException("Keyword 'continue' cannot use here!", treeInfo.GetErrorInfo());
            }

            // unreachable code
            MoveInfo blockInfo = new MoveInfo(treeInfo.CurrentBlock, SearchTree.ContentBlock, treeInfo.CurrentIndex, treeInfo);
            IElement nextTry   = blockInfo.FindNextBlack(SearchDirection.LeftToRight);

            if (nextTry != null && nextTry is Statement)
            {
                scriptInfo.SF.Errors.Add(
                    new WarningError("Unreachable code detected",
                                     blockInfo.GetErrorInfo(nextTry)));
            }
        }
示例#27
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            StringArray strArray = new StringArray();

            MoveInfo moveInfo = new MoveInfo(parentInfo);
            IElement next     = moveInfo.FindNextBlack(SearchDirection.LeftToRight);

            int length = 1;

            if (next != null &&
                (ArrayIndexer.Check(moveInfo, parsingInfo, scriptInfo) ||
                 DataMember.Check(moveInfo, parsingInfo, scriptInfo)))
            {
                length = (moveInfo.CurrentIndex + 1) - parentInfo.CurrentIndex;
            }

            strArray.AddChildren(parentInfo.CurrentElements.GetRange(parentInfo.CurrentIndex, length));
            parentInfo.Replace(length, strArray);
        }
示例#28
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            ContinueStatement continueStatement = new ContinueStatement();
            MoveInfo          moveInfo          = new MoveInfo(parentInfo);

            // terminal
            IElement terminalTry = moveInfo.FindNextBlack(SearchDirection.LeftToRight);

            if (terminalTry == null || !terminalTry.IsTT(TokenType.SemiColon))
            {
                throw new SyntaxException("Missing directive ';'?", parentInfo.GetErrorInfo());
            }

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

            continueStatement.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));
            parentInfo.Replace(length, continueStatement);
        }
示例#29
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);
        }
示例#30
0
        public static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            Vector vec = new Vector();

            ParenthesesGroup group     = (ParenthesesGroup)parentInfo.Current;
            MoveInfo         groupInfo = new MoveInfo(group, SearchTree.ContentBlock, 0, parentInfo);

            for (int i = 0; i < 3; i++)
            {
                Expression exp  = Expression.Parse(groupInfo, parsingInfo, scriptInfo);
                IElement   next = groupInfo.FindNextBlack(SearchDirection.LeftToRight);
                if ((i < 2 && !next.IsTT(TokenType.Comma)) ||
                    (i == 2 && next != null))
                {
                    throw new SyntaxException("Could not parse vector " + (i + 1) + " expression", parentInfo.GetErrorInfo());
                }

                if (i != 2) // move behind ,
                {
                    groupInfo.Move(SearchDirection.LeftToRight);
                }
            }

            int startIndex = parentInfo.CurrentIndex;
            int length     = 1;

            MoveInfo moveInfo = new MoveInfo(parentInfo);

            moveInfo.FindNextBlack(SearchDirection.LeftToRight);
            if (moveInfo.Current != null && ArrayIndexer.Check(moveInfo, parsingInfo, scriptInfo))
            {
                length = (moveInfo.CurrentIndex + 1) - startIndex;
            }

            vec.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));
            parentInfo.Replace(length, vec);
        }