Skip to content

Commit

Permalink
design document
Browse files Browse the repository at this point in the history
  • Loading branch information
michael.burzan committed Jan 2, 2025
1 parent 55debc3 commit 52e4d2f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/visitor-design.md
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.

0 comments on commit 52e4d2f

Please sign in to comment.