Skip to content

Instantly share code, notes, and snippets.

@mrcnkoba
Created October 30, 2013 21:47
Show Gist options
  • Save mrcnkoba/7240922 to your computer and use it in GitHub Desktop.
Save mrcnkoba/7240922 to your computer and use it in GitHub Desktop.
using System;
namespace SimplifyVisitor
{
public class ConcreteVisitor : VisitorBase<Node>
{
protected void Visit(ConstantNode node)
{
Console.WriteLine("Visiting constant node");
}
protected void Visit(PlusNode node)
{
Console.WriteLine("Visiting plus node");
}
protected void Visit(MinusNode node)
{
Console.WriteLine("Visiting minus node");
}
protected override void VisitMembers(Node node)
{
this.Visit(node);
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SimplifyVisitor
{
using System.Reflection;
public abstract class VisitorBase<T> where T : Node
{
public void Dispatch(T node)
{
this.VisitMembers(node);
}
protected abstract void VisitMembers(T node);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment