@@ -0,0 +1,2410 @@
+package rapanui.dsl;%0A%0Aimport java.util.Map;%0A%0Aimport rapanui.dsl.moai.*;%0A%0Apublic class Translator %7B%0A%09private final Map%3CString, Term%3E dictionary;%0A%0A%09public Translator(Map%3CString, Term%3E dictionary) %7B%0A%09%09this.dictionary = dictionary;%0A%09%7D%0A%0A%09public Term translate(Term input) %7B%0A%09%09if (input instanceof BinaryOperation)%0A%09%09%09return translate((BinaryOperation)input);%0A%09%09else if (input instanceof UnaryOperation)%0A%09%09%09return translate((UnaryOperation)input);%0A%09%09else if (input instanceof VariableReference)%0A%09%09%09return translate((VariableReference)input);%0A%09%09else if (input instanceof ConstantReference)%0A%09%09%09return input;%0A%09%09throw new IllegalStateException(%22Unknown term type: %22 + input.getClass());%0A%09%7D%0A%0A%09public BinaryOperation translate(BinaryOperation input) %7B%0A%09%09BinaryOperation output = MoaiFactory.eINSTANCE.createBinaryOperation();%0A%09%09output.setLeft(translate(input.getLeft()));%0A%09%09output.setOperator(input.getOperator());%0A%09%09output.setRight(translate(input.getRight()));%0A%09%09return output;%0A%09%7D%0A%0A%09public UnaryOperation translate(UnaryOperation input) %7B%0A%09%09UnaryOperation output = MoaiFactory.eINSTANCE.createUnaryOperation();%0A%09%09output.setOperand(translate(input.getOperand()));%0A%09%09output.setOperator(input.getOperator());%0A%09%09return output;%0A%09%7D%0A%0A%09public Term translate(VariableReference input) %7B%0A%09%09return dictionary.get(input.getVariable());%0A%09%7D%0A%0A%09public Formula translate(Formula input) %7B%0A%09%09if (input instanceof Equation)%0A%09%09%09return translate((Equation)input);%0A%09%09else if (input instanceof Inclusion)%0A%09%09%09return translate((Inclusion)input);%0A%09%09else if (input instanceof DefinitionReference)%0A%09%09%09return translate((DefinitionReference)input);%0A%09%09throw new IllegalStateException(%22Unknown formula type: %22 + input.getClass());%0A%09%7D%0A%0A%09public Equation translate(Equation input)%7B%0A%09%09Equation output = MoaiFactory.eINSTANCE.createEquation();%0A%09%09output.setLeft(translate(input.getLeft()));%0A%09%09output.setRight(translate(input.getRight()));%0A%09%09return output;%0A%09%7D%0A%0A%09public Inclusion translate(Inclusion input) %7B%0A%09%09Inclusion output = MoaiFactory.eINSTANCE.createInclusion();%0A%09%09output.setLeft(translate(input.getLeft()));%0A%09%09output.setRight(translate(input.getRight()));%0A%09%09return output;%0A%09%7D%0A%0A%09public DefinitionReference translate(DefinitionReference input) %7B%0A%09%09DefinitionReference output = MoaiFactory.eINSTANCE.createDefinitionReference();%0A%09%09output.setTarget(translate(input.getTarget()));%0A%09%09output.setDefinitionName(input.getDefinitionName());%0A%09%09return output;%0A%09%7D%0A%7D%0A

implement Translator class for replacing variables with arbitrary terms