e007ea5913567f14c43e387ea4ea3f0e907a1b87
[occt.git] / src / ExprIntrp / ExprIntrp_yaccintrf.cxx
1 // Copyright (c) 1997-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #include <ExprIntrp_yaccintrf.hxx>
16 #include <ExprIntrp_yaccanal.hxx>
17 #include <Expr_GeneralExpression.hxx>
18 #include <Expr_NamedExpression.hxx>
19 #include <Expr_NamedUnknown.hxx>
20 #include <Expr_NamedConstant.hxx>
21 #include <Expr_NamedFunction.hxx>
22 #include <Expr_NumericValue.hxx>
23 #include <Expr_UnaryFunction.hxx>
24 #include <Expr_BinaryFunction.hxx>
25 #include <Expr_PolyFunction.hxx>
26 #include <Expr_Exponentiate.hxx>
27 #include <Expr_Absolute.hxx>
28 #include <Expr_ArcCosine.hxx>
29 #include <Expr_ArcSine.hxx>
30 #include <Expr_ArcTangent.hxx>
31 #include <Expr_ArgCosh.hxx>
32 #include <Expr_ArgSinh.hxx>
33 #include <Expr_ArgTanh.hxx>
34 #include <Expr_Cosh.hxx>
35 #include <Expr_Cosine.hxx>
36 #include <Expr_Exponential.hxx>
37 #include <Expr_LogOf10.hxx>
38 #include <Expr_LogOfe.hxx>
39 #include <Expr_Sign.hxx>
40 #include <Expr_Sine.hxx>
41 #include <Expr_Sinh.hxx>
42 #include <Expr_SquareRoot.hxx>
43 #include <Expr_Tangent.hxx>
44 #include <Expr_Tanh.hxx>
45 #include <Expr_Equal.hxx>
46 #include <Expr_SystemRelation.hxx>
47 #include <Expr_UnknownIterator.hxx>
48 #include <Expr_FunctionDerivative.hxx>
49 #include <Expr.hxx>
50 #include <Expr_SequenceOfGeneralExpression.hxx>
51 #include <Expr_Operators.hxx>
52 #include <ExprIntrp_SyntaxError.hxx>
53 #include <Expr_Array1OfNamedUnknown.hxx>
54 #include <Expr_Array1OfGeneralExpression.hxx>
55
56 static TCollection_AsciiString ExprIntrp_assname;
57 static TCollection_AsciiString ExprIntrp_funcdefname;
58 static Standard_Integer ExprIntrp_nbargs;
59 static Standard_Integer ExprIntrp_nbdiff;
60
61 extern "C" void ExprIntrp_StartFunction()
62 {
63   const TCollection_AsciiString& name = ExprIntrp_GetResult();
64   ExprIntrp_Recept.PushName(name);
65   ExprIntrp_nbargs = 0;
66 }
67
68 extern "C" void ExprIntrp_StartDerivate()
69 {
70   const TCollection_AsciiString& name = ExprIntrp_GetResult();
71   ExprIntrp_Recept.PushName(name);
72 }
73
74 extern "C" void ExprIntrp_EndDerivate()
75 {
76   int degree;
77   degree = ExprIntrp_GetDegree();
78   ExprIntrp_Recept.PushValue(degree);
79 }
80
81 extern "C" void ExprIntrp_Derivation()
82 {
83   ExprIntrp_Recept.PushValue(1);
84   const TCollection_AsciiString& thename = ExprIntrp_GetResult();
85   Handle(Expr_NamedExpression) namexp = ExprIntrp_Recept.GetNamed(thename);
86   if (namexp.IsNull()) {
87     namexp = new Expr_NamedUnknown(thename);
88   }
89   if (!namexp->IsKind(STANDARD_TYPE(Expr_NamedUnknown))) {
90     ExprIntrp_SyntaxError::Raise();
91   }
92   ExprIntrp_Recept.Push(namexp);
93 }
94
95 extern "C" void ExprIntrp_DerivationValue()
96 {
97   const TCollection_AsciiString& aStr = ExprIntrp_GetResult();
98   ExprIntrp_Recept.PopValue();
99   ExprIntrp_Recept.PushValue(aStr.IntegerValue());
100 }
101
102 extern "C" void ExprIntrp_EndDerivation()
103 {
104   Standard_Integer degree = ExprIntrp_Recept.PopValue();
105   Handle(Expr_NamedUnknown) var = Handle(Expr_NamedUnknown)::DownCast(ExprIntrp_Recept.Pop());
106   Handle(Expr_GeneralExpression) exp = ExprIntrp_Recept.Pop();
107   exp = exp->NDerivative(var,degree);
108   ExprIntrp_Recept.Push(exp);
109 }
110
111 extern "C" void ExprIntrp_StartDifferential()
112 {
113   ExprIntrp_StartDerivate();
114   ExprIntrp_nbdiff = 0;
115 }
116
117 extern "C" void ExprIntrp_DiffDegreeVar()
118 {
119   const TCollection_AsciiString& aStr = ExprIntrp_GetResult();
120   const char* s = aStr.ToCString();
121   if ( *s != 'X' && *s != 'x' ) {
122     ExprIntrp_SyntaxError::Raise();
123   }
124   s++;
125   Standard_Integer rank = atoi(s);
126   ExprIntrp_Recept.PushValue(rank);
127   ExprIntrp_nbdiff++;
128 }
129
130 extern "C" void ExprIntrp_DiffVar()
131 {
132   ExprIntrp_Recept.PushValue(1);
133   ExprIntrp_DiffDegreeVar();
134 }
135
136 extern "C" void ExprIntrp_DiffDegree()
137 {
138   const TCollection_AsciiString& aStr = ExprIntrp_GetResult();
139   Standard_Integer deg = aStr.IntegerValue();
140   ExprIntrp_Recept.PushValue(deg);
141 }
142
143 extern "C" void ExprIntrp_VerDiffDegree()
144 {
145   const TCollection_AsciiString& aStr = ExprIntrp_GetResult();
146   Standard_Integer deg = aStr.IntegerValue();
147   Standard_Integer thedeg = ExprIntrp_Recept.PopValue();
148   if (deg != thedeg) {
149     ExprIntrp_SyntaxError::Raise();
150   }
151   ExprIntrp_Recept.PushValue(deg);
152 }
153
154 extern "C" void ExprIntrp_EndDifferential()
155 {
156   TCollection_AsciiString name = ExprIntrp_Recept.PopName();
157   Handle(Expr_GeneralFunction) thefunc = ExprIntrp_Recept.GetFunction(name);
158   if (thefunc.IsNull()) {
159     ExprIntrp_SyntaxError::Raise();
160   }
161   Standard_Integer rank,degree;
162   Handle(Expr_NamedUnknown) thediff;
163   Standard_Integer nbvars = thefunc->NbOfVariables();
164
165   for (Standard_Integer i=1; i<= ExprIntrp_nbdiff; i++) {
166     rank = ExprIntrp_Recept.PopValue();
167     degree = ExprIntrp_Recept.PopValue();
168     if ((rank > nbvars) || (rank < 1)) {
169       ExprIntrp_SyntaxError::Raise();
170     }
171     thediff = thefunc->Variable(rank);
172     thefunc = new Expr_FunctionDerivative(thefunc,thediff,degree);
173   }
174   ExprIntrp_Recept.PushFunction(thefunc);
175 }
176
177 extern "C" void ExprIntrp_EndDiffFunction()
178 {
179   Handle(Expr_GeneralFunction) thefunc = ExprIntrp_Recept.PopFunction();
180   if (thefunc.IsNull()) {
181     ExprIntrp_SyntaxError::Raise();
182   }
183   Standard_Integer nbargs = thefunc->NbOfVariables();
184   if (nbargs == 1) {
185     Handle(Expr_GeneralExpression) op = ExprIntrp_Recept.Pop();
186     Handle(Expr_UnaryFunction) res = 
187       new Expr_UnaryFunction(thefunc,op);
188     ExprIntrp_Recept.Push(res);
189   }
190   else if (nbargs == 2) {
191     Handle(Expr_GeneralExpression) arg2 = ExprIntrp_Recept.Pop();
192     Handle(Expr_GeneralExpression) arg1 = ExprIntrp_Recept.Pop();
193     if (arg1.IsNull()) {
194       ExprIntrp_SyntaxError::Raise();
195     }
196     Handle(Expr_BinaryFunction) res =
197       new Expr_BinaryFunction(thefunc,arg1,arg2);
198     ExprIntrp_Recept.Push(res);
199   }
200   else {
201     Expr_Array1OfGeneralExpression tabarg(1,nbargs);
202     Handle(Expr_GeneralExpression) arg;
203     for (Standard_Integer i = 1; i<= nbargs; i++) {
204       arg = ExprIntrp_Recept.Pop();
205       if (arg.IsNull()) {
206         ExprIntrp_SyntaxError::Raise();
207       }
208       tabarg(nbargs-i+1) = arg;
209     }
210     Handle(Expr_PolyFunction) res = 
211       new Expr_PolyFunction(thefunc,tabarg);
212     ExprIntrp_Recept.Push(res);
213   }
214 }
215   
216 static Handle(Expr_GeneralExpression) ExprIntrp_StandardFunction(const TCollection_AsciiString& name, const Handle(Expr_GeneralExpression)& op)
217 {
218 // return standard functions equivalent corresponding to <name> 
219 // with given operand <op> if exists. Returns null value if not.
220 // <name> is not case sensitive
221
222   Handle(Expr_GeneralExpression) res;
223   if ((name == "abs") || (name == "Abs")) {
224     res = new Expr_Absolute(op);
225   }
226   else if ((name == "acos") || (name == "ACos")) {
227     res = new Expr_ArcCosine(op);
228   }
229   else if ((name == "asin") || (name == "ASin")) {
230     res = new Expr_ArcSine(op);
231   }
232   else if ((name == "atan") || (name == "ATan")) {
233     res = new Expr_ArcTangent(op);
234   }
235   else if ((name == "acosh") || (name == "ACosh")) {
236     res = new Expr_ArgCosh(op);
237   }
238   else if ((name == "asinh") || (name == "ASinh")) {
239     res = new Expr_ArgSinh(op);
240   }
241   else if ((name == "atanh") || (name == "ATanh")) {
242     res = new Expr_ArgTanh(op);
243   }
244   else if ((name == "cosh") || (name == "Cosh")) {
245     res = new Expr_Cosh(op);
246   }
247   else if ((name == "cos") || (name == "Cos")) {
248     res = new Expr_Cosine(op);
249   }
250   else if ((name == "exp") || (name == "Exp")) {
251     res = new Expr_Exponential(op);
252   }
253   else if (name == "log") {
254     res = new Expr_LogOf10(op);
255   }
256   else if ((name == "Log") || (name == "Ln")) {
257     res = new Expr_LogOfe(op);
258   }
259   else if ((name == "sign") || (name == "Sign")) {
260     res = new Expr_Sign(op);
261   }
262   else if ((name == "sin") || (name == "Sin")) {
263     res = new Expr_Sine(op);
264   }
265   else if ((name == "sinh") || (name == "Sinh")) {
266     res = new Expr_Sinh(op);
267   }
268   else if ((name == "sqrt") || (name == "Sqrt")) {
269     res = new Expr_SquareRoot(op);
270   }
271   else if ((name == "tan") || (name == "Tan")) {
272     res = new Expr_Tangent(op);
273   }
274   else if ((name == "tanh") || (name == "Tanh")) {
275     res = new Expr_Tanh(op);
276   }
277   return res;
278 }
279
280
281 extern "C" void ExprIntrp_EndDerFunction()
282 {
283   TCollection_AsciiString name = ExprIntrp_Recept.PopName();
284   Handle(Expr_GeneralExpression) op = ExprIntrp_Recept.Pop();
285   Handle(Expr_GeneralExpression) resstand = ExprIntrp_StandardFunction(name,op);
286
287   if (!resstand.IsNull()) {
288     Handle(Expr_NamedUnknown) var;
289     Expr_UnknownIterator rit(resstand);
290     while (rit.More()) {
291       if (!var.IsNull()) {
292         ExprIntrp_SyntaxError::Raise();
293       }
294       else {
295         var = rit.Value();
296         if (var->IsAssigned()) {
297           var.Nullify();
298         }
299       }
300       rit.Next();
301     }
302     if (var.IsNull()) {
303       ExprIntrp_SyntaxError::Raise();
304     }
305     else {
306       Handle(Expr_GeneralExpression) res = resstand->NDerivative(var,ExprIntrp_Recept.PopValue());
307       ExprIntrp_Recept.Push(res);
308     }
309   }
310   else {
311     Handle(Expr_NamedFunction) thefunc = ExprIntrp_Recept.GetFunction(name);
312     if (thefunc.IsNull()) {
313       ExprIntrp_SyntaxError::Raise();
314     }
315     Standard_Integer nbargs = thefunc->NbOfVariables();
316     if (nbargs != 1) {
317       ExprIntrp_SyntaxError::Raise();
318     }
319     Handle(Expr_NamedUnknown) var = thefunc->Variable(1);
320     Handle(Expr_FunctionDerivative) thefuncder = 
321       new Expr_FunctionDerivative(thefunc,var,ExprIntrp_Recept.PopValue());
322     Handle(Expr_UnaryFunction) res = 
323       new Expr_UnaryFunction(thefuncder,op);
324     ExprIntrp_Recept.Push(res);
325   }
326 }
327     
328 extern "C" void ExprIntrp_EndFunction()
329 {
330   TCollection_AsciiString name = ExprIntrp_Recept.PopName();
331   Handle(Expr_GeneralExpression) op = ExprIntrp_Recept.Pop();
332
333   Handle(Expr_GeneralExpression) resstand = ExprIntrp_StandardFunction(name,op);
334   if (!resstand.IsNull()) {
335     ExprIntrp_Recept.Push(resstand->ShallowSimplified());
336   }
337   else {
338     Handle(Expr_NamedFunction) thefunc = ExprIntrp_Recept.GetFunction(name);
339     if (thefunc.IsNull()) {
340       ExprIntrp_SyntaxError::Raise();
341       }
342     Standard_Integer nbargs = thefunc->NbOfVariables();
343     if (nbargs == 1) {
344       Handle(Expr_UnaryFunction) res = 
345         new Expr_UnaryFunction(thefunc,op);
346       ExprIntrp_Recept.Push(res);
347     }
348     else if (nbargs == 2) {
349       Handle(Expr_GeneralExpression) arg1 = ExprIntrp_Recept.Pop();
350       if (arg1.IsNull()) {
351         ExprIntrp_SyntaxError::Raise();
352       }
353       Handle(Expr_BinaryFunction) res =
354         new Expr_BinaryFunction(thefunc,arg1,op);
355       ExprIntrp_Recept.Push(res);
356     }
357     else {
358       Expr_Array1OfGeneralExpression tabarg(1,nbargs);
359       Handle(Expr_GeneralExpression) arg;
360       tabarg(nbargs) = op;
361       for (Standard_Integer i = 1; i< nbargs; i++) {
362         arg = ExprIntrp_Recept.Pop();
363         if (arg.IsNull()) {
364           ExprIntrp_SyntaxError::Raise();
365         }
366         tabarg(nbargs-i) = arg;
367       }
368       Handle(Expr_PolyFunction) res = 
369         new Expr_PolyFunction(thefunc,tabarg);
370       ExprIntrp_Recept.Push(res);
371     }
372   }
373 }
374
375 extern "C" void ExprIntrp_NextFuncArg()
376 {
377   ExprIntrp_nbargs++;
378 }
379
380 extern "C" void ExprIntrp_EndFuncArg()
381 {
382   ExprIntrp_nbargs++;
383 }
384
385 extern "C" void ExprIntrp_SumOperator()
386 {
387   Handle(Expr_GeneralExpression) op2 = ExprIntrp_Recept.Pop();
388   Handle(Expr_GeneralExpression) op1 = ExprIntrp_Recept.Pop();
389   Handle(Expr_Sum) sres = op1 + op2;
390   Handle(Expr_GeneralExpression) res = sres->ShallowSimplified();
391   ExprIntrp_Recept.Push(res);
392 }
393
394 extern "C" void ExprIntrp_MinusOperator()
395 {
396   Handle(Expr_GeneralExpression) op2 = ExprIntrp_Recept.Pop();
397   Handle(Expr_GeneralExpression) op1 = ExprIntrp_Recept.Pop();
398   Handle(Expr_Difference) res = op1 - op2;
399   ExprIntrp_Recept.Push(res->ShallowSimplified());
400 }
401
402 extern "C" void ExprIntrp_DivideOperator()
403 {
404   Handle(Expr_GeneralExpression) op2 = ExprIntrp_Recept.Pop();
405   Handle(Expr_GeneralExpression) op1 = ExprIntrp_Recept.Pop();
406   Handle(Expr_Division) res = op1 / op2;
407   ExprIntrp_Recept.Push(res->ShallowSimplified());
408 }
409
410 extern "C" void ExprIntrp_ExpOperator()
411 {
412   Handle(Expr_GeneralExpression) op2 = ExprIntrp_Recept.Pop();
413   Handle(Expr_GeneralExpression) op1 = ExprIntrp_Recept.Pop();
414   Handle(Expr_Exponentiate) res = new Expr_Exponentiate(op1,op2);
415   ExprIntrp_Recept.Push(res->ShallowSimplified());
416 }
417
418 extern "C" void ExprIntrp_ProductOperator()
419 {
420   Handle(Expr_GeneralExpression) op2 = ExprIntrp_Recept.Pop();
421   Handle(Expr_GeneralExpression) op1 = ExprIntrp_Recept.Pop();
422   Handle(Expr_Product) res = op1 * op2;
423   ExprIntrp_Recept.Push(res->ShallowSimplified());
424 }
425
426 extern "C" void ExprIntrp_UnaryMinusOperator()
427 {
428   Handle(Expr_GeneralExpression) op = ExprIntrp_Recept.Pop();
429   Handle(Expr_UnaryMinus) res = new Expr_UnaryMinus(op);
430   ExprIntrp_Recept.Push(res->ShallowSimplified());
431 }
432
433 extern "C" void ExprIntrp_UnaryPlusOperator()
434 {
435   Handle(Expr_GeneralExpression) op = ExprIntrp_Recept.Pop();
436   ExprIntrp_Recept.Push(op);
437 }
438
439 extern "C" void ExprIntrp_VariableIdentifier()
440 {
441   const TCollection_AsciiString& thename = ExprIntrp_GetResult();
442   Handle(Expr_NamedExpression) nameexp = ExprIntrp_Recept.GetNamed(thename);
443   if (nameexp.IsNull()) {
444     nameexp = new Expr_NamedUnknown(thename);
445     ExprIntrp_Recept.Use(nameexp);
446   }
447   ExprIntrp_Recept.Push(nameexp);
448 }
449
450 extern "C" void ExprIntrp_NumValue()
451 {
452   const TCollection_AsciiString& aStr = ExprIntrp_GetResult();
453   Standard_Real value = aStr.RealValue();
454   Handle(Expr_NumericValue) nval = new Expr_NumericValue(value);
455   ExprIntrp_Recept.Push(nval);
456 }
457
458 extern "C" void ExprIntrp_AssignVariable()
459 {
460   ExprIntrp_assname = ExprIntrp_GetResult();
461 }
462
463 extern "C" void ExprIntrp_Deassign()
464 {
465   const TCollection_AsciiString& thename = ExprIntrp_GetResult();
466   Handle(Expr_NamedExpression) nameexp = ExprIntrp_Recept.GetNamed(thename);
467   if (nameexp.IsNull()) {
468     ExprIntrp_SyntaxError::Raise();
469   }
470   if (!nameexp->IsKind(STANDARD_TYPE(Expr_NamedUnknown))) {
471     ExprIntrp_SyntaxError::Raise();
472   }
473   Handle(Expr_NamedUnknown) var = Handle(Expr_NamedUnknown)::DownCast(nameexp);
474   var->Deassign();
475 }
476
477 extern "C" void ExprIntrp_DefineFunction()
478 {
479   ExprIntrp_funcdefname = ExprIntrp_Recept.PopName();
480   ExprIntrp_Recept.PushValue(ExprIntrp_nbargs);
481 }
482
483 extern "C" void ExprIntrp_close()
484 {
485   ExprIntrp_stop_string();
486 }
487
488 extern "C" void ExprIntrperror(char* msg)
489 {
490   ExprIntrp_close();
491   ExprIntrp_SyntaxError::Raise(msg);
492 }
493
494
495 extern "C" void ExprIntrp_EndOfEqual()
496 {
497   Handle(Expr_GeneralExpression) memb2 = ExprIntrp_Recept.Pop();
498   Handle(Expr_GeneralExpression) memb1 = ExprIntrp_Recept.Pop();
499   Handle(Expr_Equal) res = new Expr_Equal(memb1,memb2);
500   ExprIntrp_Recept.PushRelation(res);
501 }
502
503 extern "C" void ExprIntrp_EndOfRelation()
504 {
505   Handle(Expr_SystemRelation) sys;
506   Handle(Expr_GeneralRelation) currel;
507   Handle(Expr_GeneralRelation) oldrel;
508   while (!ExprIntrp_Recept.IsRelStackEmpty()) {
509     currel = ExprIntrp_Recept.PopRelation();
510     if (!sys.IsNull()) {
511       sys->Add(currel);
512     }
513     else if (!oldrel.IsNull()) {
514       sys = new Expr_SystemRelation(oldrel);
515       sys->Add(currel);
516     }
517     else {
518       oldrel = currel;
519     }
520   }
521   if (sys.IsNull()) {
522     ExprIntrp_Recept.PushRelation(currel);
523   }
524   else {
525     ExprIntrp_Recept.PushRelation(sys);
526   }
527 }
528
529 extern "C" void ExprIntrp_EndOfAssign()
530 {
531   Handle(Expr_NamedExpression) namexp = ExprIntrp_Recept.GetNamed(ExprIntrp_assname);
532   Handle(Expr_NamedUnknown) namu;
533   if (namexp.IsNull()) {
534     namu = new Expr_NamedUnknown(ExprIntrp_assname);
535     ExprIntrp_Recept.Use(namu);
536   }
537   else {
538     if (!namexp->IsKind(STANDARD_TYPE(Expr_NamedUnknown))) {
539       ExprIntrp_SyntaxError::Raise();
540     }
541     namu = Handle(Expr_NamedUnknown)::DownCast(namexp);
542   }
543   namu->Assign(ExprIntrp_Recept.Pop());
544 }
545
546 extern "C" void ExprIntrp_EndOfFuncDef()
547 {
548   Handle(Expr_GeneralExpression) theexp = ExprIntrp_Recept.Pop();
549   Standard_Integer nbargs = ExprIntrp_Recept.PopValue();
550   Expr_Array1OfNamedUnknown vars(1,nbargs);
551   Expr_Array1OfNamedUnknown internvars(1,nbargs);
552   Standard_Integer i;
553   for (i=nbargs; i > 0; i--) {
554     vars(i) = Handle(Expr_NamedUnknown)::DownCast(ExprIntrp_Recept.Pop());
555     internvars(i) = Handle(Expr_NamedUnknown)::DownCast(vars(i)->Copy());
556   }
557   theexp = Expr::CopyShare(theexp);  // ATTENTION, PROTECTION BUG STACK
558   for (i=1; i<= nbargs; i++) {
559     if (theexp->Contains(vars(i))) {
560       theexp->Replace(vars(i),internvars(i));
561     }
562     else {
563       if (theexp == vars(i)) {
564         theexp = internvars(i);
565       }
566     }
567   }
568   Handle(Expr_NamedFunction) thefunc = 
569     new Expr_NamedFunction(ExprIntrp_funcdefname,
570                            theexp,
571                            internvars);
572   ExprIntrp_Recept.Use(thefunc);
573 }
574
575 extern "C" void ExprIntrp_ConstantIdentifier()
576 {
577   const TCollection_AsciiString& thename = ExprIntrp_GetResult();
578   ExprIntrp_Recept.PushName(thename);
579 }
580
581 extern "C" void ExprIntrp_ConstantDefinition()
582 {
583   TCollection_AsciiString name = ExprIntrp_Recept.PopName();
584   const TCollection_AsciiString& aStr = ExprIntrp_GetResult();
585   Standard_Real val = aStr.RealValue();
586   Handle(Expr_NamedConstant) theconst = new Expr_NamedConstant(name,val);
587   ExprIntrp_Recept.Use(theconst);
588   ExprIntrp_Recept.Push(theconst);
589 }
590
591
592 extern "C" void ExprIntrp_Sumator()
593 {
594   Handle(Expr_NumericValue) number = Handle(Expr_NumericValue)::DownCast(ExprIntrp_Recept.Pop());
595   Standard_Integer nb = (Standard_Integer) number->GetValue();
596   Handle(Expr_GeneralExpression) inc = ExprIntrp_Recept.Pop();
597   Handle(Expr_GeneralExpression) first = ExprIntrp_Recept.Pop();
598   Handle(Expr_NamedUnknown) var = Handle(Expr_NamedUnknown)::DownCast(ExprIntrp_Recept.Pop());
599   Handle(Expr_GeneralExpression) theexp = ExprIntrp_Recept.Pop();
600   Standard_Boolean thesame = (theexp == var);
601   Handle(Expr_GeneralExpression) cur = Expr::CopyShare(first);
602   Handle(Expr_GeneralExpression) res;
603   Handle(Expr_GeneralExpression) member;
604   Expr_SequenceOfGeneralExpression seq;
605   for (Standard_Integer i=1; i<= nb; i++) {
606     if (thesame) {
607       member = cur;
608     }
609     else {
610       member = Expr::CopyShare(theexp);
611       member->Replace(var,cur);
612     }
613     seq.Append(member);
614     cur = (cur + inc)->ShallowSimplified();
615   }
616   res = new Expr_Sum(seq);
617   ExprIntrp_Recept.Push(res->ShallowSimplified());
618 }
619
620 extern "C" void ExprIntrp_Productor()
621 {
622   Handle(Expr_NumericValue) number = Handle(Expr_NumericValue)::DownCast(ExprIntrp_Recept.Pop());
623   Standard_Integer nb = (Standard_Integer) number->GetValue();
624   Handle(Expr_GeneralExpression) inc = ExprIntrp_Recept.Pop();
625   Handle(Expr_GeneralExpression) first = ExprIntrp_Recept.Pop();
626   Handle(Expr_NamedUnknown) var = Handle(Expr_NamedUnknown)::DownCast(ExprIntrp_Recept.Pop());
627   Handle(Expr_GeneralExpression) theexp = ExprIntrp_Recept.Pop();
628   Standard_Boolean thesame = (theexp == var);
629   Handle(Expr_GeneralExpression) cur = Expr::CopyShare(first);
630   Handle(Expr_GeneralExpression) res;
631   Handle(Expr_GeneralExpression) member;
632   Expr_SequenceOfGeneralExpression seq;
633   for (Standard_Integer i=1; i<= nb; i++) {
634     if (thesame) {
635       member = cur;
636     }
637     else {
638       member = Expr::CopyShare(theexp);
639       member->Replace(var,cur);
640     }
641     seq.Append(member);
642     cur = (cur + inc)->ShallowSimplified();
643   }
644   res = new Expr_Product(seq);
645   ExprIntrp_Recept.Push(res->ShallowSimplified());
646 }