Explore tens of thousands of sets crafted by our community.
Compiler Design Patterns
15
Flashcards
0/15
Decorator Pattern
The Decorator pattern allows behavior to be added to individual objects, statically or dynamically, without affecting the behavior of other objects from the same class. Compilers use this to extend functionalities of specific nodes in AST without modifying the class itself.
Abstract Factory Pattern
The Abstract Factory pattern provides an interface for creating families of related or dependent objects without specifying their concrete classes. A compiler might use this to handle different target languages or environments.
Visitor Pattern
The Visitor pattern is used to separate an algorithm from an object structure on which it operates. In compilers, it's used to perform operations on an AST, such as type-checking and code generation, without modifying the nodes.
Interpreter Pattern
The Interpreter pattern is about defining a representation for a language's grammar alongside an interpreter that uses the representation to interpret sentences in the language. Compilers use this for interpreting expressions or small-scale scripts.
Chain of Responsibility Pattern
The Chain of Responsibility pattern passes a request along a chain of handlers. Upon receiving a request, each handler decides either to process it or to pass it to the next handler in the chain. In compilers, this can be used for error handling or event processing pipelines.
Adapter Pattern
The Adapter pattern allows objects with incompatible interfaces to collaborate. Compilers might use this pattern to ensure that code written against different versions of an interface or different IRs can still work together.
Proxy Pattern
The Proxy pattern provides a surrogate or placeholder for another object to control access to it. Compilers may use it to defer the cost of initializing a resource-heavy object, such as a symbol table or type information.
Prototype Pattern
The Prototype pattern is used to create duplicate objects while keeping performance in mind. Compilers might use this to copy AST nodes or IR instructions without going through expensive initialization.
Command Pattern
The Command pattern turns a request into a stand-alone object that contains all information about the request. Compilers might use this pattern for implementing undo/redo actions or for structuring transformation passes.
Builder Pattern
The Builder pattern separates the construction of a complex object from its representation, allowing the same construction process to create different representations. Compilers use this for incremental construction of ASTs or IR representations.
Factory Method Pattern
The Factory Method pattern defines an interface for creating objects but lets subclasses change the type of objects that will be created. Compilers use this when different representations of code entities are needed based on the input.
Singleton Pattern
The Singleton pattern ensures that a class has only one instance and provides a global point of access to it. Compilers might use this pattern for components like symbol tables or configuration settings.
State Pattern
The State pattern allows an object to alter its behavior when its internal state changes. In compiler construction, this pattern can be used for parsing state machines or during phase transitions like lexing, parsing, and code generation.
Strategy Pattern
The Strategy pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. Compilers use this pattern to select different optimization or code generation strategies.
Flyweight Pattern
The Flyweight pattern is used to reduce the cost of creating and manipulating a large number of similar objects. In compilers, it's used for sharing nodes, like literals or identifiers, across the AST or IR to save memory.
© Hypatia.Tech. 2024 All rights reserved.