Esempio n. 1
0
        private void bCompile_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                SemanticAnalyzer an = new SemanticAnalyzer();

                var st = System.IO.File.ReadAllText(FileToCompile);
                var tokens = Lexer.ProcessString(st);
                var values = Parser.ProcessTokens(tokens);

                an.CreateSymbolTable(values);
                an.DeriveTypes();
                an.ValidateFuncCalls();

                CodeGenerator cg = new CodeGenerator(an.FuncTable);
                cg.GenerateCFunctions();
                compiledString = cg.WriteCFunctionsToString();

                ErrorMessage.Text = "";
                isCompiled = true;
                bCompile.IsEnabled = true;
                bSave.IsEnabled = true;
            }
            catch (Exception ee)
            {
                ErrorMessage.Text = ee.Message;
            }
        }
Esempio n. 2
0
        public void ReadFromFileAndTryToParse()
        {
            string content = File.ReadAllText(@"d:\tests\input.lsp");

            SemanticAnalyzer an = new SemanticAnalyzer();

            var tokens = Lexer.ProcessString(content);

            var values = Parser.ProcessTokens(tokens);

            an.CreateSymbolTable(values);
            an.DeriveTypes();
            an.ValidateFuncCalls();
        }
Esempio n. 3
0
        public void TestCodeGeneration()
        {
            string content = File.ReadAllText(@"D:\Temp\input.lsp");

            SemanticAnalyzer an = new SemanticAnalyzer();

            var tokens = Lexer.ProcessString(content);

            var values = Parser.ProcessTokens(tokens);

            an.CreateSymbolTable(values);

            an.DeriveTypes();

            an.ValidateFuncCalls();

            CodeGenerator cg = new CodeGenerator(an.FuncTable);
            cg.GenerateCFunctions();
            cg.WriteCFunctionsToFile("main.c");
        }
Esempio n. 4
0
        public void TestCondCodeGeneration()
        {
            string content = "(defun f (x) (cond   ((< x 5) 7)   ((> x 7) 13)   (T (cond (( < x 1) 9) (T 123)))))";

            SemanticAnalyzer an = new SemanticAnalyzer();

            var tokens = Lexer.ProcessString(content);

            var values = Parser.ProcessTokens(tokens);

            an.CreateSymbolTable(values);

            an.DeriveTypes();

            an.ValidateFuncCalls();

            CodeGenerator cg = new CodeGenerator(an.FuncTable);
            cg.GenerateCFunctions();
            cg.WriteCFunctionsToFile("main.c");
        }
Esempio n. 5
0
        public void TryParseCond()
        {
            var content = "(defun rvrs (l1 l2) (cond ((null l1) l2) (T (cons (car l1) l2))))";

            SemanticAnalyzer an = new SemanticAnalyzer();

            var tokens = Lexer.ProcessString(content);

            var values = Parser.ProcessTokens(tokens);

            an.CreateSymbolTable(values);
            an.DeriveTypes();
            an.ValidateFuncCalls();
        }