Esempio n. 1
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);
        }
Esempio n. 2
0
        private void CheckSemanticLocal(MoveInfo treeInfo, ScriptInfo scriptInfo, CheckingInfo checkingInfo)
        {
            _funcInfo = scriptInfo.FindLocalFunc(_name);

            if (_funcInfo == null) // find in includes
            {
                _funcInfo = scriptInfo.FindIncludesFunc(_name);

                if (_funcInfo == null)
                {
                    scriptInfo.SF.Errors.Add(
                        new SemanticError("Unknown function '" + _name + "'",
                                          treeInfo.GetErrorInfo(treeInfo.Current)));
                    return;
                }

                if (_funcInfo.Access == MemberAccess.Private)
                {
                    scriptInfo.SF.Errors.Add(
                        new SemanticError("Cannot access member '" + _funcInfo.ToString() + "'",
                                          treeInfo.GetErrorInfo(treeInfo.Current)));
                }
            }

            scriptInfo.References.Add(new FuncRefInfo(scriptInfo.SF, _funcInfo, this.CharIndex, this.CharLength,
                                                      checkingInfo.SC.SourceCode.Substring(this.CharIndex, this.CharLength), false));
        }
Esempio n. 3
0
        public override void CheckSemantic(MoveInfo treeInfo, ScriptInfo scriptInfo, CheckingInfo checkingInfo)
        {
            ScriptFile sf = scriptInfo.SF.Manager.GetSF(_usingInfo.SFPath);

            if (sf == null || sf.SI == null)
            {
                scriptInfo.SF.Errors.Add(new SemanticError("Could not find file '" + _usingInfo.SFPath + "'",
                                                           treeInfo.GetErrorInfo(treeInfo.Current)));
            }

            string             upperName = this._usingInfo.Name.ToUpperInvariant();
            List <IMemberInfo> members   = scriptInfo.SF.SI.GetAvailableMembers();

            foreach (IMemberInfo m in members)
            {
                if (m is UsingInfo && m.Name.ToUpperInvariant() == upperName)
                {
                    if ((m as UsingInfo) != this._usingInfo)
                    {
                        scriptInfo.SF.Errors.Add(
                            new SemanticError("Using '" + this._usingInfo.Name + "' already defined(" + m.SF.SFPath + "::" + m.Name + ")",
                                              treeInfo.GetErrorInfo(treeInfo.Current)));
                    }
                }
            }
        }
Esempio n. 4
0
        private void CheckSemanticLocal(MoveInfo treeInfo, ScriptInfo scriptInfo, CheckingInfo checkingInfo)
        {
            _funcInfo = scriptInfo.FindLocalFunc(_name);

            if (_funcInfo == null)
            {
                _funcInfo = scriptInfo.FindGlobalsFunc(_name);
            }

            if (_funcInfo == null) // find in includes
            {
                _funcInfo = scriptInfo.FindIncludesFunc(_name);

                if (_funcInfo == null)
                {
                    scriptInfo.SF.Errors.Add(
                        new SemanticError("Unknown function '" + _name + "'",
                                          treeInfo.GetErrorInfo(treeInfo.Current)));
                    return;
                }

                if (_funcInfo.Access != MemberAccess.Public) // private member in include
                {
                    scriptInfo.SF.Errors.Add(
                        new SemanticError("Cannot access function '" + _funcInfo.ToString() + "'",
                                          treeInfo.GetErrorInfo(treeInfo.Current)));
                }
            }
        }
Esempio n. 5
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);
        }
Esempio n. 6
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));
            }
        }
Esempio n. 7
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);
        }
Esempio n. 8
0
        private void CheckSemanticExtern(MoveInfo treeInfo, ScriptInfo scriptInfo, CheckingInfo checkingInfo)
        {
            _path = _pathOrUsing;

            #region Finding using
            UsingInfo usingInfoTry = scriptInfo.FindUsing(_path);
            if (usingInfoTry != null)
            {
                if (usingInfoTry.SF != scriptInfo.SF && usingInfoTry.Access != MemberAccess.Public)
                {
                    scriptInfo.SF.Errors.Add(new SemanticError("Could not access using '" + usingInfoTry.SF.SFPath + "::" + usingInfoTry.Name + "'",
                                                               treeInfo.GetErrorInfo(_pathElem)));
                    return;
                }

                _path = usingInfoTry.SFPath;
                UsingName usingName = UsingName.ConvertToMe(this, _pathElem, usingInfoTry);

                scriptInfo.References.Add(new UsingRefInfo(scriptInfo.SF, usingInfoTry,
                                                           usingName.CharIndex, usingName.CharLength, checkingInfo.SC.SourceCode.Substring(usingName.CharIndex, usingName.CharLength)));
            }
            #endregion

            ScriptFile sf = scriptInfo.SF.Manager.GetSF(_path);
            if (sf == null)
            {
                scriptInfo.SF.Errors.Add(
                    new SemanticError("Could not find file '" + _path + "'",
                                      treeInfo.GetErrorInfo(treeInfo.Current)));
                return;
            }
            else if (sf.SI == null)
            {
                scriptInfo.SF.Errors.Add(
                    new WarningError("Could not read file '" + _path + "'",
                                     treeInfo.GetErrorInfo(treeInfo.Current)));
                return;
            }

            _funcInfo = sf.SI.FindLocalFunc(_name);
            if (_funcInfo == null)
            {
                scriptInfo.SF.Errors.Add(
                    new SemanticError("Unknown function '" + _path + "::" + _name + "'",
                                      treeInfo.GetErrorInfo(treeInfo.Current)));
                return;
            }

            // member is private
            if (sf != scriptInfo.SF && _funcInfo.Access != MemberAccess.Public)
            {
                scriptInfo.SF.Errors.Add(
                    new SemanticError("Cannot access function '" + _path + "::" + _name + "'",
                                      treeInfo.GetErrorInfo(treeInfo.Current)));
            }
        }
