Пример #1
0
        public void LexerScansComment()
        {
            const string program = "/*Hi*///Hello, World!!!";
            var          tokens  = _lexer.LexFile(program).ToArray();

            Assert.All(tokens, token => Assert.True(token.Catagory == TokenCatagory.Comment));
            Assert.True(tokens.First().Kind == TokenKind.BlockComment);
            Assert.True(tokens.Last().Kind == TokenKind.LineComment);
        }
Пример #2
0
        private static void Main(string[] args)
        {
            MonitorScriptLexer  lexer  = new MonitorScriptLexer();
            MonitorScriptParser parser = new MonitorScriptParser(lexer.ErrorSink);

            System.Console.Write("MonitorScript> ");
            var program = @"Pattern FindWhiteVideo Repeating, TELLER, Something, George
{ 
	Start Event
	Body Event 
	Body Event Optional
	Stop Event 
	Reset Event 
}";

//            program = @"func test (string three)
//{
//    var one = 1;
//    var two = 2;
//}";


            //var program = Console.ReadLine();
            var sourceCode = new SourceCode(program);
            var tokens     = lexer.LexFile(sourceCode).ToArray();

            foreach (var token in tokens)
            {
                System.Console.WriteLine($"{token.Kind} ( \"{token.Value.Replace("\n", "\\n").Replace("\r", "\\r")}\" ) ");
            }

            if (lexer.ErrorSink.Count() > 0)
            {
                foreach (var error in lexer.ErrorSink)
                {
                    System.Console.WriteLine(new string('-', System.Console.WindowWidth / 3));

                    WriteError(error);
                }
                lexer.ErrorSink.Clear();
            }
            else
            {
                // Abstract syntax tree
                var ast = parser.ParseFile(sourceCode, tokens, MonitorScriptParserOptions.OptionalSemicolons);
                if (lexer.ErrorSink.Count() > 0)
                {
                    foreach (var error in lexer.ErrorSink)
                    {
                        System.Console.WriteLine(new string('-', System.Console.WindowWidth / 3));

                        WriteError(error);
                    }
                    lexer.ErrorSink.Clear();
                }
            }

            System.Console.WriteLine(new string('-', System.Console.WindowWidth / 2));



            System.Console.WriteLine("END OF PROGRAM");
            System.Console.ReadLine();
        }