From 52e4d2f42c027531cbdf5b22aeeceb873521c8ee Mon Sep 17 00:00:00 2001 From: "michael.burzan" Date: Thu, 2 Jan 2025 16:13:19 +0100 Subject: [PATCH] design document --- docs/visitor-design.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/visitor-design.md b/docs/visitor-design.md index e69de29..b762c42 100644 --- a/docs/visitor-design.md +++ b/docs/visitor-design.md @@ -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.