Esempio n. 1
0
        public Program(string name, Module[] modules, Settings settings)
            : base(NodeKind.Program, new Cursor(name))
        {
            _modules = modules;
            foreach (Module module in _modules)
                module.Above = this;

            _settings = settings;
        }
Esempio n. 2
0
 public Walker[] Configure(Settings settings)
 {
     return new Walker[0];
 }
Esempio n. 3
0
        public Walker[] Configure(Settings settings)
        {
            var walkers = new List<Walker>();

            // Create the symbols defined by the language core.
            walkers.Add(new CreateLanguageSymbolsWalker());

            // Enter all top-level symbols such as scopes, entries, classes, records, and enumerations into the symbol table.
            walkers.Add(new CreateToplevelSymbolsWalker());

            // Resolve symbols - i.e. create a link from each applied reference to each definition, except for routines!
            walkers.Add(new ResolveSymbolsWalker());

            // Synthesize encoded/mangled name for all routines, all call statements, and all call expressions.
            walkers.Add(new EncodeRoutinesWalker());

            // Resolve all routines and all call expressions now that they have been successfully encoded (mangled).
            walkers.Add(new ResolveRoutinesWalker());

            // Determine absolute name of all symbols in the AST.
            walkers.Add(new CreateAbsolutePathNamesWalker());

            #if DONE
            // Resolve all class references so that they are fully resolved.
            // BOGUS: walkers.Add(new ResolveClassReferencesWalker());

            // Create symbol table entries for all class members so that they are accessible through 'this' or 'base'.
            walkers.Add(new CreateMemberSymbolsWalker());

            // Resolve types, can safely be done now that all other symbols have been resolved.
            walkers.Add(new ResolveTypesWalker());

            // Resolve calls, whether in expressions or in statements.
            //walkers.Add(new ResolveInvocationsWalker());

            #if false
            // Resolve all initializers now that everything else has been resolved successfully.
            walkers.Add(new ResolveInitializersWalker());

            #endif
            // Make sure that all procedures end in a return statement (simplifies the writers).
            walkers.Add(new AppendReturnNothingStatementWalker());
            #endif
            return walkers.ToArray();
        }
Esempio n. 4
0
        public Module Load(Settings settings, string filename)
        {
            _keywords["address"]     = TokenKind.Keyword_Address;
            _keywords["array"]       = TokenKind.Keyword_Array;
            _keywords["boolean"]     = TokenKind.Keyword_Boolean;
            _keywords["call"]        = TokenKind.Keyword_Call;
            _keywords["cardinal"]    = TokenKind.Keyword_Cardinal;
            _keywords["character"]   = TokenKind.Keyword_Character;
            _keywords["class"]       = TokenKind.Keyword_Class;
            _keywords["create"]      = TokenKind.Keyword_Create;
            #if FUTURE
            _keywords["delegate"]    = TokenKind.Keyword_Delegate;
            #endif
            _keywords["delete"]      = TokenKind.Keyword_Delete;
            _keywords["entry"]       = TokenKind.Keyword_Entry;
            _keywords["enumeration"] = TokenKind.Keyword_Enumeration;
            _keywords["exit"]        = TokenKind.Keyword_Exit;
            _keywords["external"]    = TokenKind.Keyword_External;
            _keywords["false"]       = TokenKind.Keyword_False;
            _keywords["field"]       = TokenKind.Keyword_Field;
            _keywords["function"]    = TokenKind.Keyword_Function;
            _keywords["get"]         = TokenKind.Keyword_Get;
            _keywords["guard"]       = TokenKind.Keyword_Guard;
            _keywords["import"]      = TokenKind.Keyword_Import;
            _keywords["in"]          = TokenKind.Keyword_In;
            _keywords["integer"]     = TokenKind.Keyword_Integer;
            #if FUTURE
            _keywords["interface"]   = TokenKind.Keyword_Interface;
            #endif
            _keywords["io"]          = TokenKind.Keyword_Io;
            _keywords["is"]          = TokenKind.Keyword_Is;
            _keywords["let"]         = TokenKind.Keyword_Let;
            _keywords["method"]      = TokenKind.Keyword_Method;
            _keywords["new"]         = TokenKind.Keyword_New;
            _keywords["none"]        = TokenKind.Keyword_None;
            #if FUTURE
            _keywords["object"]      = TokenKind.Keyword_Object;
            #endif
            _keywords["of"]          = TokenKind.Keyword_Of;
            _keywords["out"]         = TokenKind.Keyword_Out;
            _keywords["record"]      = TokenKind.Keyword_Record;
            _keywords["return"]      = TokenKind.Keyword_Return;
            _keywords["scope"]       = TokenKind.Keyword_Scope;
            _keywords["set"]         = TokenKind.Keyword_Set;
            _keywords["text"]        = TokenKind.Keyword_Text;
            _keywords["true"]        = TokenKind.Keyword_True;
            #if FUTURE
            _keywords["type"]        = TokenKind.Keyword_Type;
            #endif
            _keywords["value"]       = TokenKind.Keyword_Value;

            /** Tokenize the input file and store the result in \c _tokens. */
            {
                _tokens.Clear();
                Scanner scanner = new Scanner();
                scanner.Filename = filename;
                scanner.Keywords = _keywords;
                scanner.OnErrorReady += PrintError;
                scanner.OnTokenReady += PrintToken;
                scanner.Produce();
            }

            Matcher matcher = new Matcher(_tokens.ToArray());
            Parser parser = new Parser(settings.Logger, matcher);
            return parser.ParseModule();
        }