summaryrefslogtreecommitdiff
path: root/src/ExprIntrp/ExprIntrp_yaccintrf.cxx
blob: b3f06eb2786bd7c175c0cf948c928e204a5332ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
//static const char* sccsid = "@(#)ExprIntrp_yaccintrf.cxx	3.2 95/01/10"; // Do not delete this line. Used by sccs.

#ifdef HAVE_CONFIG_H
# include <oce-config.h>
#endif
#include <ExprIntrp_yaccintrf.hxx>
#include <ExprIntrp_yaccanal.hxx>
#include <Expr_GeneralExpression.hxx>
#include <Expr_NamedExpression.hxx>
#include <Expr_NamedUnknown.hxx>
#include <Expr_NamedConstant.hxx>
#include <Expr_NamedFunction.hxx>
#include <Expr_NumericValue.hxx>
#include <Expr_UnaryFunction.hxx>
#include <Expr_BinaryFunction.hxx>
#include <Expr_PolyFunction.hxx>
#include <Expr_Exponentiate.hxx>
#include <Expr_Absolute.hxx>
#include <Expr_ArcCosine.hxx>
#include <Expr_ArcSine.hxx>
#include <Expr_ArcTangent.hxx>
#include <Expr_ArgCosh.hxx>
#include <Expr_ArgSinh.hxx>
#include <Expr_ArgTanh.hxx>
#include <Expr_Cosh.hxx>
#include <Expr_Cosine.hxx>
#include <Expr_Exponential.hxx>
#include <Expr_LogOf10.hxx>
#include <Expr_LogOfe.hxx>
#include <Expr_Sign.hxx>
#include <Expr_Sine.hxx>
#include <Expr_Sinh.hxx>
#include <Expr_SquareRoot.hxx>
#include <Expr_Tangent.hxx>
#include <Expr_Tanh.hxx>
#include <Expr_Equal.hxx>
#include <Expr_SystemRelation.hxx>
#include <Expr_UnknownIterator.hxx>
#include <Expr_FunctionDerivative.hxx>
#include <Expr.hxx>                    // ATTENTION POUR PROTECTION BUG STACK

#include <Expr_SequenceOfGeneralExpression.hxx>
#include <Expr_Operators.hxx>
#include <ExprIntrp_SyntaxError.hxx>
#include <Expr_Array1OfNamedUnknown.hxx>
#include <Expr_Array1OfGeneralExpression.hxx>
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif

extern char yysbuf[];
extern char *yysptr;
static char ExprIntrp_assname[30];
TCollection_AsciiString ExprIntrp_funcdefname;
static Standard_Integer ExprIntrp_nbargs;
static Standard_Integer ExprIntrp_nbdiff;


extern "C" void ExprIntrp_StartFunction()
{
  char funcname[100];
  ExprIntrp_GetResult(funcname);
  TCollection_AsciiString name(funcname);
  ExprIntrp_Recept.PushName(name);
  ExprIntrp_nbargs = 0;
}

extern "C" void ExprIntrp_StartDerivate()
{
  char funcname[100];
  ExprIntrp_GetResult(funcname);
  TCollection_AsciiString name(funcname);
  ExprIntrp_Recept.PushName(name);
}

extern "C" void ExprIntrp_EndDerivate()
{
  int degree;
  degree = ExprIntrp_GetDegree();
  ExprIntrp_Recept.PushValue(degree);
}

extern "C" void ExprIntrp_Derivation()
{
  ExprIntrp_Recept.PushValue(1);
  char name[100];
    ExprIntrp_GetResult(name);
  TCollection_AsciiString thename(name);
  Handle(Expr_NamedExpression) namexp = ExprIntrp_Recept.GetNamed(thename);
  if (namexp.IsNull()) {
    namexp = new Expr_NamedUnknown(thename);
  }
  if (!namexp->IsKind(STANDARD_TYPE(Expr_NamedUnknown))) {
    ExprIntrp_SyntaxError::Raise();
  }
  ExprIntrp_Recept.Push(namexp);
}

extern "C" void ExprIntrp_DerivationValue()
{
  char num[30];
  ExprIntrp_GetResult(num);
  Standard_Integer degree = ExprIntrp_Recept.PopValue();
  degree = atoi(num);
  ExprIntrp_Recept.PushValue(degree);
}

