-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
michael.burzan
committed
Jan 2, 2025
1 parent
55debc3
commit 52e4d2f
Showing
1 changed file
with
15 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
# Visitor Design Pattern for Syntax Tree Traversal | ||
|
||
The **Visitor Design Pattern** is employed for traversing the syntax tree. It serves the purpose of encapsulating an operation to be performed on the elements of an object structure as an object. The Visitor Pattern allows defining new operations without changing the classes of the elements it operates on, as described in *Design Patterns*. | ||
|
||
In the context of syntax trees, operations such as **information gathering**, **semantic checking**, and **code generation** are typical. However, the standard implementation of the Visitor Pattern, as described in *Design Patterns*, is not flexible enough for the object structure generated by the parser. The custom-designed pattern addresses the following requirements: | ||
|
||
## Requirements Implemented by the Custom Visitor Pattern | ||
|
||
- **Pre- and Post-Operations:** It must be possible to perform operations both before and after visiting a node. | ||
- **Selective Node Visiting:** Only one specific type of node in the tree should be visited. | ||
- **Incremental Implementation:** Visiting a specific node type should not require re-implementing the entire visitor. | ||
- **Defined Method Overrides:** The design specifies which methods must be overridden to visit exactly one type of node in the tree. | ||
|
||
This approach ensures the Visitor Pattern is adapted to handle the complexities and flexibility required by the syntax tree generated by the parser. |