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