Ejemplo n.º 1
0
        /// <summary>
        ///    Driver routine to call the program script
        /// </summary>
        static void TestFileScript(string filename)
        {
            if (filename == null)
            {
                return;
            }


            // -------------- Read the contents from the file

            StreamReader sr        = new StreamReader(filename);
            string       programs2 = sr.ReadToEnd();


            //---------------- Creates the Parser Object
            // With Program text as argument
            RDParser pars = null;

            pars = new RDParser(programs2);
            TModule p = null;

            p = pars.DoParse();

            if (p == null)
            {
                Console.WriteLine("Parse Process Failed");
                return;
            }
            //
            //  Now that Parse is Successul...
            //  Do a recursive interpretation...!
            //
            RUNTIME_CONTEXT f  = new RUNTIME_CONTEXT(p);
            SYMBOL_INFO     fp = p.Execute(f);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///    Driver routine to call the program script
        /// </summary>
        static void TestFileScript(string filename)
        {
            if (filename == null)
            {
                return;
            }


            // -------------- Read the contents from the file

            StreamReader sr        = new StreamReader(filename);
            string       programs2 = sr.ReadToEnd();


            //---------------- Creates the Parser Object
            // With Program text as argument
            RDParser pars = null;

            pars = new RDParser(programs2);

            // Create a Compilation Context
            //
            //
            COMPILATION_CONTEXT ctx = new COMPILATION_CONTEXT();

            //
            // Call the top level Parsing Routine with
            // Compilation Context as the Argument
            //
            ArrayList stmts = pars.Parse(ctx);

            //
            // if we have reached here , the parse process
            // is successful... Create a Run time context and
            // Call Execute statements of each statement...
            //

            RUNTIME_CONTEXT f = new RUNTIME_CONTEXT();

            foreach (Object obj in stmts)
            {
                Stmt s = obj as Stmt;
                s.Execute(f);
            }
        }
        /// <summary>
        ///    Generate the JavaScript for the Eligibility rules...
        /// </summary>
        /// <param name="slang_text"></param>
        /// <returns></returns>
        public bool GenerateJSRuleEligible(string slang_text)
        {
            //---------------- Creates the Parser Object
            // With Program text as argument
            RDParser pars = null;

            pars = new RDParser(slang_text);

            _eligible_rules = pars.DoParse();

            if (_eligible_rules == null)
            {
                Console.WriteLine("Parse Process Failed while processing Eligibility rules");
                return(false);
            }
            //
            //  Now that Parse is Successul...
            //  Generate JavaScript
            //
            RUNTIME_CONTEXT f  = new RUNTIME_CONTEXT(_eligible_rules);
            SYMBOL_INFO     fp = _eligible_rules.GenerateJS(f, null);

            return(true);
        }
Ejemplo n.º 4
0
        public bool Render(string expression = null)
        {
            _cv.Children.Clear();
            double             y   = _cv.Height;
            double             x   = _cv.Width;
            Transform          txv = _cv.RenderTransform;
            TransformGroup     tg  = new TransformGroup();
            ScaleTransform     sc  = new ScaleTransform(1, -1);
            TranslateTransform tt  = new TranslateTransform(x / 2, y / 2);

            //tg.Children.Add(tt);
            tg.Children.Add(sc);
            tg.Children.Add(tt);

            _cv.RenderTransform = tg;
            Line myLine = new Line();

            myLine.Stroke = System.Windows.Media.Brushes.LightSteelBlue;
            myLine.X1     = -x / 2;
            myLine.Y1     = 0;
            myLine.X2     = x / 2;
            myLine.Y2     = 0;
            myLine.HorizontalAlignment = HorizontalAlignment.Left;
            myLine.VerticalAlignment   = VerticalAlignment.Center;
            myLine.StrokeThickness     = 2;
            _cv.Children.Add(myLine);
            myLine        = new Line();
            myLine.Stroke = System.Windows.Media.Brushes.LightSteelBlue;
            myLine.X1     = 0;
            myLine.Y1     = y / 2;
            myLine.X2     = 0;
            myLine.Y2     = -y / 2;
            myLine.HorizontalAlignment = HorizontalAlignment.Left;
            myLine.VerticalAlignment   = VerticalAlignment.Center;
            myLine.StrokeThickness     = 2;
            _cv.Children.Add(myLine);

            double            t     = -x / 2;
            double            final = x / 2;
            ExpressionBuilder bld   = new ExpressionBuilder(expr);
            Exp e = bld.GetExpression();

            if (e == null)
            {
                return(false);
            }
            RUNTIME_CONTEXT context = new RUNTIME_CONTEXT();

            context.T = t;

            for (; t < final; t += 4)
            {
                Line ln = new Line();
                context.T = t;
                double n = e.Evaluate(context);

                ln.X1     = t;
                ln.Y1     = n;
                ln.X2     = t;
                ln.Y1     = n;
                ln.Stroke = System.Windows.Media.Brushes.Red;

                ln.HorizontalAlignment = HorizontalAlignment.Left;
                ln.VerticalAlignment   = VerticalAlignment.Center;
                ln.StrokeThickness     = 2;
                _cv.Children.Add(ln);
            }

            return(true);
        }