public static Type CodeGenAndGetType(RppProgram program, string typeName, Diagnostic diagnostic) { var assembly = CodeGen(program, diagnostic); Type arrayTy = assembly.GetType(typeName); Assert.IsNotNull(arrayTy); return arrayTy; }
public static Assembly CodeGen(RppProgram program, Diagnostic diagnostic) { SymbolTable scope = new SymbolTable(null); RppTypeSystem.PopulateBuiltinTypes(scope); WireRuntime(scope); Assembly stdlib = RppCompiler.FindStdlib(); if (stdlib != null) { WireAssembly(scope, stdlib); } CodeGenerator generator = new CodeGenerator(program, "TestAssembly.dll"); Type2Creator typeCreator = new Type2Creator(); program.Accept(typeCreator); program.PreAnalyze(scope); InheritanceConfigurator2 configurator = new InheritanceConfigurator2(); program.Accept(configurator); CreateRType createRType = new CreateRType(diagnostic); program.Accept(createRType); if (diagnostic.Errors.Any()) { return null; } SemanticAnalyzerStage1 semanticStage1 = new SemanticAnalyzerStage1(diagnostic); program.Accept(semanticStage1); program.Analyze(scope, diagnostic); if (diagnostic.Errors.Any()) { return null; } SemanticAnalyzer semantic = new SemanticAnalyzer(diagnostic); program.Accept(semantic); if (diagnostic.Errors.Any()) { return null; } InitializeNativeTypes initializeNativeTypes = new InitializeNativeTypes(generator.Module); program.Accept(initializeNativeTypes); CreateNativeTypes createNativeTypes = new CreateNativeTypes(); program.Accept(createNativeTypes); generator.Generate(); return generator.Assembly; }
public static CodeGenerator Compile(Action<RppProgram> parseFactory, Diagnostic diagnostic, [CanBeNull] Assembly stdlibAssembly, string fileName = "<buffer>") { RppProgram program = new RppProgram(); SymbolTable runtimeScope = new SymbolTable(); RppTypeSystem.PopulateBuiltinTypes(runtimeScope); WireRuntime(runtimeScope); if (stdlibAssembly != null) { WireAssembly(runtimeScope, stdlibAssembly); } try { parseFactory(program); CodeGenerator generator = new CodeGenerator(program, fileName); Type2Creator typeCreator = new Type2Creator(); program.Accept(typeCreator); program.PreAnalyze(runtimeScope); InheritanceConfigurator2 configurator = new InheritanceConfigurator2(); program.Accept(configurator); CreateRType createRType = new CreateRType(diagnostic); program.Accept(createRType); SemanticAnalyzerStage1 semanticStage1 = new SemanticAnalyzerStage1(diagnostic); program.Accept(semanticStage1); program.Analyze(runtimeScope, null); SemanticAnalyzer semantic = new SemanticAnalyzer(diagnostic); program.Accept(semantic); InitializeNativeTypes initializeNativeTypes = new InitializeNativeTypes(generator.Module); program.Accept(initializeNativeTypes); CreateNativeTypes createNativeTypes = new CreateNativeTypes(); program.Accept(createNativeTypes); generator.Generate(); return generator; } catch (SemanticException e) { diagnostic.Error(e.Code, e.Message); return null; } catch (ParserException e) { diagnostic.Error(e.Code, e.Message); return null; } }
public static RppProgram Parse(string code) { RppParser parser = CreateParser(code); RppProgram compilationUnit = new RppProgram(); parser.CompilationUnit(compilationUnit); return compilationUnit; }
private bool ParseTmplDef(HashSet<ObjectModifier> modifiers, RppProgram program) { if (Require(RppLexer.KW_Trait)) { RaiseSyntaxError("Traits are not implemented"); } if (Require(RppLexer.KW_Class)) { RppClass obj = ParseClassDef(modifiers); program.Add(obj); return true; } if (Require(RppLexer.KW_Object)) { RppClass obj = ParseObjectDef(modifiers); program.Add(obj); return true; } return false; }
private bool ParseTopStat(RppProgram program) { var modifiers = ParseObjectModifier(); return ParseTmplDef(modifiers, program); }
private void ParseTopStatSeq(RppProgram program) { while (ParseTopStat(program)) { ParseSemi(); } }
public RppProgram CompilationUnit(RppProgram program) { if (Require(RppLexer.KW_Package)) { // ReSharper disable once UnusedVariable QualifiedId id = ParseQualifiedId(); ExpectSemi(); } SkipNewLines(); ParseTopStatSeq(program); SkipNewLines(); Expect(RppLexer.EOF); return program; }
public static void Parse(string code, RppProgram program) { try { RppParser parser = CreateParser(code); parser.CompilationUnit(program); } catch (UnexpectedTokenException e) { var lines = GetLines(code); var line = lines[e.Actual.Line - 1]; Console.WriteLine("Systax error at line: {0}, unexpected token '{1}'", e.Actual.Line, e.Actual.Text); Console.WriteLine(line); Console.WriteLine("{0}^ Found '{1}', but expected '{2}'", Ident(e.Actual.CharPositionInLine), e.Actual.Text, e.Expected); Environment.Exit(-1); } }
private static void Parse(IEnumerable<string> fileNames, RppProgram program) { fileNames.ForEach(fileName => Parse(File.ReadAllText(fileName), program)); }
public virtual void Visit(RppProgram node) { }