Esempio n. 9
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);
        }
Esempio n. 10
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);
        }
Esempio n. 11
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);
        }
Esempio n. 12
0
        public static bool Check(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            if (parentInfo.Current is ParenthesesGroup)
            {
                ParenthesesGroup group    = (ParenthesesGroup)parentInfo.Current;
                MoveInfo         moveInfo = new MoveInfo(group, SearchTree.ContentBlock, 0, parentInfo);

                int i;
                for (i = 0; i < 2; i++)
                {
                    IElement next = moveInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible, a => a.IsTT(TokenType.Comma));
                    if (next == null)
                    {
                        break;
                    }

                    moveInfo.Move(SearchDirection.LeftToRight);
                }

                if (i == 0)
                {
                    return(false);
                }
                else if (i == 2)
                {
                    Parse(parentInfo, parsingInfo, scriptInfo);
                    return(true);
                }
                else
                {
                    throw new SyntaxException("Only 3D vector is allowed", parentInfo.GetErrorInfo());
                }
            }
            return(false);
        }
Esempio n. 13
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);
        }
Esempio n. 14
0
        public override void CheckSemantic(MoveInfo treeInfo, ScriptInfo scriptInfo, CheckingInfo checkingInfo)
        {
            if (!String.IsNullOrEmpty(this._pathOrUsing))
            {
                CheckSemanticExtern(treeInfo, scriptInfo, checkingInfo);
            }
            else
            {
                CheckSemanticLocal(treeInfo, scriptInfo, checkingInfo);
            }

            if (_funcInfo != null)
            {
                if (Arguments.Count > _funcInfo.Parameters.Count)
                {
                    if (_funcInfo.SF.IsExtern) // codapi funcs -> only warning
                    {
                        scriptInfo.SF.Errors.Add(
                            new WarningError("Function '" + _funcInfo.ToString() + "' has more arguments than parameters in the definition",
                                             treeInfo.GetErrorInfo(treeInfo.Current)));
                    }
                    else
                    {
                        scriptInfo.SF.Errors.Add(
                            new SemanticError("Function '" + _funcInfo.ToString() + "' has more arguments than parameters in the definition",
                                              treeInfo.GetErrorInfo(treeInfo.Current)));
                    }
                }

                if ((_funcInfo.OptParamStartIndex != null && Arguments.Count < _funcInfo.OptParamStartIndex) ||
                    (_funcInfo.OptParamStartIndex == null && Arguments.Count < _funcInfo.Parameters.Count))
                {
                    scriptInfo.SF.Errors.Add(
                        new WarningError("Could not find enough arguments, function '" + _funcInfo.ToString() + "'",
                                         treeInfo.GetErrorInfo(treeInfo.Current)));
                }

                FuncRefInfo funcRefInfo = new FuncRefInfo(scriptInfo.SF, _funcInfo, this.CharIndex, this.CharLength,
                                                          checkingInfo.SC.SourceCode.Substring(this.CharIndex, this.CharLength), true);
                foreach (Expression arg in this.Arguments)
                {
                    funcRefInfo.AddArgument(arg.CharIndex, arg.CharLength);
                }

                scriptInfo.References.Add(funcRefInfo);
            }
        }
Esempio n. 15
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);
        }
Esempio n. 16
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);
        }
Esempio n. 17
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)));
            }
        }
Esempio n. 18
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);
        }
Esempio n. 19
0
 public void CheckSemantic_OnLeaveFuncDef(ScriptInfo si)
 {
     foreach (LocalVarInfo v in LocalVars)
     {
         if (v.RefCount == 0 &&
             v.VarNameDef != null)    // ignore self
         {
             MoveInfo moveInfo = new MoveInfo(v.VarNameDef, SearchTree.ChildrenBlock, 0, si.SF);
             si.SF.Errors.Add(
                 new WarningError("Variable '" + v.VarNameDef.ToString() + "' is defined, but its value is never used.",
                                  moveInfo.GetErrorInfo(v.VarNameDef)));
         }
     }
 }
Esempio n. 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);
        }
Esempio n. 21
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);
        }
