Пример #1
0
        public void AddCode(string name, string code)
        {
            var pp = new Preprocessor(context.Report);

            pp.AddCode("machine.h", context.MachineInfo.HeaderCode);
            pp.AddCode(name, code);
            var lexer  = new Lexer(pp);
            var parser = new CParser();

            Add(parser.ParseTranslationUnit(lexer, context.Report));
        }
Пример #2
0
        public InternalFunction(string prototype, InternalFunctionAction action = null)
        {
            var report = new Report(new TextWriterReportPrinter(Console.Out));
            var parser = new CParser();
            var pp     = new Preprocessor(report);

            pp.AddCode("<Internal>", prototype + ";");
            var tu = parser.ParseTranslationUnit(new Lexer(pp), report);
            var f  = tu.Functions[0];

            Name         = f.Name;
            FunctionType = f.FunctionType;

            Action = action;
        }
Пример #3
0
        public static Interpreter.Executable Compile(string code, MachineInfo machineInfo = null, Report.Printer printer = null)
        {
            var report = new Report(printer);

            var mi = machineInfo ?? new MachineInfo();

            var pp = new Preprocessor(report);

            pp.AddCode("machine.h", mi.HeaderCode);
            pp.AddCode(DefaultName, code);
            var lexer  = new Lexer(pp);
            var parser = new CParser();
            var tu     = parser.ParseTranslationUnit(lexer);

            var c = new Interpreter.Compiler(mi, report);

            c.Add(tu);
            var exe = c.Compile();

            return(exe);
        }
Пример #4
0
        public static TranslationUnit ParseTranslationUnit(string code, Report report)
        {
            var parser = new CParser();

            return(parser.ParseTranslationUnit(DefaultCodePath, code, ((_, __) => null), report));
        }