View Javadoc

1   package fr.ove.openmath.jome.ctrl.amto;
2   
3   import fr.ove.openmath.jome.ctrl.linear.events.LinearParserEvent;
4   import fr.ove.openmath.jome.ctrl.amto.MapsToNAry;
5   
6   /***
7   * The abstract math tree object of the power.
8   *
9   * @author © 1999 DIRAT Laurent
10  * @version 1.0  18/11/1999
11  */
12  public class Power extends MapsToNAry {
13      /***
14      * The Constructor.
15      */
16      public Power() {
17          super("power", LinearParserEvent.POWER);
18      }
19  
20      /***
21      * "Flushes" the specified child.<BR>
22      * According to their father, some children need to be between parenthesis to respect correctness of the
23      * expression. So, when needed, the specified child is "flushed" as if it was between parenthesis.
24      * @param child the child to "flush"
25      * @param index the child index in the list of children of the instance.
26      */
27      protected void flushChild(AbstractMathTreeObject child, int index){
28          // (^ a (^ b c)) ==> a^(b^c) alors que (^ (^ a b) c) ==> (a^b)^c=a^b^c
29          if ((child.identifier.equals("power") && (index == 1)) ||
30              child.identifier.equals("minus") || child.identifier.equals("plus") || child.identifier.equals("unaryMinus") || 
31              child.identifier.equals("divide") || child.identifier.equals("arithTimes")) {
32              LinearParserEvent linearParserEvent = new LinearParserEvent(getEventSource());
33              linearParserEvent.setToken(LinearParserEvent.OPEN_PAREN, "(");
34              fireLinearParserEvent(linearParserEvent);
35              child.flush();
36              linearParserEvent.setToken(LinearParserEvent.CLOSE_PAREN, ")");
37              fireLinearParserEvent(linearParserEvent);
38          }
39          else
40              child.flush();
41      }
42  }