Solution to expression problem in Dart and Java