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