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