Example #1
0
        static void TestGenerate()
        {
            Console.WriteLine("");
            Compiler      c            = new Compiler();
            List <string> lExpressions = new List <string>();

            Console.WriteLine("testing: let x = y;");
            lExpressions.Add("let x = y;");
            try
            {
                c.Compile(lExpressions);
                Console.WriteLine("test failed, you didnot throwed an Exception");
            }
            catch (SyntaxErrorException e)
            {
                Console.WriteLine("you throwed Exception as needed, just make sure it came from Generate-code and not before");
                Console.WriteLine("your Exception message is: " + e.Message + "\n it should be: symbol was not declared");
            }

            //________________________________________________________________________________________________
            //------------------------------------------------------------------------------------------------
            Console.WriteLine("");
            Compiler      c1            = new Compiler();
            List <string> l1Expressions = new List <string>();
            string        s             = "let z = (+ (- x 12) (+ y 3));";

            Console.WriteLine("testing: " + s);
            l1Expressions.Add("s");
            try
            {
                c1.Compile(lExpressions);
                Console.WriteLine("test failed, you didnot throwed an Exception");
            }
            catch (SyntaxErrorException e)
            {
                Console.WriteLine("you throwed Exception as needed, just make sure it came from Generate-code and not before");
                Console.WriteLine("your Exception message is: " + e.Message + "\n it should be: symbol was not declared");
            }

            //________________________________________________________________________________________________
            //------------------------------------------------------------------------------------------------
            Console.WriteLine("");
            Compiler      c2            = new Compiler();
            List <string> l2Expressions = new List <string>();

            s = "let x = x;";
            Console.WriteLine("testing: " + s);
            l2Expressions.Add("s");
            try
            {
                c2.Compile(lExpressions);
                Console.WriteLine("test failed, you didnot throwed an Exception");
            }
            catch (SyntaxErrorException e)
            {
                Console.WriteLine("you throwed Exception as needed, just make sure it came from Generate-code and not before");
                Console.WriteLine("your Exception message is: " + e.Message + "\n it should be: symbol was not declared");
            }

            //________________________________________________________________________________________________
            //------------------------------------------------------------------------------------------------
            Console.WriteLine("");
            Compiler      c3            = new Compiler();
            List <string> l3Expressions = new List <string>();

            s = "let x = (+ x 3);";
            Console.WriteLine("testing: " + s);
            l3Expressions.Add("s");
            try
            {
                c3.Compile(lExpressions);
                Console.WriteLine("test failed, you didnot throwed an Exception");
            }
            catch (SyntaxErrorException e)
            {
                Console.WriteLine("you throwed Exception as needed, just make sure it came from Generate-code and not before");
                Console.WriteLine("your Exception message is: " + e.Message + "\n it should be: symbol was not declared");
            }

            //________________________________________________________________________________________________
            //------------------------------------------------------------------------------------------------

            /*           Compiler c = new Compiler();
             *         List<string> lExpressions = new List<string>();
             *         lExpressions.Add("let x = (+ (- 53 12) (- 467 3));");
             *         lExpressions.Add("let y = 3;");
             *     lExpressions.Add("let z = (+ (- x 12) (+ y 3));");
             */
        }
Example #2
0
        private void CallCompile()
        {
            var tree = CallParse();

            if (tree == null)
                return;

            AddTextLineToOutput("Building...", Color.YellowGreen);

            var compiler = new Compiler();
            compiler.Compile(tree);
        }