public void Test()
        {
            try
            {
                var encoding = new UTF8Encoding();
                using var inStream = new MemoryStream();
                inStream.Write(encoding.GetBytes("let n : number = 2 * 5 - 3; Print(\"n = \", n);"));
                inStream.Seek(0, SeekOrigin.Begin);

                IScanner scanner = new Scanner(inStream);

                IAstBuilder astBuilder = new AstBuilder();

                var parser = new Parser(scanner, astBuilder);

                var rootNode = parser.ParseGoal();

                ISemanticChecks semanticChecks = new SemanticChecks();
                semanticChecks.Check(rootNode);

                using var outputStream = File.Create("hello.exe");
                ICodeGenerator codeGen = new CodeGenerator();

                codeGen.Run(rootNode, "hello", outputStream);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Console.WriteLine();
                throw;
            }
        }
        public void Semantics_WhenValidSemantics_DoesNotThrowException(string input)
        {
            // Arrange:
            var             rootNode           = BuildAst(input);
            ISemanticChecks semanticCheckCheck = new SemanticChecks();

            // Act:
            semanticCheckCheck.Check(rootNode);

            // Assert:
            Assert.Pass();
        }
        public void Semantics_WhenSemanticError_ThrowsSemanticException1(
            string input, string expectedMessage)
        {
            // Arrange:
            var             rootNode           = BuildAst(input);
            ISemanticChecks semanticCheckCheck = new SemanticChecks();

            // Act:
            void Lambda() => semanticCheckCheck.Check(rootNode);

            // Assert:
            var ex = Assert.Throws <SemanticErrorException>(Lambda);

            Assert.That(ex.Message, Is.EqualTo(expectedMessage));
        }
Beispiel #4
0
        public static void Main(string[] args)
        {
            using var inStream = new FileStream(args[0], FileMode.Open);
            inStream.Seek(0, SeekOrigin.Begin);

            IScanner scanner = new Scanner(inStream);

            IAstBuilder astBuilder = new AstBuilder();

            var parser = new Parser(scanner, astBuilder);

            var rootNode = parser.ParseGoal();

            ISemanticChecks semanticChecks = new SemanticChecks();

            semanticChecks.Check(rootNode);

            using var outputStream = File.Create("hello");
            ICodeGenerator codeGen = new CodeGenerator();

            codeGen.Run(rootNode, "hello", outputStream);
        }