import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayDeque; import java.util.HashMap; import java.util.Map; /** * Arithmetique */ public class Variables { public static void main(String[] args) { ArrayDeque pile = new ArrayDeque<>(); HashMap ids = new HashMap<>(); for (String arg : args) { try { Integer.parseInt(arg); pile.addFirst(new Node(arg)); } catch (NumberFormatException e) { if (Character.isUpperCase(arg.charAt(0))) { pile.addFirst(new Node(arg)); ids.put(arg, 0); } else { if (pile.size() < 2) { System.err.println("Invalid stack size."); return; } Node n2 = pile.pollFirst(); Node n1 = pile.pollFirst(); Node n3 = new Node(arg); n3.addSubNode(n1); n3.addSubNode(n2); pile.addFirst(n3); } } } Node firstNode = pile.pollFirst(); System.out.println(firstNode.showNode()); try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) { for (Map.Entry entry : ids.entrySet()) { System.out.print(entry.getKey() + " ? "); ids.put(entry.getKey(), Integer.parseInt(br.readLine())); } } catch (Exception e) { System.out.println(e); } System.out.println("= " + firstNode.getResult(ids)); } }