Interpreter.xtend 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*******************************************************************************
  2. * Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/epl-v10.html
  7. *******************************************************************************/
  8. package be.uantwerpen.ansymo.semanticadaptation.interpreter
  9. //import com.google.common.collect.ImmutableMap
  10. //import com.google.common.collect.Maps
  11. //import java.math.BigDecimal
  12. //import java.math.RoundingMode
  13. /**
  14. * an interpreter for instances of EClasses of the {@link ArithmeticsPackage}.
  15. * It internally uses a polymorphic dispatcher to dispatch between the implementations for the different EClasses.
  16. */
  17. class Interpreter {
  18. // def BigDecimal evaluate(Expression obj) {
  19. // return evaluate(obj, ImmutableMap.<String, BigDecimal>of())
  20. // }
  21. //
  22. // def BigDecimal evaluate(Expression obj, ImmutableMap<String, BigDecimal> values) {
  23. // return internalEvaluate(obj, values)
  24. // }
  25. //
  26. // def dispatch protected internalEvaluate(NumberLiteral e, ImmutableMap<String, BigDecimal> values) {
  27. // e.value
  28. // }
  29. //
  30. // /**
  31. // * @param values the currently known values by name
  32. // */
  33. // def dispatch protected BigDecimal internalEvaluate(FunctionCall e, ImmutableMap<String, BigDecimal> values) {
  34. // if (e.func instanceof DeclaredParameter) {
  35. // return values.get(e.func.name)
  36. // }
  37. // switch d : e.func {
  38. // Definition: {
  39. // var params = Maps.newHashMap
  40. // for (var int i = 0; i < e.args.size; i++) {
  41. // var declaredParameter = d.args.get(i)
  42. // var evaluate = evaluate(e.args.get(i), values)
  43. // params.put(declaredParameter.getName(), evaluate)
  44. // }
  45. // return evaluate(d.expr, ImmutableMap.copyOf(params))
  46. // }
  47. // }
  48. // }
  49. //
  50. // def dispatch protected BigDecimal internalEvaluate(Plus plus, ImmutableMap<String, BigDecimal> values) {
  51. // evaluate(plus.left, values) + evaluate(plus.right, values)
  52. // }
  53. //
  54. // def dispatch protected BigDecimal internalEvaluate(Minus minus, ImmutableMap<String, BigDecimal> values) {
  55. // evaluate(minus.left, values) - evaluate(minus.right, values)
  56. // }
  57. //
  58. // def dispatch protected BigDecimal internalEvaluate(Div div, ImmutableMap<String, BigDecimal> values) {
  59. // evaluate(div.left, values).divide(evaluate(div.right, values), 20, RoundingMode.HALF_UP)
  60. // }
  61. //
  62. // def dispatch protected BigDecimal internalEvaluate(Multi multi, ImmutableMap<String, BigDecimal> values) {
  63. // evaluate(multi.left, values) * evaluate(multi.right, values)
  64. // }
  65. }