Пример #1
0
        public override void Compile(MoveInfo treeInfo, ScriptInfo scriptInfo, CompilingInfo compilingInfo)
        {
            Assign tryAssign = _exp.GetChildren()[0] as Assign;

            if (tryAssign != null)
            {
                ArrayContentDef tryArrayContentDef = tryAssign.Exp.GetChildren()[0] as ArrayContentDef;
                if (tryArrayContentDef != null)
                {
                    IElement compiledStatements = tryArrayContentDef.GetCompiledStatements(tryAssign.VarName);
                    treeInfo.ReplaceCurrent(compiledStatements);
                }
            }
        }
Пример #2
0
 public virtual void Compile(MoveInfo treeInfo, ScriptInfo scriptInfo, CompilingInfo compilingInfo)
 {
 }
Пример #3
0
        public override void Compile(MoveInfo treeInfo, ScriptInfo scriptInfo, CompilingInfo compilingInfo)
        {
            /*
             * _statement
             * !BlockStatement
             * =================================
             * do
             *  statement;
             * while (exp);
             * =================================
             *
             * _statement
             * BlockStatement
             * ScopeGroup
             *
             * =================================
             * var = true; while (var || exp)
             * { var = false; statement; }
             *
             * =================================
             *
             * =================================
             * do
             * {
             *  statement;
             * }
             * while (exp);
             * =================================
             *
             * =================================
             * var = true; while (var || exp)
             * { var = false;
             *  statement;
             * }
             *
             * =================================
             */

            Token      firstVar = new Token(TokenType.Word, "doWhileJHS8G8AW9_" + compilingInfo.IteratorsCount++);
            Expression exp      = (Expression)_expParentGroup.GetContent().Find(a => a is Expression);

            // "doWhileControlVar = true;"
            BallOfMud firstVarInit = new BallOfMud(
                new List <IElement>()
            {
                firstVar,
                Token.Space,
                Token.Assign,
                Token.Space,
                Token.True,
                Token.SemiColon
            });

            // "doWhileControlVar = false;"
            BallOfMud firstVarCancel = new BallOfMud(
                new List <IElement>()
            {
                firstVar,
                Token.Space,
                Token.Assign,
                Token.Space,
                Token.False,
                Token.SemiColon
            });

            BallOfMud blockVarInsert = new BallOfMud(
                new List <IElement> {
                Token.Space, firstVarCancel
            });

            #region Replace "do" with "doWhileControlVar = true; while (doWhileControlVar || exp)"
            // "(doWhileControlVar || exp)"
            BallOfMud newExpression = new BallOfMud(
                new List <IElement> {
                Token.ParenthesesOpen,
                firstVar,
                Token.Space,
                Token.LogicOR,
                Token.Space,
                exp,
                Token.ParenthesesClose
            });

            // "doWhileControlVar = true; while (doWhileControlVar || exp)"
            BallOfMud doReplace = new BallOfMud(
                new List <IElement> {
                firstVarInit,
                Token.Space,
                WhileKeyword,
                Token.Space,
                newExpression
            });

            int doIndex = this.children.IndexOf(_doKeyword);
            this.children[doIndex] = doReplace;
            #endregion

            #region Add fisrtVarCancel & add block
            if (_statement is BlockStatement) // it is already block ...
            {
                ScopeGroup blockGroup = (ScopeGroup)_statement.GetChildren().Find(a => a is ScopeGroup);
                blockGroup.GetContent().Insert(0, blockVarInsert);
            }
            else // create block
            {
                // "{ doWhileControlVar = false; statement; }"
                BallOfMud blockForInsert = new BallOfMud(
                    new List <IElement> {
                    Token.ScopeOpen,
                    Token.Space,
                    firstVarCancel,
                    Token.Space,
                    _statement,
                    Token.Space,
                    Token.ScopeClose
                });

                int statementI  = this.children.IndexOf(_statement);
                int tryTabIndex = statementI - 1;
                if (tryTabIndex >= 0 &&
                    this.children[tryTabIndex].IsTT(TokenType.WhiteSpace) &&
                    this.children[tryTabIndex].ToString() == "\t")
                {
                    this.children.RemoveAt(tryTabIndex);
                    statementI--;
                }
                this.children[statementI] = blockForInsert;
            }
            #endregion

            // delete "while (exp);"
            int whileKeywordI = this.children.IndexOf(_whileKeyword);
            this.children.RemoveRange(whileKeywordI, this.children.Count - whileKeywordI);
        }
