Exemple #1
0
        /// <summary>
        /// <see cref="CurrentModule"/>で指定したソースコードを直接解析し、実行します。
        /// </summary>
        /// <param name="source">ソースコード</param>
        public KecaknoahObject DoString(string source)
        {
            var le = Lexer.AnalyzeFromSource(source);

            if (!le.Success)
            {
                throw new KecaknoahException(le.Error);
            }
            var ast = Parser.Parse(le);

            if (!ast.Success)
            {
                throw new KecaknoahException(le.Error);
            }
            var src = Precompiler.PrecompileAll(ast);

            CurrentModule.RegisterSource(src);
            if (CurrentModule["main"] != KecaknoahNil.Instance)
            {
                return(new KecaknoahContext(CurrentModule).Execute(CurrentModule["main"]));
            }
            else
            {
                return(KecaknoahNil.Instance);
            }
        }
Exemple #2
0
        /// <summary>
        /// <see cref="CurrentModule"/>で指定したソースコードを式として解析し、実行します。
        /// </summary>
        /// <param name="source">ソースコード</param>
        public KecaknoahObject DoExpressionString(string source)
        {
            var le = Lexer.AnalyzeFromSource(source);

            if (!le.Success)
            {
                throw new KecaknoahException(le.Error);
            }
            var ast = Parser.ParseAsExpression(le);

            if (!ast.Success)
            {
                throw new KecaknoahException(le.Error);
            }
            var src = Precompiler.PrecompileExpression(ast);

            return(new KecaknoahContext(CurrentModule).Execute(src));
        }