コード例 #1
0
        private Expression ReadExpression(ScriptReader source, bool readTerminatingSymbolFromStream, params PredefinedSymbol[] endsWithSymbols)
        {
            Expression expression   = new Expression();
            int        bracketLevel = 0;

            while (bracketLevel >= 0)
            {
                foreach (PredefinedSymbol terminatingSymbol in endsWithSymbols)
                {
                    if ((bracketLevel == 0) && (source.NextIsKeyword(terminatingSymbol, !readTerminatingSymbolFromStream)))
                    {
                        return(expression);
                    }
                }

                Token thisToken = source.PeekNextToken();
                if (thisToken is EndOfStreamToken)
                {
                    throw new CompilerMessage(ErrorCode.EndOfInputReached, "End of script reached in the middle of an expression");
                }

                CompilerUtils.AdjustBracketLevelIfTokenIsBracket(thisToken, ref bracketLevel);

                if (bracketLevel >= 0)
                {
                    expression.Add(source.ReadNextToken());
                }
            }
            throw new CompilerMessage(ErrorCode.UnexpectedToken, "Unexpected '" + source.ReadNextToken() + "'");
        }
コード例 #2
0
        public CompileResults CompileScript(string script)
        {
            ITokenizer tokenizer = CompilerFactory.CreateTokenizer();

            _tokenizedScript = tokenizer.TokenizeScript(script);
            _source          = new ScriptReader(_tokenizedScript);
            _output          = new CompiledScript();

            while (true)
            {
                Token thisToken = _source.ReadNextToken();

                if (thisToken is EndOfStreamToken)
                {
                    break;
                }

                try
                {
                    ProcessTokenAtTopLevel(thisToken);
                }
                catch (CompilerMessage error)
                {
                    RecordError(error.Code, error.Message);
                    break;
                }
            }

            return(_results);
        }
コード例 #3
0
ファイル: ScriptCompiler.cs プロジェクト: Aquilon96/ags
		public CompileResults CompileScript(string script)
		{
			ITokenizer tokenizer = CompilerFactory.CreateTokenizer();
            _tokenizedScript = tokenizer.TokenizeScript(script);
			_source = new ScriptReader(_tokenizedScript);
			_output = new CompiledScript();

			while (true)
			{
				Token thisToken = _source.ReadNextToken();

				if (thisToken is EndOfStreamToken)
				{
					break;
				}

				try
				{
					ProcessTokenAtTopLevel(thisToken);
				}
				catch (CompilerMessage error)
				{
					RecordError(error.Code, error.Message);
                    break;
				}
			}

			return _results;
		}
コード例 #4
0
        private void GenerateCodeForExpressionWithoutOperator(Expression expression)
        {
            System.Diagnostics.Trace.WriteLine(expression.ToString());

            ScriptReader reader     = new ScriptReader(expression, _source.LineNumber);
            Token        firstToken = reader.ReadNextToken();
            Token        memberName = null;

            bool staticAccess = false;

            if (firstToken.IsVariableType)
            {
                staticAccess = true;
            }
            else if (reader.NextIsKeyword(PredefinedSymbol.OpenSquareBracket))
            {
                Expression arrayIndex = ReadExpression(reader, true, PredefinedSymbol.CloseSquareBracket);
                GenerateCodeForExpression(arrayIndex);
                // TODO: Array access
            }

            if (reader.NextIsKeyword(PredefinedSymbol.Dot))
            {
                if ((firstToken.Type != TokenType.LocalVariable) &&
                    (firstToken.Type != TokenType.GlobalVariable) &&
                    (firstToken.Type != TokenType.StructType))
                {
                    throw new CompilerMessage(ErrorCode.ParentIsNotAStruct, "'" + firstToken.Name + "' is not a struct");
                }
                memberName = reader.ReadNextToken();

                // TODO: struct member stuff
                if (staticAccess)
                {
                }
            }
            else if (staticAccess)
            {
                throw new CompilerMessage(ErrorCode.InvalidUseOfStruct, "Struct cannot be used in this way");
            }
            else
            {
                // TODO: just read the variable itself / execute the function
            }

            // TODO: Code this
        }
コード例 #5
0
ファイル: CompilerUtils.cs プロジェクト: writeescape/ags
        public static void SetArrayPropertiesOnTokenFromStream(ScriptReader source, Token variableName)
        {
            if (source.NextIsKeyword(PredefinedSymbol.OpenSquareBracket))
            {
                variableName.IsArray = true;

                if (source.NextIsKeyword(PredefinedSymbol.CloseSquareBracket))
                {
                    variableName.ArraySize = Token.ARRAY_SIZE_DYNAMIC;
                }
                else
                {
                    variableName.ArraySize = source.ReadNextAsConstInt();
                    source.ExpectKeyword(PredefinedSymbol.CloseSquareBracket);
                }
            }
        }
