import java.util.*; public class ArbreSyntaxiqueSynchronise extends ArbreSyntaxique { private boolean racine = false; public ArbreSyntaxiqueSynchronise(String [] lexemes) throws ErreurSyntaxiqueException { super(lexemes); racine = true; } public synchronized int valeur() { return super.valeur(); } public synchronized void miseAJour() { super.miseAJour(); if (racine) { System.out.println("resultat = " + valeur()); } } public static void main(String[] args) { try { new Operateur("+", 2) { public int evaluer(int [] operandes) { return operandes[0] + operandes[1]; } }; new Operateur("-", 2) { public int evaluer(int [] operandes) { return operandes[0] - operandes[1]; } }; VariableThread a = new VariableThread("a", 0, 1); VariableThread b = new VariableThread("b", 2, 2); VariableThread c = new VariableThread("c", 4, 3); ArbreSyntaxique arbre = new ArbreSyntaxiqueSynchronise(args); System.out.println("pour " + a + ", " + b + ", " + c + " resultat = " + arbre.valeur()); new Thread(a).start(); new Thread(b).start(); new Thread(c).start(); } catch (ErreurSyntaxiqueException e) { throw new Error(e.getMessage()); } catch (OperateurExistantException e) { throw new Error(e.getMessage()); } } }