extern "C" void ExprIntrp_EndDerivation()
{
  Standard_Integer degree = ExprIntrp_Recept.PopValue();
  Handle(Expr_NamedUnknown) var = Handle(Expr_NamedUnknown)::DownCast(ExprIntrp_Recept.Pop());
  Handle(Expr_GeneralExpression) exp = ExprIntrp_Recept.Pop();
  exp = exp->NDerivative(var,degree);
  ExprIntrp_Recept.Push(exp);
}

extern "C" void ExprIntrp_StartDifferential()
{
  ExprIntrp_StartDerivate();
  ExprIntrp_nbdiff = 0;
}

extern "C" void ExprIntrp_DiffDegreeVar()
{
  char name[100];
    ExprIntrp_GetResult(name);
#ifndef WNT 
  if (strncasecmp(name,"X",1)) {
#else
  if (  name[ 0 ] != 'X' && name[ 0 ] != 'x'  ) {
#endif  // WNT
    ExprIntrp_SyntaxError::Raise();
  }
  char* s = name;
  s++;
  Standard_Integer rank = atoi(s);
  ExprIntrp_Recept.PushValue(rank);
  ExprIntrp_nbdiff++;
}

extern "C" void ExprIntrp_DiffVar()
{
  ExprIntrp_Recept.PushValue(1);
  ExprIntrp_DiffDegreeVar();
}

extern "C" void ExprIntrp_DiffDegree()
{
  char name[100];
    ExprIntrp_GetResult(name);
  Standard_Integer deg = atoi(name);
  ExprIntrp_Recept.PushValue(deg);
}

extern "C" void ExprIntrp_VerDiffDegree()
{
  char name[100];
    ExprIntrp_GetResult(name);
  Standard_Integer deg = atoi(name);
  Standard_Integer thedeg = ExprIntrp_Recept.PopValue();
  if (deg != thedeg) {
    ExprIntrp_SyntaxError::Raise();
  }
  ExprIntrp_Recept.PushValue(deg);
}

extern "C" void ExprIntrp_EndDifferential()
{
  TCollection_AsciiString name = ExprIntrp_Recept.PopName();
  Handle(Expr_GeneralFunction) thefunc = ExprIntrp_Recept.GetFunction(name);
  if (thefunc.IsNull()) {
    ExprIntrp_SyntaxError::Raise();
  }
  Standard_Integer rank,degree;
  Handle(Expr_NamedUnknown) thediff;
  Standard_Integer nbvars = thefunc->NbOfVariables();

  for (Standard_Integer i=1; i<= ExprIntrp_nbdiff; i++) {
    rank = ExprIntrp_Recept.PopValue();
    degree = ExprIntrp_Recept.PopValue();
    if ((rank > nbvars) || (rank < 1)) {
      ExprIntrp_SyntaxError::Raise();
    }
    thediff = thefunc->Variable(rank);
    thefunc = new Expr_FunctionDerivative(thefunc,thediff,degree);
  }
  ExprIntrp_Recept.PushFunction(thefunc);
}

extern "C" void ExprIntrp_EndDiffFunction()
{
  Handle(Expr_GeneralFunction) thefunc = ExprIntrp_Recept.PopFunction();
  if (thefunc.IsNull()) {
    ExprIntrp_SyntaxError::Raise();
  }
  Standard_Integer nbargs = thefunc->NbOfVariables();
  if (nbargs == 1) {
    Handle(Expr_GeneralExpression) op = ExprIntrp_Recept.Pop();
    Handle(Expr_UnaryFunction) res = 
      new Expr_UnaryFunction(thefunc,op);
    ExprIntrp_Recept.Push(res);
  }
  else if (nbargs == 2) {
    Handle(Expr_GeneralExpression) arg2 = ExprIntrp_Recept.Pop();
    Handle(Expr_GeneralExpression) arg1 = ExprIntrp_Recept.Pop();
    if (arg1.IsNull()) {
      ExprIntrp_SyntaxError::Raise();
    }
    Handle(Expr_BinaryFunction) res =
      new Expr_BinaryFunction(thefunc,arg1,arg2);
    ExprIntrp_Recept.Push(res);
  }
  else {
    Expr_Array1OfGeneralExpression tabarg(1,nbargs);
    Handle(Expr_GeneralExpression) arg;
    for (Standard_Integer i = 1; i<= nbargs; i++) {
      arg = ExprIntrp_Recept.Pop();
      if (arg.IsNull()) {
	ExprIntrp_SyntaxError::Raise();
      }
      tabarg(nbargs-i+1) = arg;
    }
    Handle(Expr_PolyFunction) res = 
      new Expr_PolyFunction(thefunc,tabarg);
    ExprIntrp_Recept.Push(res);
  }
}
  
static Handle(Expr_GeneralExpression) ExprIntrp_StandardFunction(const TCollection_AsciiString& name, const Handle(Expr_GeneralExpression)& op)
{
// return standard functions equivalent corresponding to <name> 
// with given operand <op> if exists. Returns null value if not.
// <name> is not case sensitive

  Handle(Expr_GeneralExpression) res;
  if ((name == "abs") || (name == "Abs")) {
    res = new Expr_Absolute(op);
  }
  else if ((name == "acos") || (name == "ACos")) {
    res = new Expr_ArcCosine(op);
  }
  else if ((name == "asin") || (name == "ASin")) {
    res = new Expr_ArcSine(op);
  }
  else if ((name == "atan") || (name == "ATan")) {
    res = new Expr_ArcTangent(op);
  }
  else if ((name == "acosh") || (name == "ACosh")) {
    res = new Expr_ArgCosh(op);
  }
  else if ((name == "asinh") || (name == "ASinh")) {
    res = new Expr_ArgSinh(op);
  }
  else if ((name == "atanh") || (name == "ATanh")) {
    res = new Expr_ArgTanh(op);
  }
  else if ((name == "cosh") || (name == "Cosh")) {
    res = new Expr_Cosh(op);
  }
  else if ((name == "cos") || (name == "Cos")) {
    res = new Expr_Cosine(op);
  }
  else if ((name == "exp") || (name == "Exp")) {
    res = new Expr_Exponential(op);
  }
  else if (name == "log") {
    res = new Expr_LogOf10(op);
  }
  else if ((name == "Log") || (name == "Ln")) {
    res = new Expr_LogOfe(op);
  }
  else if ((name == "sign") || (name == "Sign")) {
    res = new Expr_Sign(op);
  }
  else if ((name == "sin") || (name == "Sin")) {
    res = new Expr_Sine(op);
  }
  else if ((name == "sinh") || (name == "Sinh")) {
    res = new Expr_Sinh(op);
  }
  else if ((name == "sqrt") || (name == "Sqrt")) {
    res = new Expr_SquareRoot(op);
  }
  else if ((name == "tan") || (name == "Tan")) {
    res = new Expr_Tangent(op);
  }
  else if ((name == "tanh") || (name == "Tanh")) {
    res = new Expr_Tanh(op);
  }
  return res;
}


extern "C" void ExprIntrp_EndDerFunction()
{
  TCollection_AsciiString name = ExprIntrp_Recept.PopName();
  Handle(Expr_GeneralExpression) op = ExprIntrp_Recept.Pop();
  Handle(Expr_GeneralExpression) resstand = ExprIntrp_StandardFunction(name,op);

  if (!resstand.IsNull()) {
    Handle(Expr_NamedUnknown) var;
    Expr_UnknownIterator rit(resstand);
    while (rit.More()) {
      if (!var.IsNull()) {
	ExprIntrp_SyntaxError::Raise();
      }
      else {
	var = rit.Value();
	if (var->IsAssigned()) {
	  var.Nullify();
	}
      }
      rit.Next();
    }
    if (var.IsNull()) {
      ExprIntrp_SyntaxError::Raise();
    }
    else {
      Handle(Expr_GeneralExpression) res = resstand->NDerivative(var,ExprIntrp_Recept.PopValue());
      ExprIntrp_Recept.Push(res);
    }
  }
  else {
    Handle(Expr_NamedFunction) thefunc = ExprIntrp_Recept.GetFunction(name);
    if (thefunc.IsNull()) {
      ExprIntrp_SyntaxError::Raise();
    }
    Standard_Integer nbargs = thefunc->NbOfVariables();
    if (nbargs != 1) {
      ExprIntrp_SyntaxError::Raise();
    }
    Handle(Expr_NamedUnknown) var = thefunc->Variable(1);
    Handle(Expr_FunctionDerivative) thefuncder = 
      new Expr_FunctionDerivative(thefunc,var,ExprIntrp_Recept.PopValue());
    Handle(Expr_UnaryFunction) res = 
      new Expr_UnaryFunction(thefuncder,op);
    ExprIntrp_Recept.Push(res);
  }
}
    
extern "C" void ExprIntrp_EndFunction()
{
  TCollection_AsciiString name = ExprIntrp_Recept.PopName();
  Handle(Expr_GeneralExpression) op = ExprIntrp_Recept.Pop();

  Handle(Expr_GeneralExpression) resstand = ExprIntrp_StandardFunction(name,op);
  if (!resstand.IsNull()) {
    ExprIntrp_Recept.Push(resstand->ShallowSimplified());
  }
  else {
    Handle(Expr_NamedFunction) thefunc = ExprIntrp_Recept.GetFunction(name);
    if (thefunc.IsNull()) {
      ExprIntrp_SyntaxError::Raise();
      }
    Standard_Integer nbargs = thefunc->NbOfVariables();
    if (nbargs == 1) {
      Handle(Expr_UnaryFunction) res = 
	new Expr_UnaryFunction(thefunc,op);
      ExprIntrp_Recept.Push(res);
    }
    else if (nbargs == 2) {
      Handle(Expr_GeneralExpression) arg1 = ExprIntrp_Recept.Pop();
      if (arg1.IsNull()) {
	ExprIntrp_SyntaxError::Raise();
      }
      Handle(Expr_BinaryFunction) res =
	new Expr_BinaryFunction(thefunc,arg1,op);
      ExprIntrp_Recept.Push(res);
    }
    else {
      Expr_Array1OfGeneralExpression tabarg(1,nbargs);
      Handle(Expr_GeneralExpression) arg;
      tabarg(nbargs) = op;
      for (Standard_Integer i = 1; i< nbargs; i++) {
	arg = ExprIntrp_Recept.Pop();
	if (arg.IsNull()) {
	  ExprIntrp_SyntaxError::Raise();
	}
	tabarg(nbargs-i) = arg;
      }
      Handle(Expr_PolyFunction) res = 
	new Expr_PolyFunction(thefunc,tabarg);
      ExprIntrp_Recept.Push(res);
    }
  }
}

extern "C" void ExprIntrp_NextFuncArg()
{
  ExprIntrp_nbargs++;
}

extern "C" void ExprIntrp_EndFuncArg()
{
  ExprIntrp_nbargs++;
}

extern "C" void ExprIntrp_SumOperator()
{
  Handle(Expr_GeneralExpression) op2 = ExprIntrp_Recept.Pop();
  Handle(Expr_GeneralExpression) op1 = ExprIntrp_Recept.Pop();
  Handle(Expr_Sum) sres = op1 + op2;
  Handle(Expr_GeneralExpression) res = sres->ShallowSimplified();
  ExprIntrp_Recept.Push(res);
}

extern "C" void ExprIntrp_MinusOperator()
{
  Handle(Expr_GeneralExpression) op2 = ExprIntrp_Recept.Pop();
  Handle(Expr_GeneralExpression) op1 = ExprIntrp_Recept.Pop();
  Handle(Expr_Difference) res = op1 - op2;
  ExprIntrp_Recept.Push(res->ShallowSimplified());
}

extern "C" void ExprIntrp_DivideOperator()
{
  Handle(Expr_GeneralExpression) op2 = ExprIntrp_Recept.Pop();
  Handle(Expr_GeneralExpression) op1 = ExprIntrp_Recept.Pop();
  Handle(Expr_Division) res = op1 / op2;
  ExprIntrp_Recept.Push(res->ShallowSimplified());
}

extern "C" void ExprIntrp_ExpOperator()
{
  Handle(Expr_GeneralExpression) op2 = ExprIntrp_Recept.Pop();
  Handle(Expr_GeneralExpression) op1 = ExprIntrp_Recept.Pop();
  Handle(Expr_Exponentiate) res = new Expr_Exponentiate(op1,op2);
  ExprIntrp_Recept.Push(res->ShallowSimplified());
}

extern "C" void ExprIntrp_ProductOperator()
{
  Handle(Expr_GeneralExpression) op2 = ExprIntrp_Recept.Pop();
  Handle(Expr_GeneralExpression) op1 = ExprIntrp_Recept.Pop();
  Handle(Expr_Product) res = op1 * op2;
  ExprIntrp_Recept.Push(res->ShallowSimplified());
}

extern "C" void ExprIntrp_UnaryMinusOperator()
{
  Handle(Expr_GeneralExpression) op = ExprIntrp_Recept.Pop();
  Handle(Expr_UnaryMinus) res = new Expr_UnaryMinus(op);
  ExprIntrp_Recept.Push(res->ShallowSimplified());
}

extern "C" void ExprIntrp_VariableIdentifier()
{
  char name[30];
  ExprIntrp_GetResult(name);
  TCollection_AsciiString thename(name);
  Handle(Expr_NamedExpression) nameexp = ExprIntrp_Recept.GetNamed(thename);
  if (nameexp.IsNull()) {
    nameexp = new Expr_NamedUnknown(thename);
    ExprIntrp_Recept.Use(nameexp);
  }
  ExprIntrp_Recept.Push(nameexp);
}

extern "C" void ExprIntrp_NumValue()
{
  char num[30];
  ExprIntrp_GetResult(num);
  Standard_Real value = atof(num);
  Handle(Expr_NumericValue) nval = new Expr_NumericValue(value);
  ExprIntrp_Recept.Push(nval);
}

extern "C" void ExprIntrp_AssignVariable()
{
  ExprIntrp_GetResult(ExprIntrp_assname);
}

extern "C" void ExprIntrp_Deassign()
{
  char name[100];
  ExprIntrp_GetResult(name);
  TCollection_AsciiString thename(name);
  Handle(Expr_NamedExpression) nameexp = ExprIntrp_Recept.GetNamed(thename);
  if (nameexp.IsNull()) {
    ExprIntrp_SyntaxError::Raise();
  }
  if (!nameexp->IsKind(STANDARD_TYPE(Expr_NamedUnknown))) {
    ExprIntrp_SyntaxError::Raise();
  }
  Handle(Expr_NamedUnknown) var = Handle(Expr_NamedUnknown)::DownCast(nameexp);
  var->Deassign();
}

extern "C" void ExprIntrp_DefineFunction()
{
  ExprIntrp_funcdefname = ExprIntrp_Recept.PopName();
  ExprIntrp_Recept.PushValue(ExprIntrp_nbargs);
}

extern "C" void ExprIntrp_close()
{
  ExprIntrp_stop_string();
}

extern "C" void ExprIntrperror(char* msg)
{
  ExprIntrp_close();
  ExprIntrp_SyntaxError::Raise(msg);
}


extern "C" void ExprIntrp_EndOfEqual()
{
  Handle(Expr_GeneralExpression) memb2 = ExprIntrp_Recept.Pop();
  Handle(Expr_GeneralExpression) memb1 = ExprIntrp_Recept.Pop();
  Handle(Expr_Equal) res = new Expr_Equal(memb1,memb2);
  ExprIntrp_Recept.PushRelation(res);
}

extern "C" void ExprIntrp_EndOfRelation()
{
  Handle(Expr_SystemRelation) sys;
  Handle(Expr_GeneralRelation) currel;
  Handle(Expr_GeneralRelation) oldrel;
  while (!ExprIntrp_Recept.IsRelStackEmpty()) {
    currel = ExprIntrp_Recept.PopRelation();
    if (!sys.IsNull()) {
      sys->Add(currel);
    }
    else if (!oldrel.IsNull()) {
      sys = new Expr_SystemRelation(oldrel);
      sys->Add(currel);
    }
    else {
      oldrel = currel;
    }
  }
  if (sys.IsNull()) {
    ExprIntrp_Recept.PushRelation(currel);
  }
  else {
    ExprIntrp_Recept.PushRelation(sys);
  }
}

extern "C" void ExprIntrp_EndOfAssign()
{
  Handle(Expr_NamedExpression) namexp = ExprIntrp_Recept.GetNamed(ExprIntrp_assname);
  Handle(Expr_NamedUnknown) namu;
  if (namexp.IsNull()) {
    namu = new Expr_NamedUnknown(ExprIntrp_assname);
    ExprIntrp_Recept.Use(namu);
  }
  else {
    if (!namexp->IsKind(STANDARD_TYPE(Expr_NamedUnknown))) {
      ExprIntrp_SyntaxError::Raise();
    }
    namu = Handle(Expr_NamedUnknown)::DownCast(namexp);
  }
  namu->Assign(ExprIntrp_Recept.Pop());
}

extern "C" void ExprIntrp_EndOfFuncDef()
{
  Handle(Expr_GeneralExpression) theexp = ExprIntrp_Recept.Pop();
  Standard_Integer nbargs = ExprIntrp_Recept.PopValue();
  Expr_Array1OfNamedUnknown vars(1,nbargs);
  Expr_Array1OfNamedUnknown internvars(1,nbargs);
  Standard_Integer i;
  for (i=nbargs; i > 0; i--) {
    vars(i) = Handle(Expr_NamedUnknown)::DownCast(ExprIntrp_Recept.Pop());
    internvars(i) = Handle(Expr_NamedUnknown)::DownCast(vars(i)->Copy());
  }
  theexp = Expr::CopyShare(theexp);  // ATTENTION, PROTECTION BUG STACK
  for (i=1; i<= nbargs; i++) {
    if (theexp->Contains(vars(i))) {
      theexp->Replace(vars(i),internvars(i));
    }
    else {
      if (theexp == vars(i)) {
	theexp = internvars(i);
      }
    }
  }
  Handle(Expr_NamedFunction) thefunc = 
    new Expr_NamedFunction(ExprIntrp_funcdefname,
			   theexp,
			   internvars);
  ExprIntrp_Recept.Use(thefunc);
}

extern "C" void ExprIntrp_ConstantIdentifier()
{
  char name[100];
    ExprIntrp_GetResult(name);
  TCollection_AsciiString thename(name);
  ExprIntrp_Recept.PushName(thename);
}

extern "C" void ExprIntrp_ConstantDefinition()
{
  TCollection_AsciiString name = ExprIntrp_Recept.PopName();
  char num[30];
  ExprIntrp_GetResult(num);
  Standard_Real val = atof(num);
  Handle(Expr_NamedConstant) theconst = new Expr_NamedConstant(name,val);
  ExprIntrp_Recept.Use(theconst);
  ExprIntrp_Recept.Push(theconst);
}


extern "C" void ExprIntrp_Sumator()
{
  Handle(Expr_NumericValue) number = Handle(Expr_NumericValue)::DownCast(ExprIntrp_Recept.Pop());
  Standard_Integer nb = (Standard_Integer) number->GetValue();
  Handle(Expr_GeneralExpression) inc = ExprIntrp_Recept.Pop();
  Handle(Expr_GeneralExpression) first = ExprIntrp_Recept.Pop();
  Handle(Expr_NamedUnknown) var = Handle(Expr_NamedUnknown)::DownCast(ExprIntrp_Recept.Pop());
  Handle(Expr_GeneralExpression) theexp = ExprIntrp_Recept.Pop();
  Standard_Boolean thesame = (theexp == var);
  Handle(Expr_GeneralExpression) cur = Expr::CopyShare(first);
  Handle(Expr_GeneralExpression) res;
  Handle(Expr_GeneralExpression) member;
  Expr_SequenceOfGeneralExpression seq;
  for (Standard_Integer i=1; i<= nb; i++) {
    if (thesame) {
      member = cur;
    }
    else {
      member = Expr::CopyShare(theexp);
      member->Replace(var,cur);
    }
    seq.Append(member);
    cur = (cur + inc)->ShallowSimplified();
  }
  res = new Expr_Sum(seq);
  ExprIntrp_Recept.Push(res->ShallowSimplified());
}

extern "C" void ExprIntrp_Productor()
{
  Handle(Expr_NumericValue) number = Handle(Expr_NumericValue)::DownCast(ExprIntrp_Recept.Pop());
  Standard_Integer nb = (Standard_Integer) number->GetValue();
  Handle(Expr_GeneralExpression) inc = ExprIntrp_Recept.Pop();
  Handle(Expr_GeneralExpression) first = ExprIntrp_Recept.Pop();
  Handle(Expr_NamedUnknown) var = Handle(Expr_NamedUnknown)::DownCast(ExprIntrp_Recept.Pop());
  Handle(Expr_GeneralExpression) theexp = ExprIntrp_Recept.Pop();
  Standard_Boolean thesame = (theexp == var);
  Handle(Expr_GeneralExpression) cur = Expr::CopyShare(first);
  Handle(Expr_GeneralExpression) res;
  Handle(Expr_GeneralExpression) member;
  Expr_SequenceOfGeneralExpression seq;
  for (Standard_Integer i=1; i<= nb; i++) {
    if (thesame) {
      member = cur;
    }
    else {
      member = Expr::CopyShare(theexp);
      member->Replace(var,cur);
    }
    seq.Append(member);
    cur = (cur + inc)->ShallowSimplified();
  }
  res = new Expr_Product(seq);
  ExprIntrp_Recept.Push(res->ShallowSimplified());
}