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