readcuiksystem.y
Go to the documentation of this file.
1 %{
3 #include "cuiksystem.h"
4 #include "readcuiksystemtypes.h"
5 
6 #include "boolean.h"
7 #include "error.h"
8 #include "interval.h"
9 #include "monomial.h"
10 #include "equations.h"
11 #include "equation.h"
12 #include "mequation.h"
13 #include "variable.h"
14 #include "variable_set.h"
15 #include "defines.h"
16 #include "parameters.h"
17 
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <string.h>
21 #include <math.h>
22 
23  /*Lex and Yacc variables*/
24  extern FILE *Readcuiksystemin;
25 
26  /*Lex and Yacc functions*/
27  int Readcuiksystemlex(void);
28 
29  /*Our own variables*/
30  extern unsigned int RCSline; /*line number currently processed (incremented by the LEX processor)*/
31 
32  double rcs_sgn=1.0; /* sign for the monomials added to an equation. */
33 
34  Tparameters *rcs_parameters=NULL;
35 
36  /*Global pointer to allow the different parts of the parser to acces the equations being initialized*/
37  TCuikSystem *rcs_cuiksystem=NULL;
38 
39  Tequation rcs_equation;
40  TMequation rcs_mequation;
41  Tmonomial rcs_monomial;
42 
43  double **rcs_point;
44 
45  double rcs_vect[3];
46 
47  unsigned int rcs_eq_type=SYSTEM_EQ;
48  unsigned int rcs_var_type=SYSTEM_VAR;
49 
50  unsigned int rcs_topology;
51 
52  Tconstants *rcs_constants;
53 %}
54 
55 %union
56 {
57  char *id;
58  int int_number;
59  double real_number;
60  Texpr expr;
61 }
62 
63 %start problem
64 
65 %token _CONSTANTS _SYSTEM_VARS _SECONDARY_VARS _DUMMY_VARS _CARTESIAN_VARS _SYSTEM_EQS _COORD_EQS _DUMMY_EQS _SEARCH _DEPTH _BREADTH _FIRST _MIN _EQU _LEQ _GEQ _ASSIGN _INF _PI _SIN _COS _TAN _COT _ACOS _ASIN _ATAN _ATAN2 _EXP _PWP _SQRT _ABS _PARAMETER _PRINT _T _TX _TY _TZ _TV _PA _RX _RY _RZ _ID _DRX _DRY _DRZ _DPA_U _DPA_V _DDRX _DDRY _DDRZ _DDPA_UU _DDPA_UV _DDPA_VV _INV _EQUAL _NO_EQUAL _LESS _GREATER
66 
67 %token <id> _IDENTIFIER
68 %token <int_number> _INTEGER
69 %token <real_number> _REAL
70 
71 %type <expr> expr
72 %type <int_number> cmp
73 %type <int_number> power
74 %type <int_number> trans_type
75 %type <int_number> patch_type
76 %type <int_number> opt_invert
77 
78 %left _MIN_PRECEDENCE
79 %left _EQUAL _NOT_EQUAL _LEQ _GEQ _LESS _GREATER
80 %left '+' '-'
81 %left '*' '/'
82 %left '^'
83 %right _MAX_PRECEDENCE
84 
85 %%
86 
87 problem: ct_defs var_defs system_eqs coord_eqs dummy_eqs search
88  ;
89 
90 ct_defs : _CONSTANTS ct_list
91  |
92  ;
93 
94 ct_list : ct_definition ct_list
95  |
96  ;
97 
98 ct_definition: _IDENTIFIER _ASSIGN expr
99  {
100  if (GetConstantWithName($1,rcs_constants)!=NO_UINT)
101  {
102  char s[200];
103 
104  sprintf(s,"Duplicated constant %s",$1);
106  }
107 
108  if ($3.id!=NULL)
109  ReadcuiksystemSemanticError("Constant assigned to a variable");
110 
111  AddConstant($1,$3.value,rcs_constants);
112  free($1);
113  }
114  ;
115 
116 
117 expr : '+' expr %prec _MAX_PRECEDENCE
118  {
119  if ($2.id!=NULL)
120  ReadcuiksystemSemanticError("No operation is allowed with variables");
121 
122  $$.id=NULL;
123  $$.value=$2.value;
124  }
125  | '-' expr %prec _MAX_PRECEDENCE
126  {
127  if ($2.id!=NULL)
128  ReadcuiksystemSemanticError("No operation is allowed with variables");
129 
130  $$.id=NULL;
131  $$.value=-$2.value;
132  }
133  | expr '+' expr
134  {
135  if (($1.id!=NULL)||($3.id!=NULL))
136  ReadcuiksystemSemanticError("No operation is allowed with variables");
137 
138  $$.id=NULL;
139  $$.value=$1.value+$3.value;
140  }
141  | expr '-' expr
142  {
143  if (($1.id!=NULL)||($3.id!=NULL))
144  ReadcuiksystemSemanticError("No operation is allowed with variables");
145 
146  $$.id=NULL;
147  $$.value=$1.value-$3.value;
148  }
149  | expr '*' expr
150  {
151  if (($1.id!=NULL)||($3.id!=NULL))
152  ReadcuiksystemSemanticError("No operation is allowed with variables");
153 
154  $$.id=NULL;
155  $$.value=$1.value*$3.value;
156  }
157  | expr '^' expr
158  {
159  if (($1.id!=NULL)||($3.id!=NULL))
160  ReadcuiksystemSemanticError("No operation is allowed with variables");
161 
162  $$.id=NULL;
163  $$.value=pow($1.value,$3.value);
164  }
165  | expr '/' expr
166  {
167  if (($1.id!=NULL)||($3.id!=NULL))
168  ReadcuiksystemSemanticError("No operation is allowed with variables");
169 
170  if ($3.value==0.0)
171  ReadcuiksystemSemanticError("Division by zero");
172 
173  $$.id=NULL;
174  $$.value=$1.value/$3.value;
175  }
176  | '(' expr ')'
177  {
178  if ($2.id!=NULL)
179  ReadcuiksystemSemanticError("No operation is allowed with variables");
180 
181  $$.id=NULL;
182  $$.value=$2.value;
183  }
184  | '(' expr '?' expr ':' expr ')'
185  {
186  if (($2.id!=NULL)||($4.id!=NULL)||($6.id!=NULL))
187  ReadcuiksystemSemanticError("No operation is allowed with variables");
188 
189  $$.id=NULL;
190  if ($2.value)
191  $$.value=$4.value;
192  else
193  $$.value=$6.value;
194  }
195  | expr _EQUAL expr
196  {
197  if (($1.id!=NULL)||($3.id!=NULL))
198  ReadcuiksystemSemanticError("No operation is allowed with variables");
199 
200  $$.id=NULL;
201  $$.value=($1.value==$3.value);
202  }
203  | expr _NOT_EQUAL expr
204  {
205  if (($1.id!=NULL)||($3.id!=NULL))
206  ReadcuiksystemSemanticError("No operation is allowed with variables");
207 
208  $$.id=NULL;
209  $$.value=($1.value!=$3.value);
210  }
211  | expr _LEQ expr
212  {
213  if (($1.id!=NULL)||($3.id!=NULL))
214  ReadcuiksystemSemanticError("No operation is allowed with variables");
215 
216  $$.id=NULL;
217  $$.value=($1.value<=$3.value);
218  }
219  | expr _GEQ expr
220  {
221  if (($1.id!=NULL)||($3.id!=NULL))
222  ReadcuiksystemSemanticError("No operation is allowed with variables");
223 
224  $$.id=NULL;
225  $$.value=($1.value>=$3.value);
226  }
227  | expr _LESS expr
228  {
229  if (($1.id!=NULL)||($3.id!=NULL))
230  ReadcuiksystemSemanticError("No operation is allowed with variables");
231 
232  $$.id=NULL;
233  $$.value=($1.value<$3.value);
234  }
235  | expr _GREATER expr
236  {
237  if (($1.id!=NULL)||($3.id!=NULL))
238  ReadcuiksystemSemanticError("No operation is allowed with variables");
239 
240  $$.id=NULL;
241  $$.value=($1.value>$3.value);
242  }
243  | _PI
244  {
245  $$.id=NULL;
246  $$.value=M_PI;
247  }
248  | _INF
249  {
250  $$.id=NULL;
251  $$.value=INF;
252  }
253  | _SIN '(' expr ')'
254  {
255  if ($3.id!=NULL)
256  ReadcuiksystemSemanticError("No operation is allowed with variables");
257 
258  $$.id=NULL;
259  $$.value=sin($3.value);
260  }
261  | _COS '(' expr ')'
262  {
263  if ($3.id!=NULL)
264  ReadcuiksystemSemanticError("No operation is allowed with variables");
265 
266  $$.id=NULL;
267  $$.value=cos($3.value);
268  }
269  | _TAN '(' expr ')'
270  {
271  if ($3.id!=NULL)
272  ReadcuiksystemSemanticError("No operation is allowed with variables");
273 
274  $$.id=NULL;
275  $$.value=tan($3.value);
276  }
277  | _COT '(' expr ')'
278  {
279  if ($3.id!=NULL)
280  ReadcuiksystemSemanticError("No operation is allowed with variables");
281 
282  $$.id=NULL;
283  $$.value=tan(M_PI_2-$3.value);
284  }
285  | _ASIN '(' expr ')'
286  {
287  if ($3.id!=NULL)
288  ReadcuiksystemSemanticError("No operation is allowed with variables");
289 
290  $$.id=NULL;
291  $$.value=asin($3.value);
292  }
293  | _ACOS '(' expr ')'
294  {
295  if ($3.id!=NULL)
296  ReadcuiksystemSemanticError("No operation is allowed with variables");
297 
298  $$.id=NULL;
299  $$.value=acos($3.value);
300  }
301  | _ATAN '(' expr ')'
302  {
303  if ($3.id!=NULL)
304  ReadcuiksystemSemanticError("No operation is allowed with variables");
305 
306  $$.id=NULL;
307  $$.value=atan($3.value);
308  }
309  | _ATAN2 '(' expr ',' expr ')'
310  {
311  if (($3.id!=NULL)||($5.id!=NULL))
312  ReadcuiksystemSemanticError("No operation is allowed with variables");
313 
314  $$.id=NULL;
315  $$.value=atan2($3.value,$5.value);
316  }
317  | _EXP '(' expr ')'
318  {
319  if ($3.id!=NULL)
320  ReadcuiksystemSemanticError("No operation is allowed with variables");
321 
322  $$.id=NULL;
323  $$.value=exp($3.value);
324  }
325  | _PWP '(' expr ')'
326  {
327  if ($3.id!=NULL)
328  ReadcuiksystemSemanticError("No operation is allowed with variables");
329 
330  $$.id=NULL;
331  if ($3.value<0.0)
332  $$.value=$3.value*$3.value;
333  else
334  $$.value=0.0;
335  }
336  | _SQRT '(' expr ')'
337  {
338  if ($3.id!=NULL)
339  ReadcuiksystemSemanticError("No operation is allowed with variables");
340 
341  $$.id=NULL;
342  $$.value=sqrt($3.value);
343  }
344  | _ABS '(' expr ')'
345  {
346  if ($3.id!=NULL)
347  ReadcuiksystemSemanticError("No operation is allowed with variables");
348 
349  $$.id=NULL;
350  $$.value=fabs($3.value);
351  }
352  | _PARAMETER '(' _IDENTIFIER ')'
353  {
354  unsigned int n;
355 
356  n=GetParameterID($3,rcs_parameters);
357  if (n==NO_UINT)
358  {
359  char ms[200];
360 
361  sprintf(ms,"Undefined parameter: %.100s",$3);
363  }
364 
365  $$.id=NULL;
366  $$.value=GetParameter(n,rcs_parameters);
367  }
368  | _IDENTIFIER
369  {
370  unsigned int nc;
371 
372  nc=GetConstantWithName($1,rcs_constants);
373 
374  if (nc!=NO_UINT)
375  {
376  $$.id=NULL;
377  $$.value=GetConstantValue(nc,rcs_constants);
378  free($1);
379  }
380  else
381  {
382  if (GetCSVariableID($1,rcs_cuiksystem)==NO_UINT)
383  {
384  char s[300];
385 
386  sprintf(s,"Undefined variable %s",$1);
388  free($1);
389  }
390  else
391  $$.id=$1;
392 
393  }
394  }
395  | _INTEGER
396  {
397  $$.id=NULL;
398  $$.value=(double)$1;
399  }
400  | _REAL
401  {
402  $$.id=NULL;
403  $$.value=$1;
404  }
405  ;
406 
407 var_defs : var_block var_defs
408  |
409  ;
410 
411 var_block : system_vars
412  | secondary_vars
413  | dummy_vars
414  | cartesian_vars
415  ;
416 
417 system_vars: _SYSTEM_VARS
418  {
419  rcs_var_type=SYSTEM_VAR;
420  }
421  range_list
422  ;
423 
424 secondary_vars: _SECONDARY_VARS
425  {
426  rcs_var_type=SECONDARY_VAR;
427  }
428  range_list
429  ;
430 
431 dummy_vars: _DUMMY_VARS
432  {
433  rcs_var_type=DUMMY_VAR;
434  }
435  range_list
436  ;
437 
438 cartesian_vars: _CARTESIAN_VARS
439  {
440  rcs_var_type=CARTESIAN_VAR;
441  }
442  range_list
443  ;
444 
445 range_list: range_definition range_list
446  |
447  ;
448 
449 topology: ':'
450  {
451  rcs_topology=TOPOLOGY_R;
452  }
453  | '~'
454  {
455  rcs_topology=TOPOLOGY_S;
456  }
457  ;
458 
459 range_definition : _IDENTIFIER topology '[' expr ',' expr ']'
460  {
461  Tinterval i_user;
462  Tvariable v;
463 
464  if (($4.id!=NULL)||($6.id!=NULL))
465  ReadcuiksystemSemanticError("Can not define a range with variables");
466 
467  if (GetConstantWithName($1,rcs_constants)!=NO_UINT)
468  {
469  char s[300];
470 
471  sprintf(s,"Constant %s redefined as a variable",$1);
473  }
474 
475  if (GetCSVariableID($1,rcs_cuiksystem)!=NO_UINT)
476  {
477  char s[300];
478 
479  sprintf(s,"Repeated range declaration for variable %s",$1);
481  }
482 
483  if (rcs_topology==TOPOLOGY_S)
484  {
485  if ((fabs($4.value+M_PI)>ZERO)||(fabs($6.value-M_PI)>ZERO))
486  {
487  char s[300];
488 
489  sprintf(s,"Circular variable %s must have range [-pi,pi]",$1);
491  }
492  NewInterval(-M_PI,+M_PI,&i_user);
493  }
494  else
495  NewInterval($4.value,$6.value,&i_user);
496 
497  if (EmptyInterval(&i_user))
498  ReadcuiksystemSemanticError("Empty Interval");
499 
500  NewVariable(rcs_var_type,$1,&v);
501  SetVariableInterval(&i_user,&v);
502  if (rcs_topology==TOPOLOGY_S)
504 
505  AddVariable2CS(&v,rcs_cuiksystem);
506 
507  DeleteVariable(&v);
508  free($1);
509  }
510  ;
511 
512 system_eqs : _SYSTEM_EQS
513  {
514  rcs_eq_type=SYSTEM_EQ;
515  }
516  eq_list
517  meq_list
518  |
519  ;
520 
521 coord_eqs : _COORD_EQS
522  {
523  rcs_eq_type=COORD_EQ;
524  }
525  eq_list
526  |
527  ;
528 
529 dummy_eqs : _DUMMY_EQS
530  {
531  rcs_eq_type=DUMMY_EQ;
532  }
533  eq_list
534  |
535  ;
536 
537 search: _SEARCH
538  search_type
539  |
540  {
541  SetCSSearchMode(DEPTH_FIRST_SEARCH,NULL,rcs_cuiksystem);
542  }
543  ;
544 
545 search_type: _DEPTH _FIRST
546  {
547  SetCSSearchMode(DEPTH_FIRST_SEARCH,NULL,rcs_cuiksystem);
548  }
549  | _BREADTH _FIRST
550  {
551  SetCSSearchMode(BREADTH_FIRST_SEARCH,NULL,rcs_cuiksystem);
552  }
553  | _MIN monomials
554  {
555  SetEquationType(SYSTEM_EQ,&rcs_equation);
556  SetEquationCmp(EQU,&rcs_equation);
557  SetCSSearchMode(MINIMIZATION_SEARCH,&(rcs_equation),rcs_cuiksystem);
558  ResetEquation(&rcs_equation);
559  }
560  ;
561 
562 eq_list: equation
563  {
564  AddEquation2CS(rcs_parameters,&rcs_equation,rcs_cuiksystem);
565 
566  /*Get ready for next equation definition*/
567  ResetEquation(&rcs_equation);
568  }
569  eq_list
570  |
571  ;
572 
573 equation: monomials cmp
574  {
575  rcs_sgn=-1.0;
576  }
577  monomials ';'
578  {
579  SetEquationType(rcs_eq_type,&rcs_equation);
580  SetEquationCmp($2,&rcs_equation);
581 
582  rcs_sgn=1.0;
583  }
584  ;
585 
586 monomials : opt_sign monomial
587  {
588  AddCt2Monomial(rcs_sgn,&rcs_monomial);
589  AddMonomial(&rcs_monomial,&rcs_equation);
590  ResetMonomial(&rcs_monomial);
591 
592 
593  }
594  more_monomials
595  ;
596 
597 more_monomials: sign monomial
598  {
599  AddCt2Monomial(rcs_sgn,&rcs_monomial);
600  AddMonomial(&rcs_monomial,&rcs_equation);
601  ResetMonomial(&rcs_monomial);
602  }
603  more_monomials
604  |
605  ;
606 
607 opt_sign : sign
608  |
609  ;
610 
611 sign : '+'
612  | '-'
613  {
614  AddCt2Monomial(-1.0,&rcs_monomial);
615  }
616  ;
617 
618 monomial : item '*' monomial
619  | item
620  ;
621 
622 item : _REAL power
623  {
624  if ($2==1)
625  AddCt2Monomial($1,&rcs_monomial);
626  else
627  AddCt2Monomial(pow($1,(double)$2),&rcs_monomial);
628  }
629  | _INTEGER power
630  {
631  if ($2==1)
632  AddCt2Monomial((double)$1,&rcs_monomial);
633  else
634  AddCt2Monomial(pow((double)$1,(double)$2),&rcs_monomial);
635  }
636  | _SIN '(' expr ')' power
637  {
638  if ($3.id!=NULL)
639  {
640  unsigned int id;
641 
642  id=GetCSVariableID($3.id,rcs_cuiksystem);
643  if (id!=NO_UINT) /*a known variable*/
644  AddVariable2Monomial(SINV,id,$5,&rcs_monomial);
645  else
646  {
647  char s[300];
648 
649  sprintf(s,"Unknown variable %s",$3.id);
651  }
652  free($3.id);
653  }
654  else
655  {
656  if ($5==1)
657  AddCt2Monomial(sin($3.value),&rcs_monomial);
658  else
659  AddCt2Monomial(pow(sin($3.value),(double)$5),&rcs_monomial);
660  }
661  }
662  | _COS '(' expr ')' power
663  {
664  if ($3.id!=NULL)
665  {
666  unsigned int id;
667 
668  id=GetCSVariableID($3.id,rcs_cuiksystem);
669  if (id!=NO_UINT) /*a known variable*/
670  AddVariable2Monomial(COSV,id,$5,&rcs_monomial);
671  else
672  {
673  char s[300];
674 
675  sprintf(s,"Unknown variable %s",$3.id);
677  }
678  free($3.id);
679  }
680  else
681  {
682  if ($5==1)
683  AddCt2Monomial(cos($3.value),&rcs_monomial);
684  else
685  AddCt2Monomial(pow(cos($3.value),(double)$5),&rcs_monomial);
686  }
687  }
688  | _TAN '(' expr ')' power
689  {
690  if ($3.id!=NULL)
691  {
692  unsigned int id;
693 
694  id=GetCSVariableID($3.id,rcs_cuiksystem);
695  if (id!=NO_UINT) /*a known variable*/
696  AddVariable2Monomial(TANV,id,$5,&rcs_monomial);
697  else
698  {
699  char s[300];
700 
701  sprintf(s,"Unknown variable %s",$3.id);
703  }
704  free($3.id);
705  }
706  else
707  {
708  if ($5==1)
709  AddCt2Monomial(tan($3.value),&rcs_monomial);
710  else
711  AddCt2Monomial(pow(tan($3.value),(double)$5),&rcs_monomial);
712  }
713  }
714  | _EXP '(' expr ')' power
715  {
716  if ($3.id!=NULL)
717  {
718  unsigned int id;
719 
720  id=GetCSVariableID($3.id,rcs_cuiksystem);
721  if (id!=NO_UINT) /*a known variable*/
722  AddVariable2Monomial(EXPV,id,$5,&rcs_monomial);
723  else
724  {
725  char s[300];
726 
727  sprintf(s,"Unknown variable %s",$3.id);
729  }
730  free($3.id);
731  }
732  else
733  {
734  if ($5==1)
735  AddCt2Monomial(exp($3.value),&rcs_monomial);
736  else
737  AddCt2Monomial(pow(exp($3.value),(double)$5),&rcs_monomial);
738  }
739  }
740  | _PWP '(' expr ')' power
741  {
742  if ($3.id!=NULL)
743  {
744  unsigned int id;
745 
746  id=GetCSVariableID($3.id,rcs_cuiksystem);
747  if (id!=NO_UINT) /*a known variable*/
748  AddVariable2Monomial(PWPV,id,$5,&rcs_monomial);
749  else
750  {
751  char s[300];
752 
753  sprintf(s,"Unknown variable %s",$3.id);
755  }
756  free($3.id);
757  }
758  else
759  {
760  double v;
761 
762  if ($3.value<0.0)
763  v=$3.value*$3.value;
764  else
765  v=0.0;
766 
767  if ($5==1)
768  AddCt2Monomial(v,&rcs_monomial);
769  else
770  AddCt2Monomial(pow(v,(double)$5),&rcs_monomial);
771  }
772  }
773  | _IDENTIFIER power
774  {
775  unsigned int id;
776  unsigned int nc;
777 
778  nc=GetConstantWithName($1,rcs_constants);
779 
780  if (nc!=NO_UINT)
781  AddCt2Monomial(pow(GetConstantValue(nc,rcs_constants),(double)($2)),&rcs_monomial);
782  else
783  {
784  id=GetCSVariableID($1,rcs_cuiksystem);
785  if (id!=NO_UINT) /*a known variable*/
786  AddVariable2Monomial(NFUN,id,$2,&rcs_monomial);
787  else
788  {
789  char s[300];
790 
791  sprintf(s,"Unknown variable or constant %s",$1);
793  }
794  }
795  free($1);
796  }
797  ;
798 
799 power : '^' _INTEGER
800  {
801  $$=$2;
802  }
803  |
804  {
805  $$=1;
806  }
807  ;
808 
809 cmp : _EQU
810  {
811  $$=EQU;
812  }
813  | _LEQ
814  {
815  $$=LEQ;
816  }
817  | _GEQ
818  {
819  $$=GEQ;
820  }
821  ;
822 
823 meq_list: mequation _EQU _ID ';'
824  {
825  SimplifyMEquation(&rcs_mequation);
826  AddMatrixEquation2CS(rcs_parameters,&rcs_mequation,rcs_cuiksystem);
827 
828  ResetMEquation(&rcs_mequation);
829  }
830  meq_list
831  |
832  ;
833 mequation : mitem '*' mequation
834  | mitem
835  ;
836 
837 mitem: _T '(' expr ',' expr ',' expr ',' expr ';' expr ',' expr ',' expr ',' expr ';' expr ',' expr ',' expr ',' expr ')' opt_invert
838  {
839  THTransform t;
840 
841  if (($3.id!=NULL)||($5.id!=NULL)||($7.id!=NULL)||($9.id!=NULL)||
842  ($11.id!=NULL)||($13.id!=NULL)||($15.id!=NULL)||($17.id!=NULL)||
843  ($19.id!=NULL)||($21.id!=NULL)||($23.id!=NULL)||($25.id!=NULL))
844  ReadcuiksystemSemanticError("Error defining a constant transform");
845 
846  HTransformIdentity(&t);
847 
848  HTransformSetElement(0,0,$3.value,&t);
849  HTransformSetElement(0,1,$5.value,&t);
850  HTransformSetElement(0,2,$7.value,&t);
851  HTransformSetElement(0,3,$9.value,&t);
852  HTransformSetElement(1,0,$11.value,&t);
853  HTransformSetElement(1,1,$13.value,&t);
854  HTransformSetElement(1,2,$15.value,&t);
855  HTransformSetElement(1,3,$17.value,&t);
856  HTransformSetElement(2,0,$19.value,&t);
857  HTransformSetElement(2,1,$21.value,&t);
858  HTransformSetElement(2,2,$23.value,&t);
859  HTransformSetElement(2,3,$25.value,&t);
860 
861  if ($27<0)
862  HTransformInverse(&t,&t);
863 
864  AddCtTrans2MEquation(&t,&rcs_mequation);
865 
866  HTransformDelete(&t);
867  }
868  | _TV '(' expr ',' expr ',' expr ',' expr ')' opt_invert
869  {
870  unsigned int nv,nc;
871  double ctValue;
872  boolean constant;
873 
874  /* Translation along a vector */
875 
876  if (($3.id!=NULL)||($5.id!=NULL)||($7.id!=NULL))
877  ReadcuiksystemSemanticError("Error defining a TV transform");
878 
879  constant=FALSE;
880  if ($9.id==NULL)
881  {
882  constant=TRUE;
883  ctValue=(double)$11*$9.value;
884  }
885  else
886  {
887  nc=GetConstantWithName($9.id,rcs_constants);
888  if (nc!=NO_UINT)
889  {
890  constant=TRUE;
891  ctValue=(double)$11*GetConstantValue(nc,rcs_constants);
892  }
893  }
894 
895  if (constant)
896  {
897  /* Actually defining a ct transform */
898  THTransform t;
899 
900  HTransformTxyz(ctValue*$3.value,ctValue*$5.value,ctValue*$7.value,&t);
901  AddCtTrans2MEquation(&t,&rcs_mequation);
902  HTransformDelete(&t);
903  }
904  else
905  {
906  nv=GetCSVariableID($9.id,rcs_cuiksystem);
907 
908  rcs_vect[0]=$3.value;
909  rcs_vect[1]=$5.value;
910  rcs_vect[2]=$7.value;
911 
912  AddDispTrans2MEquation($11,nv,rcs_vect,&rcs_mequation);
913  }
914  if ($9.id!=NULL)
915  free($9.id);
916  }
917  | trans_type '(' expr ')' opt_invert
918  {
919  unsigned int nv,nc;
920  double ctValue;
921  boolean constant;
922 
923  constant=FALSE;
924  if ($3.id==NULL)
925  {
926  constant=TRUE;
927  ctValue=(double)$5*$3.value;
928  }
929  else
930  {
931  nc=GetConstantWithName($3.id,rcs_constants);
932  if (nc!=NO_UINT)
933  {
934  constant=TRUE;
935  ctValue=(double)$5*GetConstantValue(nc,rcs_constants);
936  }
937  }
938 
939  if (constant)
940  {
941  /* Actually defining a ct transform */
942  THTransform t;
943 
944  if (($1!=TX)&&($1!=TY)&&($1!=TZ)&&($1!=RX)&&($1!=RY)&&($1!=RZ))
945  ReadcuiksystemSemanticError("Only basic transforms (Tx,Ty,Tz,Rx,Ry,Rz) can be set to constant");
946 
947  HTransformCreate($1,ctValue,&t);
948  AddCtTrans2MEquation(&t,&rcs_mequation);
949  HTransformDelete(&t);
950  }
951  else
952  {
953  nv=GetCSVariableID($3.id,rcs_cuiksystem);
954  AddVarTrans2MEquation($1,$5,nv,&rcs_mequation);
955  }
956  if ($3.id!=NULL)
957  free($3.id);
958  }
959  | patch_type '(' four_points ';' _IDENTIFIER ',' _IDENTIFIER ')' opt_invert
960  {
961  unsigned int u,v;
962 
963  u=GetCSVariableID($5,rcs_cuiksystem);
964  if (u==NO_UINT)
965  {
966  char s[300];
967 
968  sprintf(s,"Undefined variable %s",$5);
970  }
971 
972  v=GetCSVariableID($7,rcs_cuiksystem);
973  if (v==NO_UINT)
974  {
975  char s[300];
976 
977  sprintf(s,"Undefined variable %s",$7);
979  }
980 
981  AddPatchTrans2MEquation($1,$9,u,v,rcs_point,&rcs_mequation);
982  }
983  ;
984 
985 opt_invert : _INV
986  {
987  $$=-1;
988  }
989  |
990  {
991  $$=1;
992  }
993  ;
994 
995 trans_type : _TX
996  {
997  $$=TX;
998  }
999  | _TY
1000  {
1001  $$=TY;
1002  }
1003  | _TZ
1004  {
1005  $$=TZ;
1006  }
1007  | _RX
1008  {
1009  $$=RX;
1010  }
1011  | _RY
1012  {
1013  $$=RY;
1014  }
1015  | _RZ
1016  {
1017  $$=RZ;
1018  }
1019  | _DRX
1020  {
1021  $$=dRX;
1022  }
1023  | _DRY
1024  {
1025  $$=dRY;
1026  }
1027  | _DRZ
1028  {
1029  $$=dRZ;
1030  }
1031  | _DDRX
1032  {
1033  $$=ddRX;
1034  }
1035  | _DDRY
1036  {
1037  $$=ddRY;
1038  }
1039  | _DDRZ
1040  {
1041  $$=ddRZ;
1042  }
1043  ;
1044 
1045 patch_type : _PA
1046  {
1047  $$=PA;
1048  }
1049  | _DPA_U
1050  {
1051  $$=dPA_U;
1052  }
1053  | _DPA_V
1054  {
1055  $$=dPA_V;
1056  }
1057  | _DDPA_UU
1058  {
1059  $$=ddPA_UU;
1060  }
1061  | _DDPA_UV
1062  {
1063  $$=ddPA_UV;
1064  }
1065  | _DDPA_VV
1066  {
1067  $$=ddPA_VV;
1068  }
1069  ;
1070 
1071 four_points : expr ',' expr ',' expr ';' expr ',' expr ',' expr ';' expr ',' expr ',' expr ';' expr ',' expr ',' expr
1072  {
1073  if (($1.id!=NULL)||($3.id!=NULL)||($5.id!=NULL)||
1074  ($7.id!=NULL)||($9.id!=NULL)||($11.id!=NULL)||
1075  ($13.id!=NULL)||($15.id!=NULL)||($17.id!=NULL)||
1076  ($19.id!=NULL)||($21.id!=NULL)||($23.id!=NULL))
1077  ReadcuiksystemSemanticError("Error defining a patch transform");
1078 
1079  rcs_point[0][0]=$1.value;
1080  rcs_point[0][1]=$3.value;
1081  rcs_point[0][2]=$5.value;
1082 
1083  rcs_point[1][0]=$7.value;
1084  rcs_point[1][1]=$9.value;
1085  rcs_point[1][2]=$11.value;
1086 
1087  rcs_point[2][0]=$13.value;
1088  rcs_point[2][1]=$15.value;
1089  rcs_point[2][2]=$17.value;
1090 
1091  rcs_point[3][0]=$19.value;
1092  rcs_point[3][1]=$21.value;
1093  rcs_point[3][2]=$23.value;
1094  }
1095  ;
1096 
1097 %%
1099 /*
1100  * Reads a file containing the constants definitions, kinematic equations to be solved,
1101  * and the range constrains for the variables.
1102  */
1103 void InitCuikSystemFromFile(Tparameters *p,char *filename,TCuikSystem *cs)
1104 {
1105 
1106  /*Start the data structures*/
1107  InitCuikSystem(cs);
1108 
1109  /*Add information to the data structure */
1110  AddCuikSystemFromFile(p,filename,cs);
1111 }
1112 
1113 void AddCuikSystemFromFile(Tparameters *p,char *filename,TCuikSystem *cs)
1114 {
1115  unsigned int i;
1116 
1117  rcs_parameters=p;
1118 
1119  Readcuiksystemin=fopen(filename,"r");
1120  if (!Readcuiksystemin)
1121  {
1122  char ErrorText[500];
1123 
1124  sprintf(ErrorText,"File %s does not exists",filename);
1125  Error(ErrorText);
1126  }
1127 
1128  rcs_constants=&(cs->constants);
1129 
1130  /*Reset the lines numbering*/
1131  RCSline=1;
1132 
1133  /*we initalize the global pointer to make the parameters accesibles to any one inside the YACC module*/
1134  rcs_cuiksystem=cs;
1135 
1136  /*Get ready for first equation*/
1137  InitEquation(&rcs_equation);
1138  InitMEquation(&rcs_mequation);
1139  InitMonomial(&rcs_monomial);
1140 
1141  /* space for points */
1142  NEW(rcs_point,4,double *);
1143  for(i=0;i<4;i++)
1144  { NEW(rcs_point[i],3,double); }
1145 
1146  /*and process the file*/
1147  Readcuiksystemparse();
1148 
1149  /* and release structures */
1150  for(i=0;i<4;i++)
1151  free(rcs_point[i]);
1152  free(rcs_point);
1153 
1154  DeleteEquation(&rcs_equation);
1155  DeleteMEquation(&rcs_mequation);
1156  DeleteMonomial(&rcs_monomial);
1157 
1158  cs->updated=FALSE;
1159  fclose(Readcuiksystemin);
1160 }
1161 
Definition of the boolean type.
Definition of the Tequation type and the associated functions.
#define CARTESIAN_VAR
One of the possible type of variables.
Definition: variable.h:62
#define SYSTEM_EQ
One of the possible type of equations.
Definition: equation.h:146
Definition of the Tvariable_set type and the associated functions.
#define FALSE
FALSE.
Definition: boolean.h:30
void AddDispTrans2MEquation(int s, unsigned int v, double *vect, TMequation *me)
Adds a displacement along a vector.
Definition: mequation.c:206
void HTransformTxyz(double tx, double ty, double tz, THTransform *t)
Constructor.
Definition: htransform.c:146
double GetConstantValue(unsigned int n, Tconstants *cts)
Retrives a the value of a constant.
Definition: constants.c:113
#define dPA_V
Derivative of a PA transform.
Definition: trans_seq.h:70
Expressions that appear in the constant declarations are either variables (and have and name) or cons...
A table of constants.
Definition: constants.h:53
void SetEquationType(unsigned int type, Tequation *eq)
Changes the type of the equation (SYSTEM_EQ, CARTESIAN_EQ, DUMMY_EQ, DERIVED_EQ). ...
Definition: equation.c:1076
#define ddPA_VV
Double derivative of a PA transform.
Definition: trans_seq.h:109
#define NEW(_var, _n, _type)
Allocates memory space.
Definition: defines.h:385
#define ddRX
Double derivative of a Rx transform.
Definition: trans_seq.h:76
void InitMEquation(TMequation *me)
Construtor.
Definition: mequation.c:99
void DeleteEquation(Tequation *eq)
Destructor.
Definition: equation.c:1859
A homgeneous transform in R^3.
#define SYSTEM_VAR
One of the possible type of variables.
Definition: variable.h:24
#define RZ
One of the types of homogeneous transforms in R^3.
Definition: htransform.h:75
unsigned int AddVariable2CS(Tvariable *v, TCuikSystem *cs)
Adds a variable to the system.
Definition: cuiksystem.c:2532
#define DEPTH_FIRST_SEARCH
Depth first search.
Definition: cuiksystem.h:54
#define EQU
In a Tequation, the equation relational operator is equal.
Definition: equation.h:202
#define DUMMY_EQ
One of the possible type of equations.
Definition: equation.h:164
#define PWPV
Squared of the variable, if it is negative.
Definition: variable_set.h:96
#define COORD_EQ
One of the possible type of equations.
Definition: equation.h:155
#define BREADTH_FIRST_SEARCH
Breadth first search.
Definition: cuiksystem.h:63
#define dRX
Derivative of a Rx transform.
Definition: trans_seq.h:44
#define EXPV
Exponential of the variable.
Definition: variable_set.h:88
#define RY
One of the types of homogeneous transforms in R^3.
Definition: htransform.h:67
void SetVariableInterval(Tinterval *i, Tvariable *v)
Sets the new range for the variable.
Definition: variable.c:68
#define TRUE
TRUE.
Definition: boolean.h:21
#define LEQ
In a Tequation, the equation relational operator is less equal.
Definition: equation.h:196
void InitEquation(Tequation *eq)
Constructor.
Definition: equation.c:86
void Error(const char *s)
General error function.
Definition: error.c:80
void AddMatrixEquation2CS(Tparameters *p, TMequation *eq, TCuikSystem *cs)
Adds a matrix equation to the system.
Definition: cuiksystem.c:2511
#define NFUN
No trigonometric function for the variable.
Definition: variable_set.h:36
#define TOPOLOGY_R
One of the possible topologies.
Definition: defines.h:122
#define TZ
One of the types of homogeneous transforms in R^3.
Definition: htransform.h:51
#define MINIMIZATION_SEARCH
Search based on a minimum value of a given equation.
Definition: cuiksystem.h:76
void SimplifyMEquation(TMequation *me)
Tries to reduce the complexity of the matrix equation.
Definition: mequation.c:358
#define COSV
Cosine of the variable.
Definition: variable_set.h:50
#define ZERO
Floating point operations giving a value below this constant (in absolute value) are considered 0...
Definition: defines.h:37
Matrix equation.
Definition: mequation.h:42
void AddMonomial(Tmonomial *f, Tequation *eq)
Adds a new monomial to the equation.
Definition: equation.c:1419
#define GEQ
In a Tequation, the equation relational operator is great equal.
Definition: equation.h:190
#define ddPA_UU
Double derivative of a PA transform.
Definition: trans_seq.h:95
Error and warning functions.
#define SINV
Sine of the variable.
Definition: variable_set.h:43
void SetEquationCmp(unsigned int cmp, Tequation *eq)
Changes the relational operator (LEQ, GEQ, EQU) of the equation.
Definition: equation.c:1081
#define ddRZ
Double derivative of a Rx transform.
Definition: trans_seq.h:88
void ResetMonomial(Tmonomial *f)
Reset the monomial information.
Definition: monomial.c:24
void HTransformInverse(THTransform *t, THTransform *ti)
Inverse of a homogeneous transform.
Definition: htransform.c:503
#define TX
One of the types of homogeneous transforms in R^3.
Definition: htransform.h:35
An equation.
Definition: equation.h:237
void DeleteVariable(Tvariable *v)
Destructor.
Definition: variable.c:93
void AddCuikSystemFromFile(Tparameters *p, char *filename, TCuikSystem *cs)
Adds information from a file.
Definitions of constants and macros used in several parts of the cuik library.
#define M_PI_2
Pi/2.
Definition: defines.h:92
void NewVariable(unsigned int type, char *name, Tvariable *v)
Constructor.
Definition: variable.c:20
void ReadcuiksystemSemanticError(const char *s)
Semantic errors in .cuik files.
Definition: error.c:108
#define SECONDARY_VAR
One of the possible type of variables.
Definition: variable.h:44
void InitCuikSystemFromFile(Tparameters *p, char *filename, TCuikSystem *cs)
Constructor from a file.
void InitCuikSystem(TCuikSystem *cs)
Constructor.
Definition: cuiksystem.c:2167
void AddEquation2CS(Tparameters *p, Tequation *eq, TCuikSystem *cs)
Adds an equation to the system.
Definition: cuiksystem.c:2502
#define dPA_U
Derivative of a PA transform.
Definition: trans_seq.h:63
A scaled product of powers of variables.
Definition: monomial.h:32
A table of parameters.
Definition of the TCuikSystem type and the associated functions.
boolean updated
Definition: cuiksystem.h:184
#define TANV
Tangent of the variable.
Definition: variable_set.h:57
Definition of data types shared between the lexical and the syntactical analizer for ...
unsigned int AddConstant(char *name, double v, Tconstants *cts)
Add a constant.
Definition: constants.c:65
#define ddRY
Double derivative of a Rx transform.
Definition: trans_seq.h:82
#define M_PI
Pi.
Definition: defines.h:83
void ResetEquation(Tequation *eq)
Reset equation information.
Definition: equation.c:442
#define dRZ
Derivative of a Rz transform.
Definition: trans_seq.h:56
Data associated with each variable in the problem.
Definition: variable.h:84
A cuiksystem, i.e., a set of variables and equations defining a position analysis problem...
Definition: cuiksystem.h:181
#define NO_UINT
Used to denote an identifier that has not been initialized.
Definition: defines.h:435
#define RX
One of the types of homogeneous transforms in R^3.
Definition: htransform.h:59
#define dRY
Derivative of a Ry transform.
Definition: trans_seq.h:50
Definition of the Tvariable type and the associated functions.
void ResetMEquation(TMequation *me)
Resets the information stored in the matrix equation.
Definition: mequation.c:134
void AddVariable2Monomial(unsigned int fn, unsigned int varid, unsigned int p, Tmonomial *f)
Adds a power variable to the monomial.
Definition: monomial.c:171
Definition of the matrix equation operations.
boolean EmptyInterval(Tinterval *i)
Checks if a given interval is empty.
Definition: interval.c:335
void AddPatchTrans2MEquation(unsigned int t, int s, unsigned int u, unsigned int v, double **p, TMequation *me)
Adds a Parametrized-Patch transform to a matrix equation.
Definition: mequation.c:224
void SetVariableTopology(unsigned int t, Tvariable *v)
Sets the topology of the variable.
Definition: variable.c:42
void HTransformDelete(THTransform *t)
Destructor.
Definition: htransform.c:887
unsigned int GetConstantWithName(char *name, Tconstants *cts)
Retrives a constant from the set.
Definition: constants.c:88
#define PA
Point on a patch.
Definition: trans_seq.h:31
double GetParameter(unsigned int n, Tparameters *p)
Gets the value for a particular parameter.
Definition: parameters.c:93
#define ddPA_UV
Double derivative of a PA transform.
Definition: trans_seq.h:102
void AddCtTrans2MEquation(THTransform *t, TMequation *me)
Adds a constant transform to a matrix equation.
Definition: mequation.c:238
void NewInterval(double lower, double upper, Tinterval *i)
Constructor.
Definition: interval.c:47
void HTransformSetElement(unsigned int i, unsigned int j, double v, THTransform *t)
Sets an element in a homogeneous transform.
Definition: htransform.c:312
#define INF
Infinite.
Definition: defines.h:70
void AddCt2Monomial(double k, Tmonomial *f)
Scales a monomial.
Definition: monomial.c:158
Tconstants constants
Definition: cuiksystem.h:182
void SetCSSearchMode(unsigned int sm, Tequation *eqMin, TCuikSystem *cs)
Sets the search mode for the cuiksystem.
Definition: cuiksystem.c:2433
unsigned int GetCSVariableID(char *name, TCuikSystem *cs)
Gets the numerical identifier of a variable given its name.
Definition: cuiksystem.c:2607
unsigned int GetParameterID(char *name, Tparameters *p)
Returns the parameter identifier given the paramete name.
Definition: parameters.c:110
void HTransformCreate(unsigned int dof_r3, double v, THTransform *t)
Constructor.
Definition: htransform.c:278
Definition of the Tmonomial type and the associated functions.
Defines a interval.
Definition: interval.h:33
Definition of the Tparameters type and the associated functions.
void HTransformIdentity(THTransform *t)
Constructor.
Definition: htransform.c:69
void InitMonomial(Tmonomial *f)
Constructor.
Definition: monomial.c:17
Definition of the Tequations type and the associated functions.
#define DUMMY_VAR
One of the possible type of variables.
Definition: variable.h:53
void DeleteMEquation(TMequation *me)
Destructor.
Definition: mequation.c:492
void DeleteMonomial(Tmonomial *f)
Destructor.
Definition: monomial.c:289
unsigned int RCSline
Number of the line currently parsed when reading a .cuik file.
Definition: error.c:71
#define TY
One of the types of homogeneous transforms in R^3.
Definition: htransform.h:43
#define TOPOLOGY_S
One of the possible topologies.
Definition: defines.h:139
void AddVarTrans2MEquation(unsigned int t, int s, unsigned int v, TMequation *me)
Adds a variable transform to the matrix equation.
Definition: mequation.c:212
Definition of the Tinterval type and the associated functions.