Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tester.Tester;
- // Represents an arithmetic sequence
- interface IArith {
- <R> R accept(IArithVisitor<R> visitor);
- }
- // Represents a function
- interface IFunc2<A, B, R> {
- }
- // represents a constant
- class Const implements IArith {
- double num;
- Const(double num) {
- this.num = num;
- }
- public <R> R accept(IArithVisitor<R> visitor) {
- return visitor.visitIArithConst(this);
- }
- }
- // represents a arithmetic formula
- class formula implements IArith {
- IFunc2<Double, Double, Double> fun;
- String name;
- IArith left;
- IArith right;
- formula(IFunc2 fun, String name, IArith left, IArith right) {
- this.fun = fun;
- this.name = name;
- this.left = left;
- this.right = right;
- }
- // Accepts an apply the visitor to the formula
- public <R> R accept(IArithVisitor<R> visitor) {
- return visitor.visitIArithFormula(this);
- }
- }
- // Represents an arithmetic visitor for a formula or constant.
- interface IArithVisitor<R> extends IFunc2<Const, Const, R> {
- R visitIArith(IArith a);
- R visitIArithConst(IArith a);
- R visitIArithFormula(IArith a);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement