View Javadoc

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