Beispiel #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));
     }
 }
Beispiel #2
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);
     }
 }
Beispiel #3
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;
        }
Beispiel #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);
        }
Beispiel #5
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");
        }
Beispiel #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");
        }
Beispiel #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);
        }
        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;
        }
Beispiel #9
0
        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){}
        }