public CompilationResult Compile([FromBody] CompilationRequest request)
        {
            CompilationResult result   = new CompilationResult();
            LexicalAnalyzer   analyzer = new LexicalAnalyzer(LexicalLanguage.GetLanguage(), request.Input);
            BottomUpParser    parser   = new BottomUpParser(analyzer);

            parser.Parse();

            result.IL       = parser.GetILAsString();
            result.Assembly = new CodeGenerator().GenerateAsString(parser.GetIL());

            return(result);
        }
        public ASTResult AST([FromBody] CompilationRequest request)
        {
            ASTResult result = new ASTResult();

            LexicalAnalyzer analyzer = new LexicalAnalyzer(LexicalLanguage.GetLanguage(), request.Input);
            BottomUpParser  parser   = new BottomUpParser(analyzer);

            parser.Parse();

            result.AST += "digraph C {\r\n";
            result.AST += parser.TopLevelAST.ToDot();
            result.AST += "}";

            return(result);
        }
        public LexicalAnalyzerResult Tokenize([FromBody] LexicalAnalyzerRequest request)
        {
            LexicalAnalyzerResult result = new LexicalAnalyzerResult();

            LexicalAnalyzer analyzer = new LexicalAnalyzer(LexicalLanguage.GetLanguage(), request.Input);

            Token current = analyzer.GetNextToken();

            result.Tokens.Add(TokenToModel(current));

            while (!(current is EndOfFileToken))
            {
                current = analyzer.GetNextToken();
                result.Tokens.Add(TokenToModel(current));
            }

            return(result);
        }
Example #4
0
        public LogicalElement GetTreeForQuery(string query)
        {
            try
            {
                LexicalAnalyzer analyzer = new LexicalAnalyzer(LexicalLanguage.GetLanguage(), query);
                Parser.Parse(analyzer);

                SyntaxTreeNode command = Parser.TopLevelAST;

                return(GetElementForTreeNode(command));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            return(null);
        }
Example #5
0
        static void Main(string[] args)
        {
            string input = File.ReadAllText(args[0]);

            Stopwatch       sw       = Stopwatch.StartNew();
            LexicalAnalyzer analyzer = new LexicalAnalyzer(LexicalLanguage.GetLanguage(), input);
            BottomUpParser  parser   = new BottomUpParser(analyzer);

            parser.Parse();

            Console.WriteLine(new CodeGenerator().GenerateAsString(parser.GetIL()));

            sw.Stop();

            Console.WriteLine($"Done (took {sw.ElapsedMilliseconds} milliseconds)");

            Console.ReadLine();
            Console.ReadLine();
            Console.ReadLine();
            Console.ReadLine();
        }
Example #6
0
        public void Intersect()
        {
            new LexicalAnalyzer(LexicalLanguage.GetLanguage(), "\"AMD\"").GetNextToken();

            TableDefinition productsTable = new TableDefinition()
            {
                Name = "Product"
            };

            productsTable.Add(new AttributeDefinition()
            {
                Name = "Maker", Type = ValueType.String
            });
            productsTable.Add(new AttributeDefinition()
            {
                Name = "Model", Type = ValueType.String
            });
            productsTable.Add(new AttributeDefinition()
            {
                Name = "Type", Type = ValueType.String
            });

            Set products1 = new Set(productsTable);

            products1.Add(new object[] { "A", "10001", "PC" });
            products1.Add(new object[] { "B", "10001", "PC" });
            products1.Add(new object[] { "B", "10002", "PC" });
            products1.Add(new object[] { "B", "10002", "Laptop" });

            Set products2 = new Set(productsTable);

            products2.Add(new object[] { "A", "10001", "PC" });
            products2.Add(new object[] { "B", "10002", "Laptop" });
            products2.Add(new object[] { "C", "10003", "Laptop" });

            Set intersection = products1.Intersect(products2);

            Assert.AreEqual(2, intersection.Count());
        }