コード例 #6
0
ファイル: CompilerUtils.cs プロジェクト: smarinel/ags-web
        public static void SetArrayPropertiesOnTokenFromStream(ScriptReader source, Token variableName)
        {
            if (source.NextIsKeyword(PredefinedSymbol.OpenSquareBracket))
            {
                variableName.IsArray = true;

                if (source.NextIsKeyword(PredefinedSymbol.CloseSquareBracket))
                {
                    variableName.ArraySize = Token.ARRAY_SIZE_DYNAMIC;
                }
                else
                {
                    variableName.ArraySize = source.ReadNextAsConstInt();
                    source.ExpectKeyword(PredefinedSymbol.CloseSquareBracket);
                }
            }
        }
コード例 #7
0
ファイル: CodeBlockCompiler.cs プロジェクト: Aquilon96/ags
        private Expression ReadExpression(ScriptReader source, bool readTerminatingSymbolFromStream, params PredefinedSymbol[] endsWithSymbols)
        {
            Expression expression = new Expression();
            int bracketLevel = 0;
            while (bracketLevel >= 0)
            {
                foreach (PredefinedSymbol terminatingSymbol in endsWithSymbols)
                {
                    if ((bracketLevel == 0) && (source.NextIsKeyword(terminatingSymbol, !readTerminatingSymbolFromStream)))
                    {
                        return expression;
                    }
                }

                Token thisToken = source.PeekNextToken();
                if (thisToken is EndOfStreamToken)
                {
                    throw new CompilerMessage(ErrorCode.EndOfInputReached, "End of script reached in the middle of an expression");
                }

                CompilerUtils.AdjustBracketLevelIfTokenIsBracket(thisToken, ref bracketLevel);

                if (bracketLevel >= 0)
                {
                    expression.Add(source.ReadNextToken());
                }
            }
            throw new CompilerMessage(ErrorCode.UnexpectedToken, "Unexpected '" + source.ReadNextToken() + "'");
        }
コード例 #8
0
ファイル: CodeBlockCompiler.cs プロジェクト: Aquilon96/ags
        private void GenerateCodeForExpressionWithoutOperator(Expression expression)
        {
            System.Diagnostics.Trace.WriteLine(expression.ToString());

            ScriptReader reader = new ScriptReader(expression, _source.LineNumber);
            Token firstToken = reader.ReadNextToken();
            Token memberName = null;

            bool staticAccess = false;
            if (firstToken.IsVariableType)
            {
                staticAccess = true;
            }
            else if (reader.NextIsKeyword(PredefinedSymbol.OpenSquareBracket))
            {
                Expression arrayIndex = ReadExpression(reader, true, PredefinedSymbol.CloseSquareBracket);
                GenerateCodeForExpression(arrayIndex);
                // TODO: Array access
            }

            if (reader.NextIsKeyword(PredefinedSymbol.Dot))
            {
                if ((firstToken.Type != TokenType.LocalVariable) &&
                    (firstToken.Type != TokenType.GlobalVariable) &&
                    (firstToken.Type != TokenType.StructType))
                {
                    throw new CompilerMessage(ErrorCode.ParentIsNotAStruct, "'" + firstToken.Name + "' is not a struct");
                }
                memberName = reader.ReadNextToken();

                // TODO: struct member stuff
                if (staticAccess)
                {
                }
            }
            else if (staticAccess)
            {
                throw new CompilerMessage(ErrorCode.InvalidUseOfStruct, "Struct cannot be used in this way");
            }
            else
            {
                // TODO: just read the variable itself / execute the function
            }

            // TODO: Code this
        }
コード例 #9
0
ファイル: CodeBlockCompiler.cs プロジェクト: Aquilon96/ags
        /// <summary>
        /// Starts processing a code block from the input stream. It is assumed
        /// to start with a { or be a single expression.
        /// </summary>
        public void Process(ScriptReader script)
        {
            _source = script;

            ProcessCodeBlock();
        }
コード例 #10
0
        /// <summary>
        /// Starts processing a code block from the input stream. It is assumed
        /// to start with a { or be a single expression.
        /// </summary>
        public void Process(ScriptReader script)
        {
            _source = script;

            ProcessCodeBlock();
        }