コード例 #1
0
 public static AST.Node LoadFile(string fileName, LexerMode mode, FunctionInformation functionInfo)
 {
     using (StreamReader file = new StreamReader(fileName, Parse.Latin1))
     {
         return(Parse.String(file.ReadToEnd(), mode, functionInfo));
     }
 }
コード例 #2
0
ファイル: Parse.cs プロジェクト: sammoorhouse/aplusdotnet
 public static AST.Node LoadFile(string fileName, LexerMode mode, FunctionInformation functionInfo)
 {
     using (StreamReader file = new StreamReader(fileName, Parse.Latin1))
     {
         return Parse.String(file.ReadToEnd(), mode, functionInfo);
     }
 }
コード例 #3
0
ファイル: Parse.cs プロジェクト: sammoorhouse/aplusdotnet
        public static AST.Node UNIString(string input, FunctionInformation functionInfo)
        {
            Antlr.Runtime.Lexer lexer = new Grammar.Uni.AplusLexer(new ANTLRStringStream(input ?? ""));
            Grammar.AplusParser parser = new Grammar.AplusParser(new CommonTokenStream(lexer));
            parser.FunctionInfo = functionInfo;

            bool parseOk = parser.Parse();
            return parser.Tree;
        }
コード例 #4
0
        public static AST.Node UNIString(string input, FunctionInformation functionInfo)
        {
            Antlr.Runtime.Lexer lexer  = new Grammar.Uni.AplusLexer(new ANTLRStringStream(input ?? ""));
            Grammar.AplusParser parser = new Grammar.AplusParser(new CommonTokenStream(lexer));
            parser.FunctionInfo = functionInfo;

            bool parseOk = parser.Parse();

            return(parser.Tree);
        }
コード例 #5
0
ファイル: Parse.cs プロジェクト: sammoorhouse/aplusdotnet
        public static AST.Node String(string input, LexerMode mode, FunctionInformation functionInfo)
        {
            switch (mode)
            {
                case LexerMode.ASCII:
                    return ASCIIString(input, functionInfo);

                case LexerMode.APL:
                    return APLString(input, functionInfo);

                case LexerMode.UNI:
                    return UNIString(input, functionInfo);

                default:
                    break;
            }

            throw new ParseException("Invalid Parse Mode");
        }
コード例 #6
0
        public static AST.Node String(string input, LexerMode mode, FunctionInformation functionInfo)
        {
            switch (mode)
            {
            case LexerMode.ASCII:
                return(ASCIIString(input, functionInfo));

            case LexerMode.APL:
                return(APLString(input, functionInfo));

            case LexerMode.UNI:
                return(UNIString(input, functionInfo));

            default:
                break;
            }

            throw new ParseException("Invalid Parse Mode");
        }
コード例 #7
0
        public DLR.Expression <System.Func <Runtime.Aplus, AType> > ParseToLambda(string code)
        {
            AplusScope scope = new AplusScope(null, "__top__", this.aplus,
                                              DLR.Expression.Parameter(typeof(Aplus), "__aplusRuntime__"),
                                              DLR.Expression.Parameter(typeof(DYN.IDynamicMetaObjectProvider), "__module__")
                                              );

            FunctionInformation funcionInfo = new FunctionInformation(this.aplus.CurrentContext);

            if (this.aplus.Context != null)
            {
                funcionInfo.LoadInfo((this.aplus.Context as Scope).Storage as ScopeStorage);
            }

            DLR.Expression codebody = null;
            AST.Node       tree     = Compiler.Parse.String(code, this.aplus.LexerMode, funcionInfo);

            if (tree == null)
            {
                codebody = DLR.Expression.Constant(null);
            }
            else
            {
                codebody = DLR.Expression.Block(
                    new DLR.ParameterExpression[] { scope.ModuleExpression },
                    DLR.Expression.Assign(
                        scope.ModuleExpression, DLR.Expression.PropertyOrField(scope.RuntimeExpression, "Context")
                        ),
                    tree.Generate(scope)
                    );
            }

            DLR.Expression <System.Func <Aplus, AType> > method =
                DLR.Expression.Lambda <Func <Aplus, AType> >(
                    codebody,
                    scope.RuntimeExpression
                    );
            return(method);
        }
コード例 #8
0
        public DLR.Expression<System.Func<Runtime.Aplus, AType>> ParseToLambda(string code)
        {
            AplusScope scope = new AplusScope(null, "__top__", this.aplus,
                DLR.Expression.Parameter(typeof(Aplus), "__aplusRuntime__"),
                DLR.Expression.Parameter(typeof(DYN.IDynamicMetaObjectProvider), "__module__")
            );

            FunctionInformation funcionInfo = new FunctionInformation(this.aplus.CurrentContext);
            if (this.aplus.Context != null)
            {
                funcionInfo.LoadInfo((this.aplus.Context as Scope).Storage as ScopeStorage);
            }

            DLR.Expression codebody = null;
            AST.Node tree = Compiler.Parse.String(code, this.aplus.LexerMode, funcionInfo);

            if (tree == null)
            {
                codebody = DLR.Expression.Constant(null);
            }
            else
            {
                codebody = DLR.Expression.Block(
                    new DLR.ParameterExpression[] { scope.ModuleExpression },
                    DLR.Expression.Assign(
                        scope.ModuleExpression, DLR.Expression.PropertyOrField(scope.RuntimeExpression, "Context")
                    ),
                    tree.Generate(scope)
                );
            }

            DLR.Expression<System.Func<Aplus, AType>> method =
                DLR.Expression.Lambda<Func<Aplus, AType>>(
                    codebody,
                    scope.RuntimeExpression
                );
            return method;
        }
コード例 #9
0
ファイル: UnitTest1.cs プロジェクト: szledan/aplusdotnet
        public void TestAPlusCoreCompiler()
        {
            //VariableHelper Tests
            VariableHelper.BuildValueQualifiedName("str.1", "str2");
            VariableHelper.CreateContextParts("str1", "str2");
            VariableHelper.CreateContextParts("", "str2");

            //FunctionInformation Tests
            FunctionInformation fi = new FunctionInformation("stringContext");
            fi.IsLocalFunction("string2");
            fi.RegisterLocalFunction("string");
            fi.Context = "string";

            //ParseExcemtion Tests
            ParseException pe = new ParseException("string");
            if (pe.CanContinue){}
        }