예제 #1
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            ConstDef     constDef = new ConstDef(parentInfo.Current.CharIndex, parentInfo.Current.CharLength, parentInfo.Current.LineIndex);
            MemberAccess access   = MemberAccess.Public;
            bool         isSealed = false;

            int      startIndex = parentInfo.CurrentIndex;
            MoveInfo moveInfo   = new MoveInfo(parentInfo);

            // sealed modifier
            SealedModifier trySealed = SealedModifier.GetModifier(moveInfo);

            if (trySealed != null)
            {
                startIndex = moveInfo.CurrentIndex;
                isSealed   = true;
            }
            else
            {
                moveInfo = new MoveInfo(parentInfo);
            }

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

            if (tryAccess != null)
            {
                startIndex = moveInfo.CurrentIndex;
            }
            else
            {
                moveInfo = new MoveInfo(parentInfo);
            }

            // xml
            XMLBlock xml = XMLBlock.GetXMLSummary(moveInfo);

            constDef.xmlBlock = xml;
            if (xml != null)
            {
                startIndex = moveInfo.CurrentIndex;
            }

            // assign
            moveInfo = new MoveInfo(parentInfo);
            IElement nameElem = moveInfo.Current;

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

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

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

            constDef._compiledContent = exp;

            // 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;

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

            // info
            string name = nameElem.ToString();

            // add const def to list
            parsingInfo.ConstDefList.Add(constDef);

            /*if (scriptInfo.Constants.FindIndex(a => a.Name == name) != -1)
             *  ErrorManager.Semantic("Constant '" + name + "' already defined", new ErrorInfo(parentInfo.ErrorInfo));
             * else
             * {*/
            ConstInfo constInfo = GetInfo(name, access, exp, isSealed, constDef.xmlBlock, parsingInfo, constDef);

            scriptInfo.AddConstant(constInfo);
            constDef._constInfo = constInfo;
            //}
        }
예제 #2
0
        public static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            FuncDef function = new FuncDef(parentInfo.Current.CharIndex, parentInfo.Current.CharLength, parentInfo.Current.LineIndex, parsingInfo.SF);

            // začiatok názvu
            MoveInfo moveInfo = new MoveInfo(parentInfo);

            int startIndex = parentInfo.CurrentIndex;

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

            if (modifier != null)
            {
                startIndex = moveInfo.CurrentIndex;
            }
            else
            {
                moveInfo = new MoveInfo(parentInfo);
            }

            // xml
            XMLBlock xml = XMLBlock.GetXMLSummary(moveInfo);

            function.xmlBlock = xml;
            if (xml != null)
            {
                startIndex = moveInfo.CurrentIndex;
            }

            // začiatok názvu
            moveInfo = new MoveInfo(parentInfo);
            IElement nameElem = moveInfo.Current;

            moveInfo.Move(SearchDirection.LeftToRight);

            // parametry
            IElement paramsTry = moveInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible);

            if (!(paramsTry is ParenthesesGroup))
            {
                throw new SyntaxException("Could not find FuncDef parameters", parentInfo.GetErrorInfo());
            }

            ParenthesesGroup paramsGroup = (ParenthesesGroup)paramsTry;
            // získaj zoznam parametrov
            MoveInfo            paramsMoveInfo = new MoveInfo(paramsGroup, SearchTree.ContentBlock, 0, moveInfo);
            List <FuncDefParam> defParams      = GetParameterList(paramsMoveInfo, parsingInfo, scriptInfo);

            // pridaj zoznam parametrov do stromu a posuň sa zaň
            moveInfo.Move(SearchDirection.LeftToRight);

            // body
            IElement bodyTry = moveInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible);

            if (!(bodyTry is ScopeGroup))
            {
                throw new SyntaxException("Could not find FuncDef body", parentInfo.GetErrorInfo());
            }

            ScopeGroup      bodyGroup         = (ScopeGroup)bodyTry;
            List <IElement> bodyGroupChildren = bodyGroup.GetChildren();

            moveInfo.Move(SearchDirection.LeftToRight); // skoč za telo

            // add func to tree
            int             totalLength = moveInfo.CurrentIndex - startIndex;
            List <IElement> children    = parentInfo.CurrentElements.GetRange(startIndex, totalLength);

            function.AddChildren(children);


            foreach (FuncDefParam p in defParams)
            {
                function.LocalVars.Add(new LocalVarInfo(parsingInfo.SF, p.Name, (int)function.ImportantCharIndex, (int)function.ImportantCharLength, null, p.VarName)); // it must be after function.AddChildren() !!
            }
            parentInfo.MoveToIndex(startIndex);
            parentInfo.Replace(totalLength, function);

            // set current function
            parsingInfo.CurrentFunc = function;
            parsingInfo.FuncDefList.Add(function);

            // go inside body
            MoveInfo bodyInfo = new MoveInfo(bodyGroup, SearchTree.ContentBlock, 0, parentInfo);

            Statement.ParseStatementList(bodyInfo, parsingInfo, scriptInfo);

            // info
            string name = nameElem.ToString();

            /*if (scriptInfo.)
             * if (scriptInfo.Functions.FindIndex(a => a.Name.EqualCode(name)) != -1)
             * {
             *  ErrorManager.Semantic("Function '" + name + "' already defined", new ErrorInfo(parentInfo.ErrorInfo));
             *  return;
             * }*/

            FuncInfo funcInfo = GetInfo(name, access, defParams, xml, parsingInfo, function);

            scriptInfo.AddFunction(funcInfo);

            function.funcInfo = funcInfo;
        }
