author | Jaroslav Tulach <jtulach@netbeans.org> |
Sat, 14 Jun 2008 09:58:52 +0200 | |
changeset 169 | 3be14291c9f8 |
child 170 | 206cdfeefeec |
permissions | -rw-r--r-- |
jtulach@169 | 1 |
package org.apidesign.visitor; |
jtulach@169 | 2 |
|
jtulach@169 | 3 |
public final class Language { |
jtulach@169 | 4 |
private Language() { } |
jtulach@169 | 5 |
|
jtulach@169 | 6 |
public static abstract class Expression { |
jtulach@169 | 7 |
Expression() {} |
jtulach@169 | 8 |
public abstract void visit(Visitor v); |
jtulach@169 | 9 |
} |
jtulach@169 | 10 |
public static final class Plus extends Expression { |
jtulach@169 | 11 |
private final Expression first; |
jtulach@169 | 12 |
private final Expression second; |
jtulach@169 | 13 |
|
jtulach@169 | 14 |
public Plus(Expression first, Expression second) { |
jtulach@169 | 15 |
this.first = first; |
jtulach@169 | 16 |
this.second = second; |
jtulach@169 | 17 |
} |
jtulach@169 | 18 |
public Expression getFirst() { return first; } |
jtulach@169 | 19 |
public Expression getSecond() { return second; } |
jtulach@169 | 20 |
@Override |
jtulach@169 | 21 |
public void visit(Visitor v) { v.visitPlus(this); } |
jtulach@169 | 22 |
} |
jtulach@169 | 23 |
public static final class Number extends Expression { |
jtulach@169 | 24 |
private final int value; |
jtulach@169 | 25 |
public Number(int value) { this.value = value; } |
jtulach@169 | 26 |
public int getValue() { return value; } |
jtulach@169 | 27 |
@Override |
jtulach@169 | 28 |
public void visit(Visitor v) { v.visitNumber(this); } |
jtulach@169 | 29 |
} |
jtulach@169 | 30 |
|
jtulach@169 | 31 |
public interface Visitor { |
jtulach@169 | 32 |
public void visitUnknown(Expression e); |
jtulach@169 | 33 |
public void visitPlus(Plus s); |
jtulach@169 | 34 |
public void visitNumber(Number n); |
jtulach@169 | 35 |
} |
jtulach@169 | 36 |
} |