Esempio n. 1
0
        public syntax_tree_node BuildTree(string FileName, string Text, ParseMode ParseMode)
        {
            //if (parser == null)
            Reset();

            GPPGParser.current_file_name  = FileName;
            GPPGParser.CompilerDirectives = compilerDirectives;

            Scanner scn = new Scanner();

            scn.SetSource(Text, 0);

            parser.scanner = scn;

            bool b = parser.Parse();

            if (!b)
            {
                // if we can't recognize error :( or brain.dll not loaded
                Errors.ErrorMsg err = new Errors.ErrorMsg(GPPGParser.current_file_name, new SourceContext(0, 0, 0, 0), "PROGRAM_ERROR");
                GPPGParser.errors.Add(err);
            }

            Errors = GPPGParser.errors;

            syntax_tree_node cu = null;

            switch (ParseMode)
            {
            case ParseMode.Normal:
                cu = GPPGParser.CompilationUnit;
                break;

            case ParseMode.Expression:
            case ParseMode.Statement:
                return(null);
            }

            if (cu != null && cu is compilation_unit)
            {
                (cu as compilation_unit).file_name           = FileName;
                (cu as compilation_unit).compiler_directives = CompilerDirectives;
            }
            return(cu);
        }
Esempio n. 2
0
        public syntax_tree_node BuildTree(string FileName, string Text, ParseMode ParseMode)
        {
            //if (parser == null)
            Reset();
            
            GPPGParser.current_file_name = FileName;
            GPPGParser.CompilerDirectives = compilerDirectives;
            
            Scanner scn = new Scanner();
            scn.SetSource(Text, 0);

            parser.scanner = scn;

            bool b = parser.Parse();

            if (!b)
            {
                // if we can't recognize error :( or brain.dll not loaded
                Errors.ErrorMsg err = new Errors.ErrorMsg(GPPGParser.current_file_name,new SourceContext(0,0,0,0),"PROGRAM_ERROR");
                GPPGParser.errors.Add(err);
            }

            Errors = GPPGParser.errors;

            syntax_tree_node cu = null;

            switch (ParseMode)
            {
                case ParseMode.Normal:
                    cu = GPPGParser.CompilationUnit;
                    break;
                case ParseMode.Expression:
                case ParseMode.Statement:
                    return null;
            }

            if (cu != null && cu is compilation_unit)
            {
                (cu as compilation_unit).file_name = FileName;
                (cu as compilation_unit).compiler_directives = CompilerDirectives;
            }
            return cu;
        }