Esempio n. 22
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            SQBracketGroup group    = (SQBracketGroup)parentInfo.Current;
            MoveInfo       moveInfo = new MoveInfo(group, SearchTree.ContentBlock, 0, parentInfo);

            if (moveInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible) != null)
            {
                throw new SyntaxException("Unknown tokens in ArrayDef", parentInfo.GetErrorInfo());
            }

            ArrayDef arrayDef = new ArrayDef();

            arrayDef.AddChildren(group);
            parentInfo.Replace(1, arrayDef);
        }
Esempio n. 23
0
        private static List <FuncDefParam> GetParameterList(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            MoveInfo            moveInfo  = new MoveInfo(parentInfo);
            string              error     = "Could not parse function parameters";
            List <FuncDefParam> defParams = new List <FuncDefParam>();

            bool?    isSeparator = null;
            IElement curElem     = moveInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible);

            while (curElem != null)
            {
                if (isSeparator == false || isSeparator == null)
                {
                    FuncDefParam param = FuncDefParam.Parse(moveInfo, parsingInfo, scriptInfo);
                    defParams.Add(param);
                    isSeparator = true;
                }
                else
                {
                    if (!curElem.IsTT(TokenType.Comma))
                    {
                        throw new SyntaxException(error, parentInfo.GetErrorInfo());
                    }

                    isSeparator = false;
                }
                curElem = moveInfo.FindNextBlack(SearchDirection.LeftToRight);
            }

            if (isSeparator == false)
            {
                throw new SyntaxException(error, parentInfo.GetErrorInfo());
            }

            return(defParams);
        }
Esempio n. 24
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);
        }
Esempio n. 25
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);
        }
Esempio n. 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)));
            }
        }
Esempio n. 27
0
        public override void CheckSemantic(MoveInfo treeInfo, ScriptInfo scriptInfo, CheckingInfo checkingInfo)
        {
            string             upperName = this._constInfo.Name.ToUpperInvariant();
            List <IMemberInfo> members   = scriptInfo.SF.SI.GetAvailableMembers();

            foreach (IMemberInfo m in members)
            {
                if (m.Name.ToUpperInvariant() == upperName)
                {
                    if ((m as ConstInfo) != this._constInfo)
                    {
                        scriptInfo.SF.Errors.Add(
                            new SemanticError("Member '" + this._constInfo.Name + "' already defined(" + m.SF.SFPath + "::" + m.Name + ")",
                                              treeInfo.GetErrorInfo(treeInfo.Current)));
                    }
                }
            }
        }
Esempio n. 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);
        }
Esempio n. 29
0
        public static void ParseRegion(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            MoveInfo        moveInfo = new MoveInfo(parentInfo);
            List <IElement> content  = new List <IElement>();

            content.Add(moveInfo.Current);
            content.Add(moveInfo.Move(SearchDirection.LeftToRight));

            moveInfo.Move(SearchDirection.LeftToRight);
            int nameStart = moveInfo.CurrentIndex;

            IElement end = moveInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Unvisible, IsRegionEnd);

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

            content.AddRange(moveInfo.CurrentElements.GetRange(nameStart, moveInfo.CurrentIndex - nameStart));

            IBlock region = new PreProcessorRegion(content);

            parentInfo.Replace(moveInfo.CurrentIndex - parentInfo.CurrentIndex, region);
        }
Esempio n. 30
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            int      startIndex = parentInfo.CurrentIndex;
            MoveInfo moveInfo   = new MoveInfo(parentInfo);

            // modifier
            MemberAccess   access;
            AccessModifier modifier = AccessModifier.GetModifier(moveInfo, out access);

            if (modifier != null)
            {
                startIndex = moveInfo.CurrentIndex;
            }

            // name
            moveInfo = new MoveInfo(parentInfo);
            IElement tryName = moveInfo.FindNextBlack(SearchDirection.LeftToRight);

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

            string   name     = tryName.ToString();
            UsingDef usingDef = new UsingDef(moveInfo.Current.CharIndex, moveInfo.Current.CharLength, moveInfo.Current.LineIndex);

            // assign
            moveInfo.FindNextBlack(SearchDirection.LeftToRight); // =
            moveInfo.FindNextBlack(SearchDirection.LeftToRight); // behind =

            // expression
            Path pathTry = Path.Parse(moveInfo, parsingInfo, scriptInfo);

            if (pathTry == null)
            {
                throw new SyntaxException("Could not find using path", parentInfo.GetErrorInfo());
            }

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

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

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

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

            // info

            // add const def to list
            parsingInfo.UsingDefList.Add(usingDef);

            /*if (scriptInfo.Constants.FindIndex(a => a.Name == name) != -1)
             *  ErrorManager.Semantic("Constant '" + name + "' already defined", new ErrorInfo(parentInfo.ErrorInfo));
             * else
             * {*/
            UsingInfo usingInfo = new UsingInfo(scriptInfo.SF, name, pathTry.ToString(), access, usingDef);

            scriptInfo.AddUsing(usingInfo);
            usingDef._usingInfo = usingInfo;
            //}
        }