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> |
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> |
2a54ebbf |
49 | #include <Expr.hxx> |
7fd59977 |
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> |
2a54ebbf |
55 | |
56 | static TCollection_AsciiString ExprIntrp_assname; |
57 | static TCollection_AsciiString ExprIntrp_funcdefname; |
7fd59977 |
58 | static Standard_Integer ExprIntrp_nbargs; |
59 | static Standard_Integer ExprIntrp_nbdiff; |
60 | |
7fd59977 |
61 | extern "C" void ExprIntrp_StartFunction() |
62 | { |
2a54ebbf |
63 | const TCollection_AsciiString& name = ExprIntrp_GetResult(); |
7fd59977 |
64 | ExprIntrp_Recept.PushName(name); |
65 | ExprIntrp_nbargs = 0; |
66 | } |
67 | |
68 | extern "C" void ExprIntrp_StartDerivate() |
69 | { |
2a54ebbf |
70 | const TCollection_AsciiString& name = ExprIntrp_GetResult(); |
7fd59977 |
71 | ExprIntrp_Recept.PushName(name); |
72 | } |
73 | |
74 | extern "C" void ExprIntrp_EndDerivate() |
75 | { |
76 | int degree; |
77 | degree = ExprIntrp_GetDegree(); |
78 | ExprIntrp_Recept.PushValue(degree); |
79 | } |
80 | |
81 | extern "C" void ExprIntrp_Derivation() |
82 | { |
83 | ExprIntrp_Recept.PushValue(1); |
2a54ebbf |
84 | const TCollection_AsciiString& thename = ExprIntrp_GetResult(); |
7fd59977 |
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 | ExprIntrp_SyntaxError::Raise(); |
91 | } |
92 | ExprIntrp_Recept.Push(namexp); |
93 | } |
94 | |
95 | extern "C" void ExprIntrp_DerivationValue() |
96 | { |
2a54ebbf |
97 | const TCollection_AsciiString& aStr = ExprIntrp_GetResult(); |
98 | ExprIntrp_Recept.PopValue(); |
99 | ExprIntrp_Recept.PushValue(aStr.IntegerValue()); |
7fd59977 |
100 | } |
101 | |
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 | |
111 | extern "C" void ExprIntrp_StartDifferential() |
112 | { |
113 | ExprIntrp_StartDerivate(); |
114 | ExprIntrp_nbdiff = 0; |
115 | } |
116 | |
117 | extern "C" void ExprIntrp_DiffDegreeVar() |
118 | { |
2a54ebbf |
119 | const TCollection_AsciiString& aStr = ExprIntrp_GetResult(); |
120 | const char* s = aStr.ToCString(); |
121 | if ( *s != 'X' && *s != 'x' ) { |
7fd59977 |
122 | ExprIntrp_SyntaxError::Raise(); |
123 | } |
7fd59977 |
124 | s++; |
125 | Standard_Integer rank = atoi(s); |
126 | ExprIntrp_Recept.PushValue(rank); |
127 | ExprIntrp_nbdiff++; |
128 | } |
129 | |
130 | extern "C" void ExprIntrp_DiffVar() |
131 | { |
132 | ExprIntrp_Recept.PushValue(1); |
133 | ExprIntrp_DiffDegreeVar(); |
134 | } |
135 | |
136 | extern "C" void ExprIntrp_DiffDegree() |
137 | { |
2a54ebbf |
138 | const TCollection_AsciiString& aStr = ExprIntrp_GetResult(); |
139 | Standard_Integer deg = aStr.IntegerValue(); |
7fd59977 |
140 | ExprIntrp_Recept.PushValue(deg); |
141 | } |
142 | |
143 | extern "C" void ExprIntrp_VerDiffDegree() |
144 | { |
2a54ebbf |
145 | const TCollection_AsciiString& aStr = ExprIntrp_GetResult(); |
146 | Standard_Integer deg = aStr.IntegerValue(); |
7fd59977 |
147 | Standard_Integer thedeg = ExprIntrp_Recept.PopValue(); |
148 | if (deg != thedeg) { |
149 | ExprIntrp_SyntaxError::Raise(); |
150 | } |
151 | ExprIntrp_Recept.PushValue(deg); |
152 | } |
153 | |
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 | ExprIntrp_SyntaxError::Raise(); |
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 | ExprIntrp_SyntaxError::Raise(); |
170 | } |
171 | thediff = thefunc->Variable(rank); |
172 | thefunc = new Expr_FunctionDerivative(thefunc,thediff,degree); |
173 | } |
174 | ExprIntrp_Recept.PushFunction(thefunc); |
175 | } |
176 | |
177 | extern "C" void ExprIntrp_EndDiffFunction() |
178 | { |
179 | Handle(Expr_GeneralFunction) thefunc = ExprIntrp_Recept.PopFunction(); |
180 | if (thefunc.IsNull()) { |
181 | ExprIntrp_SyntaxError::Raise(); |
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 | ExprIntrp_SyntaxError::Raise(); |
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 | ExprIntrp_SyntaxError::Raise(); |
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 | |
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 | |
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 | ExprIntrp_SyntaxError::Raise(); |
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 | ExprIntrp_SyntaxError::Raise(); |
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 | ExprIntrp_SyntaxError::Raise(); |
314 | } |
315 | Standard_Integer nbargs = thefunc->NbOfVariables(); |
316 | if (nbargs != 1) { |
317 | ExprIntrp_SyntaxError::Raise(); |
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 | |
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 | ExprIntrp_SyntaxError::Raise(); |
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 | ExprIntrp_SyntaxError::Raise(); |
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 | ExprIntrp_SyntaxError::Raise(); |
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 | |
375 | extern "C" void ExprIntrp_NextFuncArg() |
376 | { |
377 | ExprIntrp_nbargs++; |
378 | } |
379 | |
380 | extern "C" void ExprIntrp_EndFuncArg() |
381 | { |
382 | ExprIntrp_nbargs++; |
383 | } |
384 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
433 | extern "C" void ExprIntrp_VariableIdentifier() |
434 | { |
2a54ebbf |
435 | const TCollection_AsciiString& thename = ExprIntrp_GetResult(); |
7fd59977 |
436 | Handle(Expr_NamedExpression) nameexp = ExprIntrp_Recept.GetNamed(thename); |
437 | if (nameexp.IsNull()) { |
438 | nameexp = new Expr_NamedUnknown(thename); |
439 | ExprIntrp_Recept.Use(nameexp); |
440 | } |
441 | ExprIntrp_Recept.Push(nameexp); |
442 | } |
443 | |
444 | extern "C" void ExprIntrp_NumValue() |
445 | { |
2a54ebbf |
446 | const TCollection_AsciiString& aStr = ExprIntrp_GetResult(); |
447 | Standard_Real value = aStr.RealValue(); |
7fd59977 |
448 | Handle(Expr_NumericValue) nval = new Expr_NumericValue(value); |
449 | ExprIntrp_Recept.Push(nval); |
450 | } |
451 | |
452 | extern "C" void ExprIntrp_AssignVariable() |
453 | { |
2a54ebbf |
454 | ExprIntrp_assname = ExprIntrp_GetResult(); |
7fd59977 |
455 | } |
456 | |
457 | extern "C" void ExprIntrp_Deassign() |
458 | { |
2a54ebbf |
459 | const TCollection_AsciiString& thename = ExprIntrp_GetResult(); |
7fd59977 |
460 | Handle(Expr_NamedExpression) nameexp = ExprIntrp_Recept.GetNamed(thename); |
461 | if (nameexp.IsNull()) { |
462 | ExprIntrp_SyntaxError::Raise(); |
463 | } |
464 | if (!nameexp->IsKind(STANDARD_TYPE(Expr_NamedUnknown))) { |
465 | ExprIntrp_SyntaxError::Raise(); |
466 | } |
467 | Handle(Expr_NamedUnknown) var = Handle(Expr_NamedUnknown)::DownCast(nameexp); |
468 | var->Deassign(); |
469 | } |
470 | |
471 | extern "C" void ExprIntrp_DefineFunction() |
472 | { |
473 | ExprIntrp_funcdefname = ExprIntrp_Recept.PopName(); |
474 | ExprIntrp_Recept.PushValue(ExprIntrp_nbargs); |
475 | } |
476 | |
477 | extern "C" void ExprIntrp_close() |
478 | { |
479 | ExprIntrp_stop_string(); |
480 | } |
481 | |
482 | extern "C" void ExprIntrperror(char* msg) |
483 | { |
484 | ExprIntrp_close(); |
485 | ExprIntrp_SyntaxError::Raise(msg); |
486 | } |
487 | |
488 | |
489 | extern "C" void ExprIntrp_EndOfEqual() |
490 | { |
491 | Handle(Expr_GeneralExpression) memb2 = ExprIntrp_Recept.Pop(); |
492 | Handle(Expr_GeneralExpression) memb1 = ExprIntrp_Recept.Pop(); |
493 | Handle(Expr_Equal) res = new Expr_Equal(memb1,memb2); |
494 | ExprIntrp_Recept.PushRelation(res); |
495 | } |
496 | |
497 | extern "C" void ExprIntrp_EndOfRelation() |
498 | { |
499 | Handle(Expr_SystemRelation) sys; |
500 | Handle(Expr_GeneralRelation) currel; |
501 | Handle(Expr_GeneralRelation) oldrel; |
502 | while (!ExprIntrp_Recept.IsRelStackEmpty()) { |
503 | currel = ExprIntrp_Recept.PopRelation(); |
504 | if (!sys.IsNull()) { |
505 | sys->Add(currel); |
506 | } |
507 | else if (!oldrel.IsNull()) { |
508 | sys = new Expr_SystemRelation(oldrel); |
509 | sys->Add(currel); |
510 | } |
511 | else { |
512 | oldrel = currel; |
513 | } |
514 | } |
515 | if (sys.IsNull()) { |
516 | ExprIntrp_Recept.PushRelation(currel); |
517 | } |
518 | else { |
519 | ExprIntrp_Recept.PushRelation(sys); |
520 | } |
521 | } |
522 | |
523 | extern "C" void ExprIntrp_EndOfAssign() |
524 | { |
525 | Handle(Expr_NamedExpression) namexp = ExprIntrp_Recept.GetNamed(ExprIntrp_assname); |
526 | Handle(Expr_NamedUnknown) namu; |
527 | if (namexp.IsNull()) { |
528 | namu = new Expr_NamedUnknown(ExprIntrp_assname); |
529 | ExprIntrp_Recept.Use(namu); |
530 | } |
531 | else { |
532 | if (!namexp->IsKind(STANDARD_TYPE(Expr_NamedUnknown))) { |
533 | ExprIntrp_SyntaxError::Raise(); |
534 | } |
535 | namu = Handle(Expr_NamedUnknown)::DownCast(namexp); |
536 | } |
537 | namu->Assign(ExprIntrp_Recept.Pop()); |
538 | } |
539 | |
540 | extern "C" void ExprIntrp_EndOfFuncDef() |
541 | { |
542 | Handle(Expr_GeneralExpression) theexp = ExprIntrp_Recept.Pop(); |
543 | Standard_Integer nbargs = ExprIntrp_Recept.PopValue(); |
544 | Expr_Array1OfNamedUnknown vars(1,nbargs); |
545 | Expr_Array1OfNamedUnknown internvars(1,nbargs); |
546 | Standard_Integer i; |
547 | for (i=nbargs; i > 0; i--) { |
548 | vars(i) = Handle(Expr_NamedUnknown)::DownCast(ExprIntrp_Recept.Pop()); |
549 | internvars(i) = Handle(Expr_NamedUnknown)::DownCast(vars(i)->Copy()); |
550 | } |
551 | theexp = Expr::CopyShare(theexp); // ATTENTION, PROTECTION BUG STACK |
552 | for (i=1; i<= nbargs; i++) { |
553 | if (theexp->Contains(vars(i))) { |
554 | theexp->Replace(vars(i),internvars(i)); |
555 | } |
556 | else { |
557 | if (theexp == vars(i)) { |
558 | theexp = internvars(i); |
559 | } |
560 | } |
561 | } |
562 | Handle(Expr_NamedFunction) thefunc = |
563 | new Expr_NamedFunction(ExprIntrp_funcdefname, |
564 | theexp, |
565 | internvars); |
566 | ExprIntrp_Recept.Use(thefunc); |
567 | } |
568 | |
569 | extern "C" void ExprIntrp_ConstantIdentifier() |
570 | { |
2a54ebbf |
571 | const TCollection_AsciiString& thename = ExprIntrp_GetResult(); |
7fd59977 |
572 | ExprIntrp_Recept.PushName(thename); |
573 | } |
574 | |
575 | extern "C" void ExprIntrp_ConstantDefinition() |
576 | { |
577 | TCollection_AsciiString name = ExprIntrp_Recept.PopName(); |
2a54ebbf |
578 | const TCollection_AsciiString& aStr = ExprIntrp_GetResult(); |
579 | Standard_Real val = aStr.RealValue(); |
7fd59977 |
580 | Handle(Expr_NamedConstant) theconst = new Expr_NamedConstant(name,val); |
581 | ExprIntrp_Recept.Use(theconst); |
582 | ExprIntrp_Recept.Push(theconst); |
583 | } |
584 | |
585 | |
586 | extern "C" void ExprIntrp_Sumator() |
587 | { |
588 | Handle(Expr_NumericValue) number = Handle(Expr_NumericValue)::DownCast(ExprIntrp_Recept.Pop()); |
589 | Standard_Integer nb = (Standard_Integer) number->GetValue(); |
590 | Handle(Expr_GeneralExpression) inc = ExprIntrp_Recept.Pop(); |
591 | Handle(Expr_GeneralExpression) first = ExprIntrp_Recept.Pop(); |
592 | Handle(Expr_NamedUnknown) var = Handle(Expr_NamedUnknown)::DownCast(ExprIntrp_Recept.Pop()); |
593 | Handle(Expr_GeneralExpression) theexp = ExprIntrp_Recept.Pop(); |
594 | Standard_Boolean thesame = (theexp == var); |
595 | Handle(Expr_GeneralExpression) cur = Expr::CopyShare(first); |
596 | Handle(Expr_GeneralExpression) res; |
597 | Handle(Expr_GeneralExpression) member; |
598 | Expr_SequenceOfGeneralExpression seq; |
599 | for (Standard_Integer i=1; i<= nb; i++) { |
600 | if (thesame) { |
601 | member = cur; |
602 | } |
603 | else { |
604 | member = Expr::CopyShare(theexp); |
605 | member->Replace(var,cur); |
606 | } |
607 | seq.Append(member); |
608 | cur = (cur + inc)->ShallowSimplified(); |
609 | } |
610 | res = new Expr_Sum(seq); |
611 | ExprIntrp_Recept.Push(res->ShallowSimplified()); |
612 | } |
613 | |
614 | extern "C" void ExprIntrp_Productor() |
615 | { |
616 | Handle(Expr_NumericValue) number = Handle(Expr_NumericValue)::DownCast(ExprIntrp_Recept.Pop()); |
617 | Standard_Integer nb = (Standard_Integer) number->GetValue(); |
618 | Handle(Expr_GeneralExpression) inc = ExprIntrp_Recept.Pop(); |
619 | Handle(Expr_GeneralExpression) first = ExprIntrp_Recept.Pop(); |
620 | Handle(Expr_NamedUnknown) var = Handle(Expr_NamedUnknown)::DownCast(ExprIntrp_Recept.Pop()); |
621 | Handle(Expr_GeneralExpression) theexp = ExprIntrp_Recept.Pop(); |
622 | Standard_Boolean thesame = (theexp == var); |
623 | Handle(Expr_GeneralExpression) cur = Expr::CopyShare(first); |
624 | Handle(Expr_GeneralExpression) res; |
625 | Handle(Expr_GeneralExpression) member; |
626 | Expr_SequenceOfGeneralExpression seq; |
627 | for (Standard_Integer i=1; i<= nb; i++) { |
628 | if (thesame) { |
629 | member = cur; |
630 | } |
631 | else { |
632 | member = Expr::CopyShare(theexp); |
633 | member->Replace(var,cur); |
634 | } |
635 | seq.Append(member); |
636 | cur = (cur + inc)->ShallowSimplified(); |
637 | } |
638 | res = new Expr_Product(seq); |
639 | ExprIntrp_Recept.Push(res->ShallowSimplified()); |
640 | } |