Example #1
0
        /// <summary>
        ///
        /// </summary>
        static void TestSecondScript()
        {
            string    a   = "PRINTLINE -2*10;" + "\r\n" + "PRINTLINE -10*-1;\r\n PRINT 2*10;\r\n";
            RDParser  p   = new RDParser(a);
            ArrayList arr = p.Parse();

            foreach (object obj in arr)
            {
                Stmt s = obj as Stmt;
                s.Execute(null);
            }
        }
Example #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);
            }
        }
Example #3
0
        public object Call(params object[] args)
        {
            //if (argNames.Length != args.Length) throw new Exception("wrong number of args");

            NameEnv env = new NameEnv(globals, new Dict());
            int     i   = 0;

            for (; i < args.Length; i++)
            {
                env.Set(argNames[i], args[i]);
            }

            int di = i - (argNames.Length - defaults.Length);

            while (i < argNames.Length)
            {
                env.Set(argNames[i++], defaults[di++]);
            }

            return(body.Execute(env));
        }