View Javadoc

1   package fr.ove.openmath.compounder;
2   
3   import java.io.*;
4   import java.util.*;
5   import fr.inria.openmath.omapi.*;
6   import fr.ove.openmath.OpenMathizable;
7   import fr.ove.openmath.jome.ctrl.linear.events.*;
8   import fr.ove.openmath.jome.ctrl.om.*;
9   import fr.ove.openmath.jome.ctrl.amto.*;
10  import fr.ove.openmath.jome.Jome;
11  
12  
13  /***
14  * The handler for the OpenMath parser of the OpenMath compounder
15  *
16  * @author © 2000 DIRAT Laurent
17  * @version 1.0 11/11/2000
18  */
19  public class OMCompounderParserHandler extends ParserAdapter implements java.io.Serializable {
20      /***
21      * A stack for context management.
22      */
23      private Stack stackContext = new Stack();
24  
25      /***
26      * A stack for symbol management.
27      */
28      private Stack stackSymbol = new Stack(); // Le sommet de cette pile reprÈsente le symbol
29      // qui n'est pas une feuille dans l'arbre (donc en fait un opÈrateur, une fonction).
30      // Ceci est utile lors de la construction pour dÈterminer si le pointeur courant d'insertion
31      // doit Ítre remontÈ lorsque l'on rencontre un tag </OMA> (il va de soit que le symbole courant
32      // est empilÈ lorsqu'un tag <OMA> a ÈtÈ rencontrÈ.
33      // Ex: + est n-aire dans la formula, donc a la forme (+ a b c). Pourtant a+b+c peut Ítre Ècrit en OM
34      // de plusieurs faÁon, et surtout de faÁon diffÈrente ? la forme de la formula. Par exemple:
35      // OMA + a OMA + b c /OMA /OMA. Il ne faut pas que le ptr courant remonte d'un cran lors de la
36      // rencontre du premier /OMA
37  
38      /***
39      * A stack for counting the number of operands of the current symbol
40      */
41      private Stack stackSymbolOperands = new Stack(); // Le sommet de cette pile reprÈsente le nombre d'opÈrande
42      // du symbol courant, i.e. celui au sommet de la pile stackSymbol.
43  
44      /***
45      * The list of the elements to compose
46      */
47      private Hashtable elements;
48  
49      /***
50      * The compounded OpenMath Object
51      */
52      private StringBuffer compounded = new StringBuffer();
53  
54      /***
55      * The different contexts all along the parsing.
56      */
57      private static final byte CREATE_OBJECT             = 0;
58      private static final byte WAIT_FOR_OBJECT           = 1;
59      private static final byte WAIT_FOR_END_OBJECT       = 2;
60  
61      private static final byte CREATE_APPLICATION        = 3;
62  
63      private static final byte CREATE_ATTRIBUTION        = 4;
64      private static final byte CREATE_ATTRIBUT_PAIRS     = 5;
65      private static final byte END_ATTRIBUT_PAIRS        = 6;
66      private static final byte END_ATTRIBUTION           = 7;
67  
68      private static final byte CREATE_ERROR              = 8;
69  
70      private static final byte CREATE_BIDING             = 9;
71      private static final byte CREATE_BIDING_VARIABLES   = 10;
72      private static final byte WAIT_FOR_VARIABLES        = 11;
73      private static final byte CREATE_BIDING_OBJECT      = 12;
74      private static final byte END_BIDING                = 13;
75  
76      private Locator locator;
77  
78      // nÈcessaire pour l'insertion d'un symbol "fictif" dans la pile pour les fonctions.
79      // Au moins pour le moment.
80      // si on a f(x) (donc <OMA><OMV name="f"/><OMV name="x"/></OMA>), quand on va tomber sur le
81      // </OMA>, il n'y aura pas de symbole dans la pile, et donc on remontera plus que... la raison le permet.
82      private boolean isApply = false;
83  
84      /***
85      * The constructor.<BR>
86      * formula must be the root of an empty one.
87      */
88      public OMCompounderParserHandler(Hashtable elements) {
89          this.elements = elements;
90      }
91  
92  
93      /***
94      * Return the compounded OpenMath Object.
95      */
96      public String getCompounded() {
97          return compounded.toString();
98      }
99  
100     /***
101     * Pushes the context in the stack.
102     * @param context the context to push.
103     */
104     private void pushContext(byte context) {
105         stackContext.push(new Byte(context));
106     }
107 
108     /***
109     * Pops the context which is on the top of the stack.
110     */
111     private byte popContext() {
112         return ((Byte) stackContext.pop()).byteValue();
113     }
114 
115     /***
116     * Returns the context which is on the top of the stack.<BR>
117     * The returned context still remains into the stack.
118     */
119     private byte getContext() {
120         return ((Byte) stackContext.peek()).byteValue();
121     }
122 
123 
124     /***
125     * Throws an OpenMath exception.
126     * @param message the message to display.
127     * @param e a specific exception to throw.
128     * @see fr.inria.openmath.omapi.OMException
129     */
130     private void throwOME(String message, Exception e) throws OMException {
131         if (locator != null) {
132             throw new OMException(
133                     message + " (at line:" + locator.getLineNumber() + " col:"
134                     + locator.getColumnNumber() + ")", e);
135         } else {
136             throw new OMException(message, e);
137         }
138     }
139 
140     /***
141     * Throws an OpenMath exception.
142     * @param message the message to display.
143     * @param code the code of the excpetion thrown.
144     * @see fr.inria.openmath.omapi.OMException
145     */
146     private void throwOME(String message, short code) throws OMException {
147         if (locator != null) {
148             throw new OMException(
149                     message + " (at line:" + locator.getLineNumber() + " col:"
150                     + locator.getColumnNumber() + ")", code);
151         } else {
152             throw new OMException(message, code);
153         }
154 
155     }
156 
157     /***
158     * Throws an OpenMath exception.
159     * @param message the message to display.
160     * @see fr.inria.openmath.omapi.OMException
161     */
162     private void throwOME(String message) throws OMException {
163         throwOME(message, OMException.OME_GENERIC);
164     }
165 
166 
167     /********************************************/
168     /*                                         */
169     /* Les mÈthodes de la classe ParserAdapter */
170     /*                                         */
171     /********************************************/
172 
173 
174 
175 
176     /***
177      * Receives a Locator for parse events.
178      *
179      * <p>By default, do nothing. Application writers may override this
180      * method in a subclass if they wish to store the locator for use
181      * with other  events.</p>
182      *
183      * @param locator A locator for all OpenMath parse events.
184      * @see fr.inria.openmath.omapi.ParserHandler#setLocator
185      * @see fr.inria.openmath.omapi.Locator
186      */
187     public void setLocator(Locator locator) {
188     }
189 
190     /***
191      * Receives notification of the beginning of parse (of a set of OpenMath-objects).
192      *
193      * <p>By default, do nothing. Application writers may override this
194      * method in a subclass.</p>
195      *
196      * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
197      */
198     public void startParse() throws OMException {
199     }
200 
201     /***
202      * Receives notification of the end of parse.
203      *
204      * <p>By default, do nothing. Application writers may override this
205      * method in a subclass.</p>
206      *
207      * <p>The OpenMath parser will invoke this method only once, and it will
208      * be the last method invoked during the parse.  The parser shall
209      * not invoke this method until it has either abandoned parsing
210      * (because of an unrecoverable error) or reached the end of
211      * the input (no more OpenMath objects).</p>
212      *
213      * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
214      */
215     public void endParse() throws OMException {
216     }
217 
218     /***
219      * Receives notification of the beginning of a object element.
220      *
221      * <p>By default, do nothing.  Application writers may override this
222      * method in a subclass.</p>
223      *
224      * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
225      * @see #endObject
226      */
227     public void startObject() throws OMException {
228         //TraceContext("startObject");
229         stackContext.removeAllElements();
230         stackSymbol.removeAllElements();
231         stackSymbolOperands.removeAllElements();
232 
233         if (!stackContext.empty())
234             throwOME("Malformed object. Unexpected start of object found", OMException.OME_SYNTAX);
235 
236         pushContext(CREATE_OBJECT);
237 
238         compounded.setLength(0); // initialisation du buffer
239         compounded.append("<OMOBJ>");
240     }
241 
242     /***
243      * Receives notification of the end of an object element.
244      *
245      * <p>By default, do nothing.  Application writers may override this
246      * method in a subclass.</p>
247      *
248      * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
249      * @see #startObject
250      */
251     public void endObject() throws OMException {
252         if (!stackContext.empty()) {
253             popContext();
254 
255             if (!stackContext.empty())
256                     throwOME("Malformed object. Something wrong occured");
257         }
258         else
259             throwOME("Malformed object. Something wrong occured");
260 
261         compounded.append("</OMOBJ>");
262     }
263 
264     /***
265      * Receives notification of the beginning of a application element.
266      *
267      * <p>By default, do nothing.  Application writers may override this
268      * method in a subclass.</p>
269      *
270      * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
271      * @see #endApplication
272      */
273     public void startApplication() throws OMException {
274         if (!stackSymbol.empty()) {
275             Symbol currentSymbol = (Symbol) stackSymbol.peek();
276 
277             // d'abord on regarde si c'est un "vrai" symbol.
278             if (!currentSymbol.equals("", "")) {
279                 // C'est un vrai symbol, on teste maintenant si l'aritÈ est respectÈe
280                 byte numOperands = ((Byte) stackSymbolOperands.pop()).byteValue();
281                 // On augmente le nombre d'opÈrandes
282                 numOperands++;
283                 stackSymbolOperands.push(new Byte(numOperands));
284             }
285         }
286 
287         if (!stackContext.empty()) {
288 
289             compounded.append("<OMA>");
290 
291             byte context = popContext();
292             switch (context) {
293                 case CREATE_APPLICATION:
294                 case CREATE_BIDING_OBJECT:
295                     pushContext(context);
296                 case CREATE_OBJECT:
297                 case WAIT_FOR_OBJECT:
298                 case CREATE_BIDING:
299                     pushContext(CREATE_APPLICATION);
300                     break;
301                 case WAIT_FOR_END_OBJECT:
302                     throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
303                 case CREATE_ATTRIBUTION:
304                     throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
305                 case CREATE_ATTRIBUT_PAIRS:
306                     throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
307                 case END_ATTRIBUT_PAIRS:
308                     throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
309                 case END_ATTRIBUTION:
310                     throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
311                 case CREATE_ERROR:
312                     throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
313                 case CREATE_BIDING_VARIABLES:
314                     throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
315                 case WAIT_FOR_VARIABLES:
316                     throwOME("Malformed object. Variables expected", OMException.OME_SYNTAX);
317                 case END_BIDING:
318                     throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
319             }
320         }
321         else
322             throwOME("Malformed object. Something wrong occured");
323     }
324 
325     /***
326      * Receives notification of the end of an application element.
327      *
328      * <p>By default, do nothing. Application writers may override this
329      * method in a subclass.</p>
330      *
331      * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
332      * @see #startApplication
333      */
334     public void endApplication() throws OMException {
335         Symbol symbol;  // Le symbol courant quand on entre dans cette mÈthode.
336         Symbol topSymbol;  // Le symbol en sommet de pile quand on a enlevÈ le symbol courant.
337                            // c'est le futur symbole courant.
338 
339         //TraceContext("endApplication");
340 
341         if (!stackContext.empty()) {
342 
343             compounded.append("</OMA>");
344 
345             byte context = popContext();
346             switch (context) {
347                 case WAIT_FOR_OBJECT:
348                     popContext(); // On enlËve le contexte d'application
349                     // On rÈcupËre le symbole courant et on l'enlËve de la pile
350                     symbol = (Symbol) stackSymbol.pop();
351                     // On enlËve le nombre d'opÈrandes correspondant
352                     stackSymbolOperands.pop();
353 
354                     if (!stackContext.empty()) {
355                         switch (getContext()) {
356                             case CREATE_OBJECT: // a priori on n'aura jamais Áa !!!!!
357                                 pushContext(WAIT_FOR_END_OBJECT);
358                             case CREATE_APPLICATION:
359                             case CREATE_ERROR:
360                                 pushContext(WAIT_FOR_OBJECT);
361                                 break;
362                             case CREATE_BIDING:
363                                 pushContext(CREATE_BIDING_VARIABLES);
364                                 break;
365                             case CREATE_BIDING_OBJECT:
366                                 popContext();  // on enlËve le contexte CREATE_BIDING_OBJECT
367                                 popContext();  // on enlËve le contexte CREATE_BIDING
368                                 pushContext(END_BIDING);
369                                 break;
370                             case CREATE_ATTRIBUT_PAIRS:
371                                 pushContext(END_ATTRIBUT_PAIRS);
372                                 break;
373                             case CREATE_ATTRIBUTION:
374                                 pushContext(END_ATTRIBUTION);
375                                 break;
376                         }
377                     }
378                     else
379                         pushContext(WAIT_FOR_END_OBJECT);
380 
381                     break;
382 
383                 case CREATE_OBJECT:
384                 case CREATE_APPLICATION:
385                 case CREATE_BIDING:
386                 case CREATE_BIDING_OBJECT:
387                     throwOME("Malformed object. An object was expected", OMException.OME_NODE_NOT_FOUND);
388                 case WAIT_FOR_END_OBJECT:
389                     throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
390                 case CREATE_ATTRIBUTION:
391                     throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
392                 case CREATE_ATTRIBUT_PAIRS:
393                     throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
394                 case END_ATTRIBUT_PAIRS:
395                     throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
396                 case END_ATTRIBUTION:
397                     throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
398                 case CREATE_ERROR:
399                     throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
400                 case CREATE_BIDING_VARIABLES:
401                     throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
402                 case WAIT_FOR_VARIABLES:
403                     throwOME("Malformed object. Variables expected", OMException.OME_SYNTAX);
404                 case END_BIDING:
405                     throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
406             }
407         }
408         else
409             throwOME("Malformed object. Something wrong occured");
410 
411     }
412 
413 
414     /***
415      * Receives notification of the beginning of a attribution element.
416      *
417      * <p>By default, do nothing.  Application writers may override this
418      * method in a subclass.</p>
419      *
420      * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
421      * @see #endAttribution
422      */
423     public void startAttribution() throws OMException {
424 
425         //TraceContext("startAttribution");
426 
427         if (!stackContext.empty()) {
428             compounded.append("<OMATP>");
429 
430             byte context = popContext();
431             switch (context) {
432                 case CREATE_APPLICATION:
433                     // On rajoute un symbole foireux parce qu'on n'a pas crÈÈ une application ? partir d'un symbol
434                     // d'un CD. On n'a donc pas ? tester a priori le nombre d'opÈrandes.
435                     stackSymbol.push(new Symbol("", ""));
436                     stackSymbolOperands.push(new Byte(Byte.MAX_VALUE));
437 
438                 case CREATE_BIDING:
439                 case WAIT_FOR_VARIABLES:
440                 case CREATE_BIDING_OBJECT:
441                     pushContext(context);
442                 case CREATE_OBJECT:
443                 case WAIT_FOR_OBJECT:
444                     pushContext(CREATE_ATTRIBUTION);
445 
446                     /*
447                     Ce qu'il faut pour l'attribution
448                     */
449 
450                     break;
451 
452                 case WAIT_FOR_END_OBJECT:
453                     throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
454                 case CREATE_ATTRIBUTION:
455                     throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
456                 case CREATE_ATTRIBUT_PAIRS:
457                     throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
458                 case END_ATTRIBUT_PAIRS:
459                     throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
460                 case END_ATTRIBUTION:
461                     throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
462                 case CREATE_ERROR:
463                     throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
464                 case CREATE_BIDING_VARIABLES:
465                     throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
466                 case END_BIDING:
467                     throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
468             }
469         }
470         else
471             throwOME("Malformed object. Something wrong occured");
472     }
473 
474     /***
475      * Receives notification of the end of an attribution element.
476      *
477      * <p>By default, do nothing.  Application writers may override this
478      * method in a subclass.</p>
479      *
480      * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
481      * @see #startAttribution
482      */
483     public void endAttribution() throws OMException {
484 
485         //TraceContext("endAttribution");
486 
487         if (!stackContext.empty()) {
488 
489             compounded.append("</OMATP>");
490 
491             byte context = popContext();
492             switch (context) {
493                 case END_ATTRIBUTION:
494                     //System.out.println("On termine l'attribution");
495 
496                     /*
497                     Ce qu'il faut pour terminer l'attribution
498                     */
499 
500                     // Ca fait que l'on vient de lire un object.
501                     // I lfaut regarder le contexte maintenant pour savoir dans quel Ètat on passe.
502                     if (!stackContext.empty()) {
503                         switch (getContext()) {
504                             case CREATE_OBJECT:
505                                 pushContext(WAIT_FOR_END_OBJECT);
506                             case CREATE_ERROR:
507                                 pushContext(WAIT_FOR_OBJECT);
508                                 break;
509                             case CREATE_BIDING:
510                                 pushContext(CREATE_BIDING_VARIABLES);
511                                 break;
512                             case WAIT_FOR_VARIABLES:
513                                 popContext();  // on enlËve le contexte WAIT_FOR_VARIABLES
514                                 pushContext(CREATE_BIDING_OBJECT);
515                                 break;
516                             case CREATE_BIDING_OBJECT:
517                                 popContext();  // on enlËve le contexte CREATE_BIDING_OBJECT
518                                 popContext();  // on enlËve le contexte CREATE_BIDING
519                                 pushContext(END_BIDING);
520                                 break;
521                             case CREATE_ATTRIBUT_PAIRS:
522                                 pushContext(END_ATTRIBUT_PAIRS);
523                                 break;
524                             case CREATE_ATTRIBUTION:
525                                 pushContext(END_ATTRIBUTION);
526                                 break;
527                         }
528                     }
529                     else
530                         pushContext(WAIT_FOR_END_OBJECT);
531 
532                     break;
533 
534                 case CREATE_OBJECT:
535                 case WAIT_FOR_OBJECT:
536                 case CREATE_APPLICATION:
537                 case CREATE_BIDING:
538                 case CREATE_BIDING_OBJECT:
539                     throwOME("Malformed object. An object was expected", OMException.OME_NODE_NOT_FOUND);
540                 case WAIT_FOR_END_OBJECT:
541                     throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
542                 case CREATE_ATTRIBUTION:
543                     throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
544                 case CREATE_ATTRIBUT_PAIRS:
545                     throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
546                 case END_ATTRIBUT_PAIRS:
547                     throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
548                 case CREATE_ERROR:
549                     throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
550                 case CREATE_BIDING_VARIABLES:
551                     throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
552                 case WAIT_FOR_VARIABLES:
553                     throwOME("Malformed object. Variables expected", OMException.OME_SYNTAX);
554                 case END_BIDING:
555                     throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
556             }
557         }
558         else
559             throwOME("Malformed object. Something wrong occured");
560 
561     }
562 
563     /***
564      * Receives notification of the beginning of an attribute-pairs element.
565      *
566      * <p>By default, do nothing.  Application writers may override this
567      * method in a subclass.</p>
568      *
569      * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
570      *
571      * @see #endAttributePairs
572      */
573     public void startAttributePairs() throws OMException {
574         //TraceContext("startAttributePairs");
575 
576         if (!stackContext.empty()) {
577 
578             compounded.append("<OMATTR>");
579 
580             byte context = popContext();
581             switch (context) {
582                 case CREATE_ATTRIBUTION:
583                     /*
584                     Ce qu'il faut pour dÈmarrer la paire d'attribut.
585                     */
586 
587                     pushContext(context);
588                     pushContext(CREATE_ATTRIBUT_PAIRS);
589                     break;
590 
591                 case CREATE_OBJECT:
592                 case WAIT_FOR_OBJECT:
593                 case CREATE_APPLICATION:
594                 case CREATE_BIDING:
595                 case CREATE_BIDING_OBJECT:
596                     throwOME("Malformed object. An object was expected", OMException.OME_NODE_NOT_FOUND);
597                 case WAIT_FOR_END_OBJECT:
598                     throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
599                 case CREATE_ATTRIBUT_PAIRS:
600                     throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
601                 case END_ATTRIBUT_PAIRS:
602                     throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
603                 case END_ATTRIBUTION:
604                     throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
605                 case CREATE_ERROR:
606                     throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
607                 case CREATE_BIDING_VARIABLES:
608                     throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
609                 case WAIT_FOR_VARIABLES:
610                     throwOME("Malformed object. Variables expected", OMException.OME_SYNTAX);
611                 case END_BIDING:
612                     throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
613             }
614         }
615         else
616             throwOME("Malformed object. Something wrong occured");
617     }
618 
619     /***
620      * Receives notification of the end of an attribute-pairs element.
621      *
622      * <p>By default, do nothing.  Application writers may override this
623      * method in a subclass.</p>
624      *
625      * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
626      * @see #startAttribution
627      */
628     public void endAttributePairs() throws OMException {
629 
630         //TraceContext("endAttributePairs");
631 
632         if (!stackContext.empty()) {
633 
634             compounded.append("</OMATTR>");
635 
636             byte context = popContext();
637             switch (context) {
638                 case END_ATTRIBUT_PAIRS:
639                     //System.out.println("On termine la paire d'attribut");
640 
641                     /*
642                     Ce qu'il faut pour terminer la paire d'attribut
643                     */
644 
645                     if (!stackContext.empty()) {
646                         popContext();
647                         pushContext(WAIT_FOR_OBJECT);
648                     }
649                     else
650                         throwOME("Malformed object. Something wrong occured");
651 
652                     break;
653 
654                 case CREATE_OBJECT:
655                 case WAIT_FOR_OBJECT:
656                 case CREATE_APPLICATION:
657                 case CREATE_BIDING:
658                 case CREATE_BIDING_OBJECT:
659                     throwOME("Malformed object. An object was expected", OMException.OME_NODE_NOT_FOUND);
660                 case WAIT_FOR_END_OBJECT:
661                     throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
662                 case CREATE_ATTRIBUTION:
663                     throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
664                 case CREATE_ATTRIBUT_PAIRS:
665                     throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
666                 case END_ATTRIBUTION:
667                     throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
668                 case CREATE_ERROR:
669                     throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
670                 case CREATE_BIDING_VARIABLES:
671                     throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
672                 case WAIT_FOR_VARIABLES:
673                     throwOME("Malformed object. Variables expected", OMException.OME_SYNTAX);
674                 case END_BIDING:
675                     throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
676             }
677         }
678         else
679             throwOME("Malformed object. Something wrong occured");
680     }
681 
682     /***
683      * Receives notification of the beginning of a Bind element.
684      *
685      * <p>By default, do nothing.  Application writers may override this
686      * method in a subclass.</p>
687      *
688      * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
689      *
690      * @see #endBind
691      */
692     public void startBind() throws OMException {
693         //TraceContext("startBind");
694 
695 
696         if (!stackContext.empty()) {
697 
698             compounded.append("<OMBIND>");
699 
700             byte context = popContext();
701             switch (context) {
702                 case CREATE_APPLICATION:
703                     // On rajoute un symbole foireux parce qu'on n'a pas crÈÈ une application ? partir d'un symbol
704                     // d'un CD. On n'a donc pas ? tester a priori le nombre d'opÈrandes.
705                     stackSymbol.push(new Symbol("", ""));
706                     stackSymbolOperands.push(new Byte(Byte.MAX_VALUE));
707 
708                 case CREATE_BIDING:
709                 case CREATE_BIDING_OBJECT:
710                     pushContext(context);
711                 case CREATE_OBJECT:
712                 case WAIT_FOR_OBJECT:
713                     pushContext(CREATE_BIDING);
714 
715                     /*
716                     Ce qu'il faut pour crÈer le biding
717                     */
718 
719                     break;
720 
721                 case WAIT_FOR_END_OBJECT:
722                     throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
723                 case CREATE_ATTRIBUTION:
724                     throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
725                 case CREATE_ATTRIBUT_PAIRS:
726                     throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
727                 case END_ATTRIBUT_PAIRS:
728                     throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
729                 case END_ATTRIBUTION:
730                     throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
731                 case CREATE_ERROR:
732                     throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
733                 case CREATE_BIDING_VARIABLES:
734                     throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
735                 case WAIT_FOR_VARIABLES:
736                     throwOME("Malformed object. Variables expected", OMException.OME_SYNTAX);
737                 case END_BIDING:
738                     throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
739             }
740         }
741         else
742             throwOME("Malformed object. Something wrong occured");
743     }
744 
745 
746 
747 
748     /***
749      * Receives notification of the beginning of a BVars element.
750      *
751      * <p>By default, do nothing.  Application writers may override this
752      * method in a subclass.</p>
753      *
754      * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
755      *
756      * @see #endBVars
757      */
758     public void startBVars() throws OMException {
759         //TraceContext("startBVars");
760 
761         if (!stackContext.empty()) {
762 
763             compounded.append("<OMBVAR>");
764 
765             byte context = popContext();
766             switch (context) {
767                 case CREATE_BIDING_VARIABLES:
768                     pushContext(WAIT_FOR_VARIABLES);
769                     break;
770 
771                 case CREATE_OBJECT:
772                 case WAIT_FOR_OBJECT:
773                 case CREATE_BIDING:
774                 case CREATE_BIDING_OBJECT:
775                     throwOME("Malformed object. An object was expected", OMException.OME_NODE_NOT_FOUND);
776                 case CREATE_APPLICATION:
777                     throwOME("Malformed object. Application expected", OMException.OME_NODE_NOT_FOUND);
778                 case WAIT_FOR_VARIABLES:
779                     throwOME("Malformed object. Variables expected", OMException.OME_SYNTAX);
780                 case WAIT_FOR_END_OBJECT:
781                     throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
782                 case CREATE_ATTRIBUTION:
783                     throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
784                 case CREATE_ATTRIBUT_PAIRS:
785                     throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
786                 case END_ATTRIBUT_PAIRS:
787                     throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
788                 case END_ATTRIBUTION:
789                     throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
790                 case CREATE_ERROR:
791                     throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
792                 case END_BIDING:
793                     throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
794             }
795         }
796         else
797             throwOME("Malformed object. Something wrong occured");
798     }
799 
800     /***
801      * Receives notification of the beginning of a BVars element.
802      *
803      * <p>By default, do nothing.  Application writers may override this
804      * method in a subclass.</p>
805      *
806      * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
807      *
808      * @see #startBVars
809      */
810     public void endBVars() throws OMException {
811         //TraceContext("endBVars");
812 
813         if (!stackContext.empty()) {
814 
815             compounded.append("</OMBVAR>");
816 
817             byte context = popContext();
818 
819             switch (context) {
820                 case WAIT_FOR_VARIABLES:
821                     pushContext(CREATE_BIDING_OBJECT);
822                     break;
823 
824                 case CREATE_OBJECT:
825                 case WAIT_FOR_OBJECT:
826                 case CREATE_BIDING:
827                 case CREATE_BIDING_OBJECT:
828                     throwOME("Malformed object. An object was expected", OMException.OME_NODE_NOT_FOUND);
829                 case CREATE_APPLICATION:
830                     throwOME("Malformed object. Application expected", OMException.OME_NODE_NOT_FOUND);
831                 case CREATE_BIDING_VARIABLES:
832                     throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
833                 case WAIT_FOR_END_OBJECT:
834                     throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
835                 case CREATE_ATTRIBUTION:
836                     throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
837                 case CREATE_ATTRIBUT_PAIRS:
838                     throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
839                 case END_ATTRIBUT_PAIRS:
840                     throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
841                 case END_ATTRIBUTION:
842                     throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
843                 case CREATE_ERROR:
844                     throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
845                 case END_BIDING:
846                     throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
847             }
848         }
849         else
850             throwOME("Malformed object. Something wrong occured");
851     }
852 
853 
854     /***
855      * Receives notification of the beginning of a Bind element.
856      *
857      * <p>By default, do nothing.  Application writers may override this
858      * method in a subclass.</p>
859      *
860      * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
861      *
862      * @see #endBind
863      */
864     public void endBind() throws OMException {
865         //TraceContext("endBind");
866 
867         if (!stackContext.empty()) {
868 
869             compounded.append("</OMBIND>");
870 
871             byte context = popContext();
872             switch (context) {
873                 case END_BIDING:
874                     // Ca fait que l'on vient de lire un object.
875                     // Il faut regarder le contexte maintenant pour savoir dans quel Ètat on passe.
876                     if (!stackContext.empty()) {
877                         switch (getContext()) {
878                             case CREATE_OBJECT:
879                                 pushContext(WAIT_FOR_END_OBJECT);
880                                 break;
881                             case CREATE_APPLICATION:
882                             case CREATE_ERROR:
883                                 pushContext(WAIT_FOR_OBJECT);
884                                 break;
885                             case CREATE_BIDING:
886                                 pushContext(CREATE_BIDING_VARIABLES);
887                                 break;
888                             case WAIT_FOR_VARIABLES:
889                                 pushContext(CREATE_BIDING_OBJECT);
890                                 break;
891                             case CREATE_ATTRIBUT_PAIRS:
892                                 pushContext(END_ATTRIBUT_PAIRS);
893                                 break;
894                             case CREATE_ATTRIBUTION:
895                                 pushContext(END_ATTRIBUTION);
896                                 break;
897                         }
898                     }
899                     else
900                         pushContext(WAIT_FOR_END_OBJECT);
901 
902                     break;
903 
904                 case CREATE_OBJECT:
905                 case WAIT_FOR_OBJECT:
906                 case CREATE_APPLICATION:
907                 case CREATE_BIDING:
908                 case CREATE_BIDING_OBJECT:
909                     throwOME("Malformed object. An object was expected", OMException.OME_NODE_NOT_FOUND);
910                 case WAIT_FOR_END_OBJECT:
911                     throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
912                 case CREATE_ATTRIBUTION:
913                     throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
914                 case CREATE_ATTRIBUT_PAIRS:
915                     throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
916                 case END_ATTRIBUT_PAIRS:
917                     throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
918                 case END_ATTRIBUTION:
919                     throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
920                 case CREATE_ERROR:
921                     throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
922                 case CREATE_BIDING_VARIABLES:
923                     throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
924                 case WAIT_FOR_VARIABLES:
925                     throwOME("Malformed object. Variables expected", OMException.OME_SYNTAX);
926             }
927         }
928         else
929             throwOME("Malformed object. Something wrong occured");
930 
931     }
932 
933     /***
934      * Receives notification of the beginning of a error element.
935      *
936      * <p>By default, do nothing.  Application writers may override this
937      * method in a subclass.</p>
938      *
939      * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
940      *
941      * @see #endError
942      */
943     public void startError() throws OMException {
944         //TraceContext("startError");
945 
946         if (!stackContext.empty()) {
947 
948             compounded.append("<OME>");
949 
950             byte context = popContext();
951             switch (context) {
952                 case CREATE_APPLICATION:
953                     // *************************************************************
954                     // Est-ce judicieux d'appliquer une erreur sur qque chose ??????
955                     // *************************************************************
956 
957                     // On rajoute un symbole foireux parce qu'on n'a pas crÈÈ une application ? partir d'un symbol
958                     // d'un CD. On n'a donc pas ? tester a priori le nombre d'opÈrandes.
959                     stackSymbol.push(new Symbol("", ""));
960                     stackSymbolOperands.push(new Byte(Byte.MAX_VALUE));
961 
962                 case CREATE_OBJECT:
963                     pushContext(context);
964                 case WAIT_FOR_OBJECT:
965                 case CREATE_BIDING:
966                 case CREATE_BIDING_OBJECT:
967                     pushContext(CREATE_ERROR);
968 
969                     // Faudra crÈer l'objet adÈquat !!!!
970 
971                     break;
972                 case WAIT_FOR_END_OBJECT:
973                     throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
974                 case CREATE_ATTRIBUTION:
975                     throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
976                 case CREATE_ATTRIBUT_PAIRS:
977                     throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
978                 case END_ATTRIBUT_PAIRS:
979                     throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
980                 case END_ATTRIBUTION:
981                     throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
982                 case CREATE_ERROR:
983                     throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
984                 case CREATE_BIDING_VARIABLES:
985                     throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
986                 case WAIT_FOR_VARIABLES:
987                     throwOME("Malformed object. Variables expected", OMException.OME_SYNTAX);
988                 case END_BIDING:
989                     throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
990             }
991         }
992         else
993             throwOME("Malformed object. Something wrong occured");
994     }
995 
996     /***
997      * Receives notification of the end of an error element.
998      *
999      * <p>By default, do nothing.  Application writers may override this
1000      * method in a subclass.</p>
1001      *
1002      * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
1003      * @see #startError
1004      */
1005     public void endError() throws OMException {
1006         //TraceContext("endError");
1007 
1008         if (!stackContext.empty()) {
1009 
1010             compounded.append("</OME>");
1011 
1012             byte context = popContext();
1013             switch (context) {
1014                 case WAIT_FOR_OBJECT:
1015                     /*
1016                     ce qu'il faut pour terminer l'erreur
1017                     */
1018 
1019                     // Ca fait que l'on vient de lire un object.
1020                     // I lfaut regarder le contexte maintenant pour savoir dans quel Ètat on passe.
1021                     if (!stackContext.empty()) {
1022                         switch (getContext()) {
1023                             case CREATE_OBJECT:
1024                                 pushContext(WAIT_FOR_END_OBJECT);
1025                                 break;
1026                             case CREATE_APPLICATION:
1027                                 pushContext(WAIT_FOR_OBJECT);
1028                                 break;
1029                             case CREATE_ERROR:
1030                                 //pushContext(WAIT_FOR_OBJECT);
1031                                 // plutÙt Áa !!!
1032                                 popContext();
1033                                 popContext();
1034                                 pushContext(WAIT_FOR_END_OBJECT);
1035                                 break;
1036                             case CREATE_BIDING:
1037                                 pushContext(CREATE_BIDING_VARIABLES);
1038                                 break;
1039                             case WAIT_FOR_VARIABLES:
1040                                 pushContext(CREATE_BIDING_OBJECT);
1041                                 break;
1042                             case CREATE_ATTRIBUT_PAIRS:
1043                                 pushContext(END_ATTRIBUT_PAIRS);
1044                                 break;
1045                             case CREATE_ATTRIBUTION:
1046                                 pushContext(END_ATTRIBUTION);
1047                                 break;
1048                         }
1049                     }
1050                     else
1051                         pushContext(WAIT_FOR_END_OBJECT);
1052 
1053                     break;
1054 
1055                 case CREATE_OBJECT:
1056                 case CREATE_APPLICATION:
1057                 case CREATE_BIDING:
1058                 case CREATE_BIDING_OBJECT:
1059                     throwOME("Malformed object. An object was expected", OMException.OME_NODE_NOT_FOUND);
1060                 case WAIT_FOR_END_OBJECT:
1061                     throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
1062                 case CREATE_ATTRIBUTION:
1063                     throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
1064                 case CREATE_ATTRIBUT_PAIRS:
1065                     throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
1066                 case END_ATTRIBUT_PAIRS:
1067                     throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
1068                 case END_ATTRIBUTION:
1069                     throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
1070                 case CREATE_ERROR:
1071                     throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
1072                 case CREATE_BIDING_VARIABLES:
1073                     throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
1074                 case WAIT_FOR_VARIABLES:
1075                     throwOME("Malformed object. Variables expected", OMException.OME_SYNTAX);
1076                 case END_BIDING:
1077                     throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
1078             }
1079         }
1080         else
1081             throwOME("Malformed object. Something wrong occured");
1082 
1083     }
1084 
1085 
1086     /***
1087      * Receives notification of an Integer element.
1088      *
1089      * <p>By default, do nothing. Application writers may override this
1090      * method in a subclass.</p>
1091      *
1092      * @param value the value embeded in this Integer element. This is an infinite precision integer.
1093      * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
1094      * @see fr.inria.openmath.omapi.BigInt
1095      */
1096     public void readInteger(BigInt value) throws OMException {
1097         //TraceContext("readInteger");
1098         Symbol symbol;
1099 
1100         if (!stackContext.empty()) {
1101             byte context = popContext();
1102 
1103             switch (context) {
1104                 case CREATE_OBJECT:
1105                     insertInteger(value);
1106                     pushContext(WAIT_FOR_END_OBJECT);
1107                     break;
1108                 case WAIT_FOR_OBJECT:
1109                     // Dans ce cas l?, on peut venir de plusieurs Ètats, notamment celui d'une application
1110                     // d'un symbole sur des opÈrandes. Il faut que l'on teste alors si l'aritÈ dudit symbole
1111                     // est respectÈe ou pas. Pour les cas o? une application n'est pas faite ? partir d'un
1112                     // symbole, dans la pile des symboles, on AURA MIS UN SYMBOLE FOIREUX (new Symbol("", ""))
1113                     // POUR POUVOIR FAIRE LA DISTINCTION.
1114                     // Dans le cas contraire, on insËre le symbole sans se poser de questions.
1115 
1116 
1117                     // Ca fait que l'on vient de lire un object.
1118                     // Il faut regarder le contexte maintenant pour savoir dans quel Ètat on passe.
1119                     if (!stackContext.empty()) {
1120 
1121                         byte superContext = getContext();
1122                         if (superContext == CREATE_APPLICATION) {
1123                             Symbol currentSymbol = (Symbol) stackSymbol.peek();
1124 
1125                             // d'abord on regarde si c'est un "vrai" symbol.
1126                             if (!currentSymbol.equals("", "")) {
1127                                 // C'est un vrai symbol, on teste maintenant si l'aritÈ est respectÈe
1128                                 byte numOperands = ((Byte) stackSymbolOperands.pop()).byteValue();
1129                                 numOperands++;
1130 
1131                                 stackSymbolOperands.push(new Byte(numOperands));
1132                             }
1133                         }
1134 
1135                         insertInteger(value);
1136 
1137                         switch (superContext) {
1138                             case CREATE_ERROR:
1139                             case CREATE_APPLICATION:
1140                                 pushContext(WAIT_FOR_OBJECT);
1141                                 break;
1142                             case CREATE_BIDING:
1143                                 pushContext(CREATE_BIDING_VARIABLES);
1144                                 break;
1145                             case CREATE_ATTRIBUT_PAIRS:
1146                                 pushContext(END_ATTRIBUT_PAIRS);
1147                                 break;
1148                             case CREATE_ATTRIBUTION:
1149                                 pushContext(END_ATTRIBUTION);
1150                                 break;
1151                         }
1152                     }
1153                     else {
1154                         insertInteger(value);
1155                         pushContext(WAIT_FOR_END_OBJECT);
1156                     }
1157 
1158                     break;
1159 
1160                 case CREATE_BIDING:
1161                     // A priori, le binder est un symbole, et non un entier
1162                     // Faudra voir si "extension totale" ? la grammaire qui permet un objet OM (autre que <OMS.../>)
1163                     pushContext(context);
1164                     pushContext(CREATE_BIDING_VARIABLES);
1165                     break;
1166                 case CREATE_BIDING_OBJECT:
1167                     insertInteger(value); // pourquoi pas.
1168                     popContext();  // on enlËve le contexte CREATE_BIDING
1169                     pushContext(END_BIDING);
1170                     break;
1171                 case CREATE_APPLICATION:
1172                     throwOME("Malformed application. Can't apply an Integer to something", OMException.OME_SYNTAX);
1173                 case WAIT_FOR_END_OBJECT:
1174                     throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
1175                 case CREATE_ATTRIBUTION:
1176                     throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
1177                 case CREATE_ATTRIBUT_PAIRS:
1178                     throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
1179                 case END_ATTRIBUT_PAIRS:
1180                     throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
1181                 case END_ATTRIBUTION:
1182                     throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
1183                 case CREATE_ERROR:
1184                     throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
1185                 case CREATE_BIDING_VARIABLES:
1186                     throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
1187                 case WAIT_FOR_VARIABLES:
1188                     throwOME("Malformed object. Variables expected", OMException.OME_SYNTAX);
1189                 case END_BIDING:
1190                     throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
1191             }
1192         }
1193         else
1194             throwOME("Malformed object. Something wrong occured");
1195     }
1196 
1197     /***
1198      * Receives notification of a floating-point number element.
1199      *
1200      * <p>By default, do nothing.  Application writers may override this
1201      * method in a subclass.</p>
1202      *
1203      * @param value the value embeded in this Float element.
1204      * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
1205      *
1206      */
1207     public void readFloat(double value) throws OMException {
1208         //TraceContext("readFloat");
1209         Symbol symbol;
1210 
1211         if (!stackContext.empty()) {
1212             byte context = popContext();
1213 
1214             switch (context) {
1215                 case CREATE_OBJECT:
1216                     insertFloat(value);
1217                     pushContext(WAIT_FOR_END_OBJECT);
1218                     break;
1219                 case WAIT_FOR_OBJECT:
1220                     // Dans ce cas l?, on peut venir de plusieurs Ètats, notamment celui d'une application
1221                     // d'un symbole sur des opÈrandes. Il faut que l'on teste alors si l'aritÈ dudit symbole
1222                     // est respectÈe ou pas. Pour les cas o? une application n'est pas faite ? partir d'un
1223                     // symbole, dans la pile des symboles, on AURA MIS UN SYMBOLE FOIREUX (new Symbol("", ""))
1224                     // POUR POUVOIR FAIRE LA DISTINCTION.
1225                     // Dans le cas contraire, on insËre le symbole sans se poser de questions.
1226 
1227 
1228                     // Ca fait que l'on vient de lire un object.
1229                     // Il faut regarder le contexte maintenant pour savoir dans quel Ètat on passe.
1230                     if (!stackContext.empty()) {
1231 
1232                         byte superContext = getContext();
1233                         if (superContext == CREATE_APPLICATION) {
1234                             Symbol currentSymbol = (Symbol) stackSymbol.peek();
1235 
1236                             // d'abord on regarde si c'est un "vrai" symbol.
1237                             if (!currentSymbol.equals("", "")) {
1238                                 // C'est un vrai symbol, on teste maintenant si l'aritÈ est respectÈe
1239                                 byte numOperands = ((Byte) stackSymbolOperands.pop()).byteValue();
1240                                 // On augmente le nombre d'opÈrandes
1241                                 numOperands++;
1242                                 stackSymbolOperands.push(new Byte(numOperands));
1243                             }
1244                         }
1245 
1246                         insertFloat(value);
1247 
1248                         switch (superContext) {
1249                             case CREATE_ERROR:
1250                             case CREATE_APPLICATION:
1251                                 pushContext(WAIT_FOR_OBJECT);
1252                                 break;
1253                             case CREATE_BIDING:
1254                                 pushContext(CREATE_BIDING_VARIABLES);
1255                                 break;
1256                             case CREATE_ATTRIBUT_PAIRS:
1257                                 pushContext(END_ATTRIBUT_PAIRS);
1258                                 break;
1259                             case CREATE_ATTRIBUTION:
1260                                 pushContext(END_ATTRIBUTION);
1261                                 break;
1262                         }
1263                     }
1264                     else {
1265                         insertFloat(value);
1266                         pushContext(WAIT_FOR_END_OBJECT);
1267                     }
1268 
1269                     break;
1270 
1271                 case CREATE_BIDING:
1272                     // A priori, le binder est un symbole, et non un float
1273                     // Faudra voir si "extension totale" ? la grammaire qui permet un objet OM (autre que <OMS.../>)
1274                     pushContext(context);
1275                     pushContext(CREATE_BIDING_VARIABLES);
1276                     break;
1277                 case CREATE_BIDING_OBJECT:
1278                     insertFloat(value); // pourquoi pas.
1279                     popContext();  // on enlËve le contexte CREATE_BIDING
1280                     pushContext(END_BIDING);
1281                     break;
1282                 case CREATE_APPLICATION:
1283                     throwOME("Malformed application. Can't apply an Integer to something", OMException.OME_SYNTAX);
1284                 case WAIT_FOR_END_OBJECT:
1285                     throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
1286                 case CREATE_ATTRIBUTION:
1287                     throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
1288                 case CREATE_ATTRIBUT_PAIRS:
1289                     throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
1290                 case END_ATTRIBUT_PAIRS:
1291                     throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
1292                 case END_ATTRIBUTION:
1293                     throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
1294                 case CREATE_ERROR:
1295                     throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
1296                 case CREATE_BIDING_VARIABLES:
1297                     throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
1298                 case WAIT_FOR_VARIABLES:
1299                     throwOME("Malformed object. Variables expected", OMException.OME_SYNTAX);
1300                 case END_BIDING:
1301                     throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
1302             }
1303         }
1304         else
1305             throwOME("Malformed object. Something wrong occured");
1306     }
1307 
1308     /***
1309      * Receives notification of a string element.
1310      *
1311      * <p>By default, do nothing.  Application writers may override this
1312      * method in a subclass.</p>
1313      *
1314      * @param value the value embeded in this String element.
1315      * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
1316      *
1317      */
1318     public void readString(String value) throws OMException {
1319         //TraceContext("readString");
1320 
1321         if (!stackContext.empty()) {
1322 
1323             compounded.append("<OMSTR>" + value + "</OMSTR>");
1324 
1325             byte context = popContext();
1326             switch (context) {
1327                 case CREATE_OBJECT:
1328                     //System.out.println("\t On insere la string dans l'arbre");
1329                     /*
1330                     Insertion de la string
1331                     }
1332                     */
1333                     pushContext(WAIT_FOR_END_OBJECT);
1334                     break;
1335                 case WAIT_FOR_OBJECT:
1336                     //System.out.println("\t On insere la string dans l'arbre");
1337                     // Dans ce cas l?, on peut venir de plusieurs Ètats, notamment celui d'une application
1338                     // d'un symbole sur des opÈrandes. Il faut que l'on teste alors si l'aritÈ dudit symbole
1339                     // est respectÈe ou pas. Pour les cas o? une application n'est pas faite ? partir d'un
1340                     // symbole, dans la pile des symboles, on AURA MIS UN SYMBOLE FOIREUX (new Symbol("", ""))
1341                     // POUR POUVOIR FAIRE LA DISTINCTION.
1342                     // Dans le cas contraire, on insËre le symbole sans se poser de questions.
1343 
1344 
1345                     // Ca fait que l'on vient de lire un object.
1346                     // Il faut regarder le contexte maintenant pour savoir dans quel Ètat on passe.
1347                     if (!stackContext.empty()) {
1348 
1349                         byte superContext = getContext();
1350                         if (superContext == CREATE_APPLICATION) {
1351                             // alors faut faire le teste de l'aritÈ du symbol
1352 
1353                             Symbol currentSymbol = (Symbol) stackSymbol.peek();
1354 
1355                             // d'abord on regarde si c'est un "vrai" symbol.
1356                             if (!currentSymbol.equals("", "")) {
1357                                 // C'est un vrai symbol, on teste maintenant si l'aritÈ est respectÈe
1358                                 byte numOperands = ((Byte) stackSymbolOperands.pop()).byteValue();
1359                                 // On augmente le nombre d'opÈrandes
1360                                 numOperands++;
1361                                 stackSymbolOperands.push(new Byte(numOperands));
1362                             }
1363                         }
1364 
1365                         //System.out.println("\t On insere la string dans l'arbre");
1366 
1367                         /*
1368                         insertion
1369                         */
1370 
1371                         switch (superContext) {
1372                             case CREATE_ERROR:
1373                             case CREATE_APPLICATION:
1374                                 pushContext(WAIT_FOR_OBJECT);
1375                                 break;
1376                             case CREATE_BIDING:
1377                                 pushContext(CREATE_BIDING_VARIABLES);
1378                                 break;
1379                             case CREATE_ATTRIBUT_PAIRS:
1380                                 pushContext(END_ATTRIBUT_PAIRS);
1381                                 break;
1382                             case CREATE_ATTRIBUTION:
1383                                 pushContext(END_ATTRIBUTION);
1384                                 break;
1385                         }
1386                     }
1387                     else {
1388                         // On insËre directement ce que l'on vient de lire dans l'arbre
1389 
1390                         /*
1391                         insertion.
1392                         */
1393 
1394                         pushContext(WAIT_FOR_END_OBJECT);
1395                     }
1396 
1397                     break;
1398 
1399 
1400                 case CREATE_BIDING:
1401                     //System.out.println("\t On insere la string dans l'arbre");
1402                     /*
1403                     Insertion de la string
1404                     */
1405                     pushContext(context);
1406                     pushContext(CREATE_BIDING_VARIABLES);
1407                     break;
1408                 case CREATE_BIDING_OBJECT:
1409                     //System.out.println("\t On insere la string dans l'arbre");
1410                     /*
1411                     Insertion de la string
1412                     */
1413                     popContext();  // on enlËve le contexte CREATE_BIDING
1414                     pushContext(END_BIDING);
1415                     break;
1416                 case CREATE_APPLICATION:
1417                     //System.out.println("\t CrÈation de l'application" + value);
1418                     pushContext(context);
1419                     pushContext(WAIT_FOR_OBJECT);
1420                     break;
1421                 case WAIT_FOR_END_OBJECT:
1422                     throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
1423                 case CREATE_ATTRIBUTION:
1424                     throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
1425                 case CREATE_ATTRIBUT_PAIRS:
1426                     throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
1427                 case END_ATTRIBUT_PAIRS:
1428                     throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
1429                 case END_ATTRIBUTION:
1430                     throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
1431                 case CREATE_ERROR:
1432                     throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
1433                 case CREATE_BIDING_VARIABLES:
1434                     throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
1435                 case WAIT_FOR_VARIABLES:
1436                     throwOME("Malformed object. Variables expected", OMException.OME_SYNTAX);
1437                 case END_BIDING:
1438                     throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
1439             }
1440         }
1441         else
1442             throwOME("Malformed object. Something wrong occured");
1443     }
1444 
1445     /***
1446      * Receives notification of a variable element.
1447      *
1448      * <p>By default, do nothing.  Application writers may override this
1449      * method in a subclass.</p>
1450      *
1451      * @param name the name of this Variable element.
1452      * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
1453      *
1454      */
1455     public void readVariable(String name) throws OMException {
1456         //TraceContext("readVariable");
1457 
1458         if (!stackContext.empty()) {
1459             byte context = popContext();
1460 
1461             switch (context) {
1462                 case CREATE_OBJECT:
1463                     insertVariable(name);
1464                     pushContext(WAIT_FOR_END_OBJECT);
1465                     break;
1466                 case WAIT_FOR_OBJECT:
1467                     // Dans ce cas l?, on peut venir de plusieurs Ètats, notamment celui d'une application
1468                     // d'un symbole sur des opÈrandes. Il faut que l'on teste alors si l'aritÈ dudit symbole
1469                     // est respectÈe ou pas. Pour les cas o? une application n'est pas faite ? partir d'un
1470                     // symbole, dans la pile des symboles, on AURA MIS UN SYMBOLE FOIREUX (new Symbol("", ""))
1471                     // POUR POUVOIR FAIRE LA DISTINCTION.
1472                     // Dans le cas contraire, on insËre le symbole sans se poser de questions.
1473 
1474 
1475                     // Ca fait que l'on vient de lire un object.
1476                     // Il faut regarder le contexte maintenant pour savoir dans quel Ètat on passe.
1477                     if (!stackContext.empty()) {
1478 
1479                         byte superContext = getContext();
1480                         if (superContext == CREATE_APPLICATION) {
1481                             // alors faut faire le teste de l'aritÈ du symbol
1482                             Symbol currentSymbol = (Symbol) stackSymbol.peek();
1483 
1484                             // d'abord on regarde si c'est un "vrai" symbol.
1485                             if (!currentSymbol.equals("", "")) {
1486                                 // C'est un vrai symbol, on teste maintenant si l'aritÈ est respectÈe
1487                                 byte numOperands = ((Byte) stackSymbolOperands.pop()).byteValue();
1488                                 // On augmente le nombre d'opÈrandes
1489                                 numOperands++;
1490                                 stackSymbolOperands.push(new Byte(numOperands));
1491                             }
1492                         }
1493 
1494                         insertVariable(name);
1495 
1496                         switch (superContext) {
1497                             case CREATE_ERROR:
1498                             case CREATE_APPLICATION:
1499                                 pushContext(WAIT_FOR_OBJECT);
1500                                 break;
1501                             case CREATE_BIDING:
1502                                 pushContext(CREATE_BIDING_VARIABLES);
1503                                 break;
1504                             case CREATE_ATTRIBUT_PAIRS:
1505                                 pushContext(END_ATTRIBUT_PAIRS);
1506                                 break;
1507                             case CREATE_ATTRIBUTION:
1508                                 pushContext(END_ATTRIBUTION);
1509                                 break;
1510                         }
1511                     }
1512                     else {
1513                         insertVariable(name);
1514                         pushContext(WAIT_FOR_END_OBJECT);
1515                     }
1516 
1517                     break;
1518 
1519 
1520                 case CREATE_BIDING:
1521                     // A priori, le binder est un symbole, et non une variable
1522                     // Faudra voir si "extension totale" ? la grammaire qui permet un objet OM (autre que <OMS.../>)
1523                     pushContext(context);
1524                     pushContext(CREATE_BIDING_VARIABLES);
1525                     break;
1526                 case CREATE_BIDING_OBJECT:
1527                     insertVariable(name);
1528                     popContext();  // on enlËve le contexte CREATE_BIDING
1529                     pushContext(END_BIDING);
1530                     break;
1531                 case CREATE_APPLICATION:
1532                     // On insËre un machin particulier
1533                     // Faudra voir plus tard avec function n variables
1534                     Symbol symbol = new Symbol("null", "user_function");
1535                     stackSymbol.push(symbol);
1536                     stackSymbolOperands.push(new Byte((byte) 0));
1537 
1538                     compounded.append("<OMV name=\"" + name + "\"/>");
1539 
1540                     pushContext(context);
1541                     pushContext(WAIT_FOR_OBJECT);
1542                     break;
1543                 case WAIT_FOR_VARIABLES:
1544                     compounded.append("<OMV name=\"" + name + "\"/>");
1545                     pushContext(context);
1546                     break;
1547                 case WAIT_FOR_END_OBJECT:
1548                     throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
1549                 case CREATE_ATTRIBUTION:
1550                     throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
1551                 case CREATE_ATTRIBUT_PAIRS:
1552                     throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
1553                 case END_ATTRIBUT_PAIRS:
1554                     throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
1555                 case END_ATTRIBUTION:
1556                     throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
1557                 case CREATE_ERROR:
1558                     throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
1559                 case CREATE_BIDING_VARIABLES:
1560                     throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
1561                 case END_BIDING:
1562                     throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
1563             }
1564         }
1565         else
1566             throwOME("Malformed object. Something wrong occured");
1567     }
1568 
1569     /***
1570      * Receives notification of a byteArray element.
1571      *
1572      * <p>By default, do nothing.  Application writers may override this
1573      * method in a subclass.</p>
1574      *
1575      * @param value the value embeded in this ByteArray element.
1576      * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
1577      *
1578      */
1579     public void readByteArray(byte[] value) throws OMException {
1580         //TraceContext("readByteArray");
1581 
1582         if (!stackContext.empty()) {
1583 
1584             compounded.append("<OMB" + value + "</OMB>");
1585 
1586             byte context = popContext();
1587             switch (context) {
1588                 case CREATE_OBJECT:
1589                     //System.out.println("\t On insere le ByteArray dans l'arbre");
1590                     /*
1591                     insertion
1592                     */
1593                     pushContext(WAIT_FOR_END_OBJECT);
1594                     break;
1595                 case WAIT_FOR_OBJECT:
1596                     // Dans ce cas l?, on peut venir de plusieurs Ètats, notamment celui d'une application
1597                     // d'un symbole sur des opÈrandes. Il faut que l'on teste alors si l'aritÈ dudit symbole
1598                     // est respectÈe ou pas. Pour les cas o? une application n'est pas faite ? partir d'un
1599                     // symbole, dans la pile des symboles, on AURA MIS UN SYMBOLE FOIREUX (new Symbol("", ""))
1600                     // POUR POUVOIR FAIRE LA DISTINCTION.
1601                     // Dans le cas contraire, on insËre le symbole sans se poser de questions.
1602 
1603 
1604                     // Ca fait que l'on vient de lire un object.
1605                     // Il faut regarder le contexte maintenant pour savoir dans quel Ètat on passe.
1606                     if (!stackContext.empty()) {
1607 
1608                         byte superContext = getContext();
1609                         if (superContext == CREATE_APPLICATION) {
1610                             // alors faut faire le teste de l'aritÈ du symbol
1611 
1612                             Symbol currentSymbol = (Symbol) stackSymbol.peek();
1613 
1614                             // d'abord on regarde si c'est un "vrai" symbol.
1615                             if (!currentSymbol.equals("", "")) {
1616                                 // C'est un vrai symbol, on teste maintenant si l'aritÈ est respectÈe
1617                                 byte numOperands = ((Byte) stackSymbolOperands.pop()).byteValue();
1618                                 // On augmente le nombre d'opÈrandes
1619                                 numOperands++;
1620                                 stackSymbolOperands.push(new Byte(numOperands));
1621                             }
1622                         }
1623 
1624                         //System.out.println("\t On insere le ByteArray dans l'arbre");
1625 
1626                         /*
1627                         insertion
1628                         */
1629 
1630                         switch (superContext) {
1631                             case CREATE_ERROR:
1632                             case CREATE_APPLICATION:
1633                                 pushContext(WAIT_FOR_OBJECT);
1634                                 break;
1635                             case CREATE_BIDING:
1636                                 pushContext(CREATE_BIDING_VARIABLES);
1637                                 break;
1638                             case CREATE_ATTRIBUT_PAIRS:
1639                                 pushContext(END_ATTRIBUT_PAIRS);
1640                                 break;
1641                             case CREATE_ATTRIBUTION:
1642                                 pushContext(END_ATTRIBUTION);
1643                                 break;
1644                         }
1645                     }
1646                     else {
1647                         // On insËre directement ce que l'on vient de lire dans l'arbre
1648 
1649                         /*
1650                         insertion.
1651                         */
1652 
1653                         pushContext(WAIT_FOR_END_OBJECT);
1654                     }
1655 
1656                     break;
1657 
1658 
1659                 case CREATE_BIDING:
1660                     //System.out.println("\t On insere le ByteArray dans l'arbre");
1661                     /*
1662                     insertion
1663                     */
1664                     pushContext(context);
1665                     pushContext(CREATE_BIDING_VARIABLES);
1666                     break;
1667                 case CREATE_BIDING_OBJECT:
1668                     //System.out.println("\t On insere le ByteArray dans l'arbre");
1669                     /*
1670                     insertion
1671                     */
1672                     popContext();  // on enlËve le contexte CREATE_BIDING
1673                     pushContext(END_BIDING);
1674                     break;
1675                 case CREATE_APPLICATION:
1676                     throwOME("Malformed application. Can't apply a ByteArray to something", OMException.OME_SYNTAX);
1677                 case WAIT_FOR_END_OBJECT:
1678                     throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
1679                 case CREATE_ATTRIBUTION:
1680                     throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
1681                 case CREATE_ATTRIBUT_PAIRS:
1682                     throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
1683                 case END_ATTRIBUT_PAIRS:
1684                     throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
1685                 case END_ATTRIBUTION:
1686                     throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
1687                 case CREATE_ERROR:
1688                     throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
1689                 case CREATE_BIDING_VARIABLES:
1690                     throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
1691                 case WAIT_FOR_VARIABLES:
1692                     throwOME("Malformed object. Variables expected", OMException.OME_SYNTAX);
1693                 case END_BIDING:
1694                     throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
1695             }
1696         }
1697         else
1698             throwOME("Malformed object. Something wrong occured");
1699     }
1700 
1701     /***
1702      * Receives notification of a symbol element.
1703      *
1704      * <p>By default, do nothing.  Application writers may override this
1705      * method in a subclass.</p>
1706      *
1707      * @param value the value embeded in this Symbol element.
1708      * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
1709      * @see Symbol
1710      */
1711     public void readSymbol(Symbol value) throws OMException {
1712         //TraceContext("readSymbol");
1713         byte errorCode;
1714         String typeOpe;
1715 
1716 
1717         if (!stackContext.empty()) {
1718             byte context = popContext();
1719 
1720             switch (context) {
1721                 case CREATE_APPLICATION:
1722                     pushContext(context);
1723                     // Le symbole existe. On regarde maintenant si le symbole peut Ítre utilisÈ
1724                     // en tant qu'application
1725                     if (true /*supportedCD.isSymbolApplication(value.getCD(), value.getName())*/) {
1726                         insertSymbol(value);
1727 
1728                         // Gestion des symboles.
1729                         stackSymbol.push(value);
1730                         stackSymbolOperands.push(new Byte((byte) 0));
1731 
1732                         pushContext(WAIT_FOR_OBJECT);
1733                     }
1734                     else
1735                         throwOME("Malformed application. " /*+ supportedCD.errorToString()*/, OMException.OME_SYNTAX);
1736                     break;
1737 
1738                 case CREATE_OBJECT:
1739                     insertSymbol(value);
1740                     pushContext(WAIT_FOR_END_OBJECT);
1741                     break;
1742                 case WAIT_FOR_OBJECT:
1743                     // Dans ce cas l?, on peut venir de plusieurs Ètats, notamment celui d'une application
1744                     // d'un symbole sur des opÈrandes. Il faut que l'on teste alors si l'aritÈ dudit symbole
1745                     // est respectÈe ou pas. Pour les cas o? une application n'est pas faite ? partir d'un
1746                     // symbole, dans la pile des symboles, on AURA MIS UN SYMBOLE FOIREUX (new Symbol("", ""))
1747                     // POUR POUVOIR FAIRE LA DISTINCTION.
1748                     // Dans le cas contraire, on insËre le symbole sans se poser de questions.
1749 
1750 
1751                     // Ca fait que l'on vient de lire un object.
1752                     // Il faut regarder le contexte maintenant pour savoir dans quel Ètat on passe.
1753                     if (!stackContext.empty()) {
1754 
1755                         byte superContext = getContext();
1756                         if (superContext == CREATE_APPLICATION) {
1757                             // alors faut faire le teste de l'aritÈ du symbol
1758                             Symbol currentSymbol = (Symbol) stackSymbol.peek();
1759 
1760                             // d'abord on regarde si c'est un "vrai" symbol.
1761                             if (!currentSymbol.equals("", "")) {
1762                                 // C'est un vrai symbol, on teste maintenant si l'aritÈ est respectÈe
1763                                 byte numOperands = ((Byte) stackSymbolOperands.pop()).byteValue();
1764                                 // On augmente le nombre d'opÈrandes
1765                                 numOperands++;
1766                                 stackSymbolOperands.push(new Byte(numOperands));
1767                             }
1768                         }
1769 
1770                         insertSymbol(value);
1771 
1772                         switch (superContext) {
1773                             case CREATE_ERROR:
1774                             case CREATE_APPLICATION:
1775                                 pushContext(WAIT_FOR_OBJECT);
1776                                 break;
1777                             case CREATE_BIDING:
1778                                 pushContext(CREATE_BIDING_VARIABLES);
1779                                 break;
1780                             case CREATE_ATTRIBUT_PAIRS:
1781                                 pushContext(END_ATTRIBUT_PAIRS);
1782                                 break;
1783                             case CREATE_ATTRIBUTION:
1784                                 pushContext(END_ATTRIBUTION);
1785                                 break;
1786                         }
1787                     }
1788                     else
1789                         insertSymbol(value);
1790 
1791                     break;
1792 
1793                 case CREATE_BIDING:
1794                     insertSymbol(value);
1795                     pushContext(context);
1796                     pushContext(CREATE_BIDING_VARIABLES);
1797                     break;
1798                 case CREATE_BIDING_OBJECT:
1799                     insertSymbol(value);
1800                     popContext();  // on enlËve le contexte CREATE_BIDING_OBJECT
1801                     popContext();  // on enlËve le contexte CREATE_BIDING
1802                     pushContext(END_BIDING);
1803                     break;
1804                 case CREATE_ATTRIBUT_PAIRS:
1805                 case CREATE_ERROR:
1806                     /*
1807                     insertSymbol(value);
1808                     */
1809 
1810                     /*
1811                     Pour le moment on ne fait que lever une exception, en retournant le symbole
1812                     correspondant ? l'erreur qui a ÈtÈ transmise.
1813                     On verra par la suite comment on se dÈbrouille avec Áa.
1814                     */
1815                     //throw new RuntimeException(value.toString());
1816                     pushContext(context);
1817                     pushContext(WAIT_FOR_OBJECT);
1818                     break;
1819                 case WAIT_FOR_END_OBJECT:
1820                     throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
1821                 case CREATE_ATTRIBUTION:
1822                     throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
1823                 case END_ATTRIBUT_PAIRS:
1824                     throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
1825                 case END_ATTRIBUTION:
1826                     throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
1827                 case CREATE_BIDING_VARIABLES:
1828                     throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
1829                 case WAIT_FOR_VARIABLES:
1830                     throwOME("Malformed object. Variables expected", OMException.OME_SYNTAX);
1831                 case END_BIDING:
1832                     throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
1833             }
1834         }
1835         else
1836             throwOME("Malformed object. Something wrong occured");
1837     }
1838 
1839     /***
1840      * Receives notification of a comment element.
1841      *
1842      * <p>By default, do nothing.  Application writers may override this
1843      * method in a subclass.</p>
1844      *
1845      * @param value the value embeded in this Comment element.
1846      * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
1847      * @see Comment
1848      */
1849     public void readComment(String value) throws OMException {}
1850 
1851     /***
1852     * Inserts the specified symbol.
1853     * @param symbol the specified symbol
1854     */
1855     private void insertSymbol(Symbol symbol) {
1856         compounded.append("<OMS cd=\"" + symbol.getCD() + "\" name=\"" + symbol.getName() + "\"/>");
1857     }
1858 
1859     /***
1860     * Insert the specified variable in the OpenMath object.<BR>
1861     * It first checks if the variable identifies an element to compound. If so, the
1862     * correspondind OpenMath object is inserted. Otherwise, the variable is inserted
1863     * @param name the name of the variable.
1864     */
1865     private void insertVariable(String name) {
1866         OpenMathizable omizable = (OpenMathizable) elements.get(name);
1867         if (omizable == null)
1868             compounded.append("<OMV name = \"" + name + "\"/>");
1869         else {
1870             name = omizable.getOpenMath();
1871             if ((name != null) && (name.startsWith("<OMOBJ>"))) {
1872                 name = name.substring(7, name.length() - 9);
1873                 compounded.append(name);
1874             }
1875             else
1876                 compounded.append("<OMV name = \"" + name + "\"/>");
1877         }
1878     }
1879 
1880     /***
1881     * Inserts the specified integer value.
1882     * @param value the specified integer.
1883     */
1884     private void insertInteger(BigInt value) {
1885         compounded.append("<OMI>");
1886         compounded.append((value.getSign() != 1) ? "-" : "");
1887         compounded.append(value.getDigits());
1888         compounded.append("</OMI>");
1889     }
1890 
1891     /***
1892     * Inserts the specified float value.
1893     * @param value the specified float.
1894     */
1895     private void insertFloat(double value) {
1896         compounded.append("<OMF dec=\"" + value + "\"/>");
1897     }
1898 
1899     private void TraceContext(String methodName) {
1900         System.out.println("\n\t\t <--");
1901         System.out.println("\t\t On entre dans la methode " + methodName);
1902         String str = (stackSymbol.empty() == true) ? "null" : ((Symbol) stackSymbol.peek()).toString();
1903         System.out.println("\t\t La valeur courante est " + str);
1904         str = (stackSymbolOperands.empty() == true) ? "null" : ""+((Byte) stackSymbolOperands.peek()).byteValue();
1905         System.out.println("\t\t Le nbre d'operandes est " + str );
1906         System.out.println("\t\t -->");
1907     }
1908 }
1909