-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathASTBaseVisitor.cs
31 lines (27 loc) · 950 Bytes
/
ASTBaseVisitor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
namespace MiniC {
public abstract class ASTBaseVisitor<T> {
public virtual T Visit(ASTVisitableElement node) {
return node.Accept(this);
}
public virtual T VisitChildren(ASTVisitableElement node) {
T netResult = default;
foreach (ASTVisitableElement child in node.GetChildren()) {
netResult = AggregateResult(netResult, child.Accept(this));
}
return netResult;
}
public virtual T VisitContext(ASTVisitableElement node, int context) {
foreach (ASTVisitableElement child in node.GetChildren(context)) {
child.Accept(this);
}
return default;
}
public virtual T AggregateResult(T oldResult, T value) {
return value;
}
}
public abstract class ASTVisitableElement : ASTElement {
protected ASTVisitableElement(int context) : base(context) { }
public abstract T Accept<T>(ASTBaseVisitor<T> visitor);
}
}