Esempio n. 1
0
        public void ParseLine(string value, bool expected)
        {
            var grammer = new AsmStructuralGrammar();
            var p = new ParserState(value);

            Assert.That(grammer.line.Match(p), Is.EqualTo(expected));

            var printer = new CppStructuralOutputAsXml();
            printer.Print(p.GetRoot());
            Console.WriteLine(printer.AsXml());
        }
Esempio n. 2
0
        public void ParseOpCode(string value, bool expected)
        {
            var grammer = new AsmBaseGrammar();
            var printer = new CppStructuralOutputAsXml();
            var p = new ParserState(value);

            Assert.That(grammer.opcode.Match(p), Is.EqualTo(expected));

            ParseNode node = p.GetRoot();
            Console.WriteLine(node.Value);
        }
Esempio n. 3
0
        public void Block(string expression, bool expected)
        {
            var grammer = new AndyStructuralGrammar();
            var p = new ParserState(expression);

            Assert.That(grammer.block.Match(p), Is.EqualTo(expected));

            var printer = new CppStructuralOutputAsXml();
            printer.Print(p.GetRoot());
            Console.WriteLine(printer.AsXml());
        }
Esempio n. 4
0
        public void OpenFile(string file)
        {
            var grammar = new AsmStructuralGrammar();
            file = string.Concat(_testPaths[Environment.MachineName], file);

            var outputFile = Path.ChangeExtension(file, ".asm");
            using (var stringWriter = File.CreateText(outputFile))
            using (var writer = new InstructionTextWriter(stringWriter))
            {
                string source = File.ReadAllText(file);
                var parser = new ParserState(source);
                var result = grammar.program.Match(parser);
                Assert.That(result, Is.True);

                var printer = new CppStructuralOutputAsXml();
                printer.Print(parser.GetRoot());
                Console.WriteLine(printer.AsXml());

                var assembler = new Assembler(parser);
                assembler.Assemble().ToList().ForEach(writer.Write);
            }
        }
Esempio n. 5
0
        public void UnaryInteger(string integer, bool expected)
        {
            var grammer = new AndyStructuralGrammar();
            var p = new ParserState(integer);

            Assert.That(grammer.term.Match(p), Is.EqualTo(expected));

            var printer = new CppStructuralOutputAsXml();
            printer.Print(p.GetRoot());
            Console.WriteLine(printer.AsXml());
        }
Esempio n. 6
0
        public void ParseComment()
        {
            var grammar = new CppStructuralGrammar();
            var output = new CppStructuralOutputAsXml();
            var parserState = CppSourceParser.Parse("/* Comment */", output, rule: grammar.declaration_list);
            Assert.That(parserState.ParseException, Is.Null);

            Console.WriteLine(output.AsXml());
        }
Esempio n. 7
0
        public void Can_parse(string source)
        {
            var sourceFile = Path.Combine(Source_Directory, source);
            if (!File.Exists(sourceFile))
                Assert.Inconclusive("Cannot find filename " + sourceFile);

            var output = new CppStructuralOutputAsXml();

            var result = CppFileParser.Parse(sourceFile, output);
            Console.WriteLine(result.GetRoot());
            Assert.That(result.ParseException, Is.Null);

            Console.WriteLine("Actual");
            Console.WriteLine(output.AsXml());
            Console.WriteLine();
        }