예제 #3
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            DelegateCall delegCall = new DelegateCall();
            MoveInfo     moveInfo  = new MoveInfo(parentInfo);

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

            Expression deleg = Expression.Parse(groupInfo, parsingInfo, scriptInfo);

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

            #region ParsingInfo Args
            object lastCall         = parsingInfo.CurrentCall;
            int?   lastCallArgIndex = parsingInfo.CurrentCallArgIndex;
            parsingInfo.CurrentCall         = delegCall;
            parsingInfo.CurrentCallArgIndex = 0;
            #endregion

            // find args
            moveInfo.FindNextBlack(SearchDirection.LeftToRight);
            if (!FuncArgs.Check(moveInfo, parsingInfo, scriptInfo))
            {
                throw new SyntaxException("Could not find delegate funcArgs", parentInfo.GetErrorInfo());
            }

            int startIndex = parentInfo.CurrentIndex;
            int length;

            #region ParsingInfo Args
            parsingInfo.CurrentCall         = lastCall;
            parsingInfo.CurrentCallArgIndex = lastCallArgIndex;
            #endregion

            // find self and modifiers
            MoveInfo selfInfo = new MoveInfo(parentInfo);
            IElement self     = selfInfo.FindNextBlack(SearchDirection.RightToLeft);
            if (self != null && self is ExpressionOperand) // self is self or FuncCallModifier
            {
                startIndex = selfInfo.CurrentIndex;
                if (self is FuncCallModifier) // self is FuncCallModifier -> find self
                {
                    self = selfInfo.FindNextBlack(SearchDirection.RightToLeft);
                    if (self != null && self is ExpressionOperand)
                    {
                        startIndex = selfInfo.CurrentIndex;
                    }
                }
            }

            // 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)));

            // build
            delegCall.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));
            parentInfo.MoveToIndex(startIndex);
            parentInfo.Replace(length, delegCall);
        }
예제 #4
0
        private static void ParseLocal(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            FuncCall funcCall = new FuncCall();

            MoveInfo moveInfo = new MoveInfo(parentInfo);

            funcCall._nameElem = (Token)moveInfo.Current;
            funcCall._name     = moveInfo.Current.ToString();

            #region ParsingInfo Args
            FuncInfo tryOutFuncInfo = scriptInfo.FindGlobalsFunc(funcCall._name);
            if (tryOutFuncInfo != null && tryOutFuncInfo.HasOutParams)
            {
                parsingInfo.OutParamFuncCall     = funcCall;
                parsingInfo.OutParamFuncInfo     = tryOutFuncInfo;
                parsingInfo.OutParamFuncArgIndex = 0;
            }

            object lastCall         = parsingInfo.CurrentCall;
            int?   lastCallArgIndex = parsingInfo.CurrentCallArgIndex;
            parsingInfo.CurrentCall         = funcCall;
            parsingInfo.CurrentCallArgIndex = 0;
            #endregion

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

            #region ParsingInfo Args
            if (parsingInfo.OutParamFuncCall != null)
            {
                parsingInfo.OutParamFuncCall = null;
            }

            parsingInfo.CurrentCall         = lastCall;
            parsingInfo.CurrentCallArgIndex = lastCallArgIndex;
            #endregion

            int startIndex = parentInfo.CurrentIndex;
            int length;

            // find self and modifiers
            MoveInfo selfInfo = new MoveInfo(parentInfo);
            IElement self     = selfInfo.FindNextBlack(SearchDirection.RightToLeft);
            if (self != null && self is ExpressionOperand) // self is self or FuncCallModifier
            {
                startIndex = selfInfo.CurrentIndex;
                if (self is FuncCallModifier) // self is FuncCallModifier -> find self
                {
                    self = selfInfo.FindNextBlack(SearchDirection.RightToLeft);
                    if (self != null && self is ExpressionOperand)
                    {
                        startIndex = selfInfo.CurrentIndex;
                    }
                }
            }

            // 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)));

            // build
            funcCall.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));
            parentInfo.MoveToIndex(startIndex);
            parentInfo.Replace(length, funcCall);
        }