Пример #4
0
        public override void Compile(MoveInfo treeInfo, ScriptInfo scriptInfo, CompilingInfo compilingInfo)
        {
            /*
             * =================================
             * foreach (var in array)
             *  statement;
             * =================================
             *
             * =================================
             * for (i = 0; i < array.size; i++)
             * { var = array[i]; statement; }
             * =================================
             *
             * =================================
             * foreach (var in array)
             * {
             *  statement;
             * }
             * =================================
             *
             * =================================
             * for (i = 0; i < array.size; i++)
             * { var = array[i];
             *  statement;
             * }
             * =================================
             */

            Token indexer = new Token(TokenType.Word, "foreachg45e74f_" + compilingInfo.IteratorsCount++);

            #region Replace "foreach (var in array)" with "for (i = 0; i < array.size; i++)"
            // "i = 0"
            BallOfMud indexerInit = new BallOfMud(
                new List <IElement>()
            {
                indexer,
                Token.Space,
                Token.Assign,
                Token.Space,
                NumberZero
            });

            // "i < array.size"
            BallOfMud indexerCondition = new BallOfMud(
                new List <IElement>()
            {
                indexer,
                Token.Space,
                Token.LogicLess,
                Token.Space,
                _array,
                Token.Ref,
                KeywordSize
            });

            // "i++"
            BallOfMud indexerStatement = new BallOfMud(
                new List <IElement>()
            {
                indexer,
                Token.INC
            });

            // "(i = 0; i < array.size; i++)"
            BallOfMud foreachGroupReplace = new BallOfMud(
                new List <IElement> {
                Token.ParenthesesOpen,
                indexerInit,
                Token.SemiColon,
                Token.Space,
                indexerCondition,
                Token.SemiColon,
                Token.Space,
                indexerStatement,
                Token.ParenthesesClose
            });

            int foreachI = this.children.IndexOf(_foreachKeyword);
            this.children[foreachI] = KeywordFor;

            int foreachGroupI = this.children.IndexOf(_foreachGroup);
            this.children[foreachGroupI] = foreachGroupReplace;
            #endregion

            #region Add var define & add block
            // " var = array[i];"
            BallOfMud varDefine = new BallOfMud(
                new List <IElement> {
                Token.Space,
                _currentVar,
                Token.Space,
                Token.Assign,
                Token.Space,
                _array,
                Token.SQBracketOpen,
                indexer,
                Token.SQBracketClose,
                Token.SemiColon
            });

            if (_statement is BlockStatement) // it is already block ...
            {
                ScopeGroup blockGroup = (ScopeGroup)_statement.GetChildren().Find(a => a is ScopeGroup);
                blockGroup.GetContent().Insert(0, varDefine);
            }
            else // create block
            {
                // "{ var = array[i]; statement; }"
                BallOfMud blockForInsert = new BallOfMud(
                    new List <IElement> {
                    Token.ScopeOpen,
                    varDefine,
                    Token.Space,
                    _statement,
                    Token.Space,
                    Token.ScopeClose
                });

                int statementI  = this.children.IndexOf(_statement);
                int tryTabIndex = statementI - 1;
                if (tryTabIndex >= 0 &&
                    this.children[tryTabIndex].IsTT(TokenType.WhiteSpace) &&
                    this.children[tryTabIndex].ToString() == "\t")
                {
                    this.children.RemoveAt(tryTabIndex);
                    statementI--;
                }

                this.children[statementI] = blockForInsert;
            }
            #endregion
        }
Пример #5
0
        public override void Compile(MoveInfo treeInfo, ScriptInfo scriptInfo, CompilingInfo compilingInfo)
        {
            if (this._constInfo.SF.SFPath == "compiler")
            {
                IElement e = null;
                switch (this._constInfo.Name)
                {
                case "Time":
                    e = new Token(TokenType.String, DateTime.Now.ToShortTimeString());
                    break;

                case "Date":
                    e = new Token(TokenType.String, DateTime.Now.ToShortDateString());
                    break;

                case "DateTime":
                    e = new Token(TokenType.String, DateTime.Now.ToString());
                    break;

                case "FilePath":
                    e = new Token(TokenType.String, scriptInfo.SF.SFPath);
                    break;

                case "FilePathFull":
                    e = new Token(TokenType.String, scriptInfo.SF.SFFullPath);
                    break;

                case "Line":
                    e = new Token(TokenType.Number, treeInfo.Current.LineIndex + 1);
                    break;

                case "FunctionName":
                    var function1     = treeInfo.FindBlockInStack <FuncDef>(true);
                    var function1Name = "";
                    if (function1 != null)
                    {
                        function1Name = function1.FuncInfo.Name;
                    }
                    e = new Token(TokenType.String, function1Name);
                    break;

                case "FunctionSignature":
                    var function2          = treeInfo.FindBlockInStack <FuncDef>(true);
                    var function2Signature = "";
                    if (function2 != null)
                    {
                        function2Signature = function2.FuncInfo.GetHead();
                    }
                    e = new Token(TokenType.String, function2Signature);
                    break;

                case "VersionInt":
                    e = new Token(TokenType.Number, scriptInfo.SF.Manager.Settings.VersionInt);
                    break;

                case "VersionStr":
                    e = new Token(TokenType.String, scriptInfo.SF.Manager.Settings.VersionStr);
                    break;

                case "TargetPlatform":
                    e = new Token(TokenType.Number, (int)scriptInfo.SF.Manager.Settings.TargetPlatform);
                    break;

                case "TargetPlatform_Windows":
                    e = new Token(TokenType.Number, (int)TargetPlatform.Windows);
                    break;

                case "TargetPlatform_Linux":
                    e = new Token(TokenType.Number, (int)TargetPlatform.Linux);
                    break;

                case "TargetPlatform_LinuxNinja":
                    e = new Token(TokenType.Number, (int)TargetPlatform.LinuxNinja);
                    break;

                case "TargetConfiguration":
                    e = new Token(TokenType.Number, (int)scriptInfo.SF.Manager.Settings.TargetConfiguration);
                    break;

                case "TargetConfiguration_Debug":
                    e = new Token(TokenType.Number, (int)TargetConfiguration.Debug);
                    break;

                case "TargetConfiguration_Release":
                    e = new Token(TokenType.Number, (int)TargetConfiguration.Release);
                    break;

                case "TargetConfiguration_FinalRelease":
                    e = new Token(TokenType.Number, (int)TargetConfiguration.FinalRelease);
                    break;

                default:
                    throw new ArgumentException("Unknown compiler constant '" + _constInfo.Name + "', " + scriptInfo.SF.ToString());
                }
                treeInfo.ReplaceCurrent(e);
            }
        }