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