Exemplo n.º 1
0
        public bool ContinueWith(SyntaxTree input)
        {
            if (input == null || input.Diagnostics.Any())
            {
                if (chainDiagnostics)
                {
                    diagnostics.AddDiagnostics(input.Diagnostics);
                }

                return(false);
            }

            if (interperatations == null)
            {
                interperatations = new List <Interperatation>();
            }

            var interperatation = new Interperatation(input, CurrentInterpretation);

            if (interperatation.Diagnostics.Any())
            {
                if (chainDiagnostics)
                {
                    diagnostics.AddDiagnostics(interperatation.Diagnostics);
                }

                return(false);
            }
            else
            {
                interperatations.Add(interperatation);
                return(true);
            }
        }
Exemplo n.º 2
0
        public SyntaxTree(string input, bool parseFull = true)
        {
            Diagnostics = new DiagnosticContainer();
            Source      = new TextSource(input);
            var tokenStream = GetTokens(input);

            tokenStream.Fill();
            Tokens = tokenStream.GetTokens();

            if (parseFull)
            {
                CommonTokenStream tokens = GetTokens(input);
                GLangParser       parser = new GLangParser(tokens);
                parser.RemoveErrorListeners();

                var ast = ASTProducer.CreateAST(parser.compilationUnit());

                if (ast.Value is CompilationUnitSyntax compSyntax)
                {
                    Root = compSyntax;
                }
                else
                {
                    Root = null;
                }

                Diagnostics.AddDiagnostics(ast.Diagnostics);
            }
        }
Exemplo n.º 3
0
        public BoundProgram CreateProgram()
        {
            if (GlobalScope == null || GlobalScope.Root == null || diagnostics.Any())
            {
                return(null);
            }

            var program = Binder.BindProgram(GlobalScope);

            diagnostics.AddDiagnostics(program.Diagnostics);

            if (program.Value == null)
            {
                return(null);
            }

            Interlocked.CompareExchange(ref boundProgram, program.Value, null);
            diagnostics.AddDiagnostics(program.Diagnostics);

            return(program.Value);
        }