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
ExprIntrp_StartFunction()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
ExprIntrp_StartDerivate()68 extern "C" void ExprIntrp_StartDerivate()
69 {
70 const TCollection_AsciiString& name = ExprIntrp_GetResult();
71 ExprIntrp_Recept.PushName(name);
72 }
73
ExprIntrp_EndDerivate()74 extern "C" void ExprIntrp_EndDerivate()
75 {
76 int degree;
77 degree = ExprIntrp_GetDegree();
78 ExprIntrp_Recept.PushValue(degree);
79 }
80
ExprIntrp_Derivation()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 throw ExprIntrp_SyntaxError();
91 }
92 ExprIntrp_Recept.Push(namexp);
93 }
94
ExprIntrp_DerivationValue()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
ExprIntrp_EndDerivation()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
ExprIntrp_StartDifferential()111 extern "C" void ExprIntrp_StartDifferential()
112 {
113 ExprIntrp_StartDerivate();
114 ExprIntrp_nbdiff = 0;
115 }
116
ExprIntrp_DiffDegreeVar()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 throw ExprIntrp_SyntaxError();
123 }
124 s++;
125 Standard_Integer rank = atoi(s);
126 ExprIntrp_Recept.PushValue(rank);
127 ExprIntrp_nbdiff++;
128 }
129
ExprIntrp_DiffVar()130 extern "C" void ExprIntrp_DiffVar()
131 {
132 ExprIntrp_Recept.PushValue(1);
133 ExprIntrp_DiffDegreeVar();
134 }
135
ExprIntrp_DiffDegree()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
ExprIntrp_VerDiffDegree()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 throw ExprIntrp_SyntaxError();
150 }
151 ExprIntrp_Recept.PushValue(deg);
152 }
153
ExprIntrp_EndDifferential()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 throw ExprIntrp_SyntaxError();
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 throw ExprIntrp_SyntaxError();
170 }
171 thediff = thefunc->Variable(rank);
172 thefunc = new Expr_FunctionDerivative(thefunc,thediff,degree);
173 }
174 ExprIntrp_Recept.PushFunction(thefunc);
175 }
176
ExprIntrp_EndDiffFunction()177 extern "C" void ExprIntrp_EndDiffFunction()
178 {
179 Handle(Expr_GeneralFunction) thefunc = ExprIntrp_Recept.PopFunction();
180 if (thefunc.IsNull()) {
181 throw ExprIntrp_SyntaxError();
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 throw ExprIntrp_SyntaxError();
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 throw ExprIntrp_SyntaxError();
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
ExprIntrp_StandardFunction(const TCollection_AsciiString & name,const Handle (Expr_GeneralExpression)& op)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
ExprIntrp_EndDerFunction()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 throw ExprIntrp_SyntaxError();
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 throw ExprIntrp_SyntaxError();
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 throw ExprIntrp_SyntaxError();
314 }
315 Standard_Integer nbargs = thefunc->NbOfVariables();
316 if (nbargs != 1) {
317 throw ExprIntrp_SyntaxError();
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
ExprIntrp_EndFunction()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 throw ExprIntrp_SyntaxError();
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 throw ExprIntrp_SyntaxError();
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 throw ExprIntrp_SyntaxError();
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
ExprIntrp_NextFuncArg()375 extern "C" void ExprIntrp_NextFuncArg()
376 {
377 ExprIntrp_nbargs++;
378 }
379
ExprIntrp_EndFuncArg()380 extern "C" void ExprIntrp_EndFuncArg()
381 {
382 ExprIntrp_nbargs++;
383 }
384
ExprIntrp_SumOperator()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
ExprIntrp_MinusOperator()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
ExprIntrp_DivideOperator()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
ExprIntrp_ExpOperator()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
ExprIntrp_ProductOperator()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
ExprIntrp_UnaryMinusOperator()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
ExprIntrp_UnaryPlusOperator()433 extern "C" void ExprIntrp_UnaryPlusOperator()
434 {
435 Handle(Expr_GeneralExpression) op = ExprIntrp_Recept.Pop();
436 ExprIntrp_Recept.Push(op);
437 }
438
ExprIntrp_VariableIdentifier()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
ExprIntrp_NumValue()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
ExprIntrp_AssignVariable()458 extern "C" void ExprIntrp_AssignVariable()
459 {
460 ExprIntrp_assname = ExprIntrp_GetResult();
461 }
462
ExprIntrp_Deassign()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 throw ExprIntrp_SyntaxError();
469 }
470 if (!nameexp->IsKind(STANDARD_TYPE(Expr_NamedUnknown))) {
471 throw ExprIntrp_SyntaxError();
472 }
473 Handle(Expr_NamedUnknown) var = Handle(Expr_NamedUnknown)::DownCast(nameexp);
474 var->Deassign();
475 }
476
ExprIntrp_DefineFunction()477 extern "C" void ExprIntrp_DefineFunction()
478 {
479 ExprIntrp_funcdefname = ExprIntrp_Recept.PopName();
480 ExprIntrp_Recept.PushValue(ExprIntrp_nbargs);
481 }
482
ExprIntrp_close()483 extern "C" void ExprIntrp_close()
484 {
485 ExprIntrp_stop_string();
486 }
487
ExprIntrperror(char * msg)488 extern "C" void ExprIntrperror(char* msg)
489 {
490 ExprIntrp_close();
491 throw ExprIntrp_SyntaxError(msg);
492 }
493
494
ExprIntrp_EndOfEqual()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
ExprIntrp_EndOfRelation()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
ExprIntrp_EndOfAssign()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 const Handle(Expr_NamedExpression)& aNamedExpr = namu; // to resolve ambiguity
536 ExprIntrp_Recept.Use(aNamedExpr);
537 }
538 else {
539 if (!namexp->IsKind(STANDARD_TYPE(Expr_NamedUnknown))) {
540 throw ExprIntrp_SyntaxError();
541 }
542 namu = Handle(Expr_NamedUnknown)::DownCast(namexp);
543 }
544 namu->Assign(ExprIntrp_Recept.Pop());
545 }
546
ExprIntrp_EndOfFuncDef()547 extern "C" void ExprIntrp_EndOfFuncDef()
548 {
549 Handle(Expr_GeneralExpression) theexp = ExprIntrp_Recept.Pop();
550 Standard_Integer nbargs = ExprIntrp_Recept.PopValue();
551 Expr_Array1OfNamedUnknown vars(1,nbargs);
552 Expr_Array1OfNamedUnknown internvars(1,nbargs);
553 Standard_Integer i;
554 for (i=nbargs; i > 0; i--) {
555 vars(i) = Handle(Expr_NamedUnknown)::DownCast(ExprIntrp_Recept.Pop());
556 internvars(i) = Handle(Expr_NamedUnknown)::DownCast(vars(i)->Copy());
557 }
558 theexp = Expr::CopyShare(theexp); // ATTENTION, PROTECTION BUG STACK
559 for (i=1; i<= nbargs; i++) {
560 if (theexp->Contains(vars(i))) {
561 theexp->Replace(vars(i),internvars(i));
562 }
563 else {
564 if (theexp == vars(i)) {
565 theexp = internvars(i);
566 }
567 }
568 }
569 Handle(Expr_NamedFunction) thefunc =
570 new Expr_NamedFunction(ExprIntrp_funcdefname,
571 theexp,
572 internvars);
573 ExprIntrp_Recept.Use(thefunc);
574 }
575
ExprIntrp_ConstantIdentifier()576 extern "C" void ExprIntrp_ConstantIdentifier()
577 {
578 const TCollection_AsciiString& thename = ExprIntrp_GetResult();
579 ExprIntrp_Recept.PushName(thename);
580 }
581
ExprIntrp_ConstantDefinition()582 extern "C" void ExprIntrp_ConstantDefinition()
583 {
584 TCollection_AsciiString name = ExprIntrp_Recept.PopName();
585 const TCollection_AsciiString& aStr = ExprIntrp_GetResult();
586 Standard_Real val = aStr.RealValue();
587 Handle(Expr_NamedConstant) theconst = new Expr_NamedConstant(name,val);
588 const Handle(Expr_NamedExpression) theexpr = theconst; // to resolve ambiguity
589 ExprIntrp_Recept.Use(theexpr);
590 ExprIntrp_Recept.Push(theconst);
591 }
592
593
ExprIntrp_Sumator()594 extern "C" void ExprIntrp_Sumator()
595 {
596 Handle(Expr_NumericValue) number = Handle(Expr_NumericValue)::DownCast(ExprIntrp_Recept.Pop());
597 Standard_Integer nb = (Standard_Integer) number->GetValue();
598 Handle(Expr_GeneralExpression) inc = ExprIntrp_Recept.Pop();
599 Handle(Expr_GeneralExpression) first = ExprIntrp_Recept.Pop();
600 Handle(Expr_NamedUnknown) var = Handle(Expr_NamedUnknown)::DownCast(ExprIntrp_Recept.Pop());
601 Handle(Expr_GeneralExpression) theexp = ExprIntrp_Recept.Pop();
602 Standard_Boolean thesame = (theexp == var);
603 Handle(Expr_GeneralExpression) cur = Expr::CopyShare(first);
604 Handle(Expr_GeneralExpression) res;
605 Handle(Expr_GeneralExpression) member;
606 Expr_SequenceOfGeneralExpression seq;
607 for (Standard_Integer i=1; i<= nb; i++) {
608 if (thesame) {
609 member = cur;
610 }
611 else {
612 member = Expr::CopyShare(theexp);
613 member->Replace(var,cur);
614 }
615 seq.Append(member);
616 cur = (cur + inc)->ShallowSimplified();
617 }
618 res = new Expr_Sum(seq);
619 ExprIntrp_Recept.Push(res->ShallowSimplified());
620 }
621
ExprIntrp_Productor()622 extern "C" void ExprIntrp_Productor()
623 {
624 Handle(Expr_NumericValue) number = Handle(Expr_NumericValue)::DownCast(ExprIntrp_Recept.Pop());
625 Standard_Integer nb = (Standard_Integer) number->GetValue();
626 Handle(Expr_GeneralExpression) inc = ExprIntrp_Recept.Pop();
627 Handle(Expr_GeneralExpression) first = ExprIntrp_Recept.Pop();
628 Handle(Expr_NamedUnknown) var = Handle(Expr_NamedUnknown)::DownCast(ExprIntrp_Recept.Pop());
629 Handle(Expr_GeneralExpression) theexp = ExprIntrp_Recept.Pop();
630 Standard_Boolean thesame = (theexp == var);
631 Handle(Expr_GeneralExpression) cur = Expr::CopyShare(first);
632 Handle(Expr_GeneralExpression) res;
633 Handle(Expr_GeneralExpression) member;
634 Expr_SequenceOfGeneralExpression seq;
635 for (Standard_Integer i=1; i<= nb; i++) {
636 if (thesame) {
637 member = cur;
638 }
639 else {
640 member = Expr::CopyShare(theexp);
641 member->Replace(var,cur);
642 }
643 seq.Append(member);
644 cur = (cur + inc)->ShallowSimplified();
645 }
646 res = new Expr_Product(seq);
647 ExprIntrp_Recept.Push(res->ShallowSimplified());
648 }
649