Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
pre-order.h
1#pragma once
2
3#include <stack>
4#include <vector>
5
6namespace Antares::Expressions::Nodes
7{
8// Forward-declaration is enough
9
10class Node;
11
12// PreOrder Iterator for AST
14{
15 std::stack<Node*> nodeStack;
16
17public:
18 // Iterator type aliases
19 using iterator_category = std::forward_iterator_tag;
20 using value_type = Node;
21 using difference_type = std::ptrdiff_t;
22 using pointer = Node*;
23 using reference = Node&;
24
25 // Constructor
26 explicit ASTPreOrderIterator(Node* root = nullptr);
27
28 // Dereference operator
29 reference operator*() const;
30
31 // Pointer access operator
32 pointer operator->() const;
33
34 // Increment operator (pre-order traversal)
35 ASTPreOrderIterator& operator++();
36
37 // Equality comparison
38 bool operator==(const ASTPreOrderIterator& other) const;
39
40 // Inequality comparison
41 bool operator!=(const ASTPreOrderIterator& other) const;
42};
43
44// AST container class to expose begin/end iterators
45class AST
46{
47 Node* root;
48
49public:
50 explicit AST(Node* rootNode);
51
52 // Begin iterator
53 ASTPreOrderIterator begin();
54
55 // End iterator (indicating traversal is complete)
57};
58} // namespace Antares::Expressions::Nodes
Definition pre-order.h:46
Base class for nodes in a syntax tree.
Definition Node.h:30