Example #1
0
        public TelemetryFilter()
        {
            List <TraceAggregationConfig> traceAggregationConfigs;
            List <ParseResult>            parseResults = SyntaxAnalyzer.Parse(ConfigFileName, new string[] { }, Utility.TraceSource.WriteError, false, out traceAggregationConfigs);

            foreach (var telConfig in traceAggregationConfigs)
            {
                try
                {
                    // including the aggregator to white-list
                    this.whiteListedEventsFromConfigFile.Add(new Tuple <string, string>(telConfig.TaskName, telConfig.EventName), telConfig);
                }
                catch (ArgumentNullException e)
                {
                    Utility.TraceSource.WriteError(LogSourceId, "Unexpected null value parsed from config file: {0} - Exception: {1}.", ConfigFileName, e);
                }
                catch (ArgumentException e)
                {
                    if (telConfig.DifferentiatorFieldName == this.whiteListedEventsFromConfigFile[new Tuple <string, string>(telConfig.TaskName, telConfig.EventName)].DifferentiatorFieldName)
                    {
                        Utility.TraceSource.WriteWarning(LogSourceId, "Conflicting trace white-listing (trace already white-listed) -Trace: {0} - Exception : {1}.", telConfig, e);
                    }
                }
            }

            // Tracing any errors that may have occured during parsing
            foreach (var parseRes in parseResults)
            {
                if (parseRes.ParseCode != ParseCode.Success)
                {
                    Utility.TraceSource.WriteError(LogSourceId, "{0}({1},{2}) : Error : {3}", ConfigFileName, parseRes.LineNumber, parseRes.ColumnPos + 1, parseRes.ErrorMsg);
                }
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            string sourcePath = "";

            if (args.Any())
            {
                sourcePath = args[0];
            }
            else
            {
                Console.Write($"Paste source file need to compile:{Environment.NewLine}" +
                              "> ");
                sourcePath = Console.ReadLine();
            }

            try
            {
                LexicalAnalyzer.Parse(sourcePath);
                SyntaxAnalyzer.Parse();
                Console.WriteLine("Синтаксический анализ окончен");
                SemanticAnalyzer.Parse();
                Console.WriteLine("Семантический анализ окончен");
                if (!(IsSyntaxCorrect && Root.IsSemanticCorrect))
                {
                    Console.WriteLine("Возникли ошибки сборки. Ассемблерный код не будет сгенерирован");
                }
                else
                {
                    Root.GenerateIntermediateCode();
                    GeneratingAssembleCode.Generate();
                    Console.WriteLine("Ассемблерный код сгенерирован");
                }
            }
            catch (CompilerException e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("Press any key to finish...");
            Console.ReadLine();
        }
Example #3
0
        public void Parse_Query()
        {
            var text   = "select * from MyTable";
            var lexems = _syntaxAnalyzer.Parse(text).ToList();

            Assert.AreEqual(4, lexems.Count);
            int i = 0;

            Assert.AreEqual(0, lexems[i].StartPosition);
            Assert.AreEqual(5, lexems[i].EndPosition);
            Assert.AreEqual("select", lexems[i].Name);
            Assert.AreEqual(LexemKind.Keyword, lexems[i].Kind);
            i++;
            Assert.AreEqual(7, lexems[i].StartPosition);
            Assert.AreEqual(7, lexems[i].EndPosition);
            Assert.AreEqual("*", lexems[i].Name);
            Assert.AreEqual(LexemKind.Delimiter, lexems[i].Kind);
            i++;
            Assert.AreEqual(9, lexems[i].StartPosition);
            Assert.AreEqual(12, lexems[i].EndPosition);
            Assert.AreEqual("from", lexems[i].Name);
            Assert.AreEqual(LexemKind.Keyword, lexems[i].Kind);
            i++;
            Assert.AreEqual(14, lexems[i].StartPosition);
            Assert.AreEqual(20, lexems[i].EndPosition);
            Assert.AreEqual("MyTable", lexems[i].Name);
            Assert.AreEqual(LexemKind.Identifier, lexems[i].Kind);
        }
Example #4
0
        private static void ExecuteSyntaxTest(Lexer lexer)
        {
            var analyzer = new SyntaxAnalyzer(lexer);

            analyzer.Parse();
        }
        static void Main(string[] args)
        {
            var tests = new List <string>()
            {
                "2 + 3",
                "2 - 3",
                "2 * 3",
                "2 / 3",
                "2+3",
                "2-3",
                "2*3",
                "2/3",
                "2*3+1--6",
                "5 ** ( 6 + 10 )",
                "5**(6+10)",
                "5 ** ( ( 6 + 10 ) * 5 )",
                "5**((6+10)*5)",
            };

            var expectations = new List <double>()
            {
                5,
                -1,
                6,
                0.6666666666666666,
                5,
                -1,
                6,
                0.6666666666666666,
                13,
                152587890625,
                152587890625,
                8.271806125530277E+55,
                8.271806125530277E+55,
            };

            Console.WriteLine("Starting tests...\n");
            var counter       = 0;
            var passedCounter = 0;

            foreach (string test in tests)
            {
                var sb               = new StringBuilder();
                var table            = new TransitionTable();
                var lexical_analyzer = new LexicalAnalyzer(table);
                var syntax_analyzer  = new SyntaxAnalyzer();
                var executor         = new Executor();
                var tokens1          = lexical_analyzer.Parse(test);
                var tokens2          = syntax_analyzer.Parse(tokens1);
                var result           = executor.Execute(tokens2);

                Console.WriteLine(string.Format(" >>> Test {0}", counter));
                Console.WriteLine(string.Format("case\t\t\'{0}\'", test));
                Console.WriteLine(string.Format("expectation\t{0}", expectations[counter]));
                Console.WriteLine(string.Format("result\t\t{0}", result));

                if (result == expectations[counter])
                {
                    passedCounter++;
                    Console.WriteLine("OK!\n");
                }
                else
                {
                    Console.WriteLine("FAILURE!\n");
                }

                counter++;
            }

            Console.WriteLine("RESULT: {0}/{1}!\n", passedCounter, counter);
            Console.ReadKey();
        }