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 _EXP _PWP _SQRT _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
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 '+' '-'
80 %left '*' '/'
81 %left '^'
82 %right _MAX_PRECEDENCE
83 
84 %%
85 
86 problem: ct_defs var_defs system_eqs coord_eqs dummy_eqs search
87  ;
88 
89 ct_defs : _CONSTANTS ct_list
90  |
91  ;
92 
93 ct_list : ct_definition ct_list
94  |
95  ;
96 
97 ct_definition: _IDENTIFIER _ASSIGN expr
98  {
99  if (GetConstantWithName($1,rcs_constants)!=NO_UINT)
100  {
101  char s[200];
102 
103  sprintf(s,"Duplicated constant %s",$1);
105  }
106 
107  if ($3.id!=NULL)
108  ReadcuiksystemSemanticError("Constant assigned to a variable");
109 
110  AddConstant($1,$3.value,rcs_constants);
111  free($1);
112  }
113  ;
114 
115 
116 expr : '+' expr %prec _MAX_PRECEDENCE
117  {
118  if ($2.id!=NULL)
119  ReadcuiksystemSemanticError("No operation is allowed with variables");
120 
121  $$.id=NULL;
122  $$.value=$2.value;
123  }
124  | '-' expr %prec _MAX_PRECEDENCE
125  {
126  if ($2.id!=NULL)
127  ReadcuiksystemSemanticError("No operation is allowed with variables");
128 
129  $$.id=NULL;
130  $$.value=-$2.value;
131  }
132  | expr '+' expr
133  {
134  if (($1.id!=NULL)||($3.id!=NULL))
135  ReadcuiksystemSemanticError("No operation is allowed with variables");
136 
137  $$.id=NULL;
138  $$.value=$1.value+$3.value;
139  }
140  | expr '-' expr
141  {
142  if (($1.id!=NULL)||($3.id!=NULL))
143  ReadcuiksystemSemanticError("No operation is allowed with variables");
144 
145  $$.id=NULL;
146  $$.value=$1.value-$3.value;
147  }
148  | expr '*' expr
149  {
150  if (($1.id!=NULL)||($3.id!=NULL))
151  ReadcuiksystemSemanticError("No operation is allowed with variables");
152 
153  $$.id=NULL;
154  $$.value=$1.value*$3.value;
155  }
156  | expr '^' expr
157  {
158  if (($1.id!=NULL)||($3.id!=NULL))
159  ReadcuiksystemSemanticError("No operation is allowed with variables");
160 
161  $$.id=NULL;
162  $$.value=pow($1.value,$3.value);
163  }
164  | expr '/' expr
165  {
166  if (($1.id!=NULL)||($3.id!=NULL))
167  ReadcuiksystemSemanticError("No operation is allowed with variables");
168 
169  if ($3.value==0.0)
170  ReadcuiksystemSemanticError("Division by zero");
171 
172  $$.id=NULL;
173  $$.value=$1.value/$3.value;
174  }
175  | '(' expr ')'
176  {
177  if ($2.id!=NULL)
178  ReadcuiksystemSemanticError("No operation is allowed with variables");
179 
180  $$.id=NULL;
181  $$.value=$2.value;
182  }
183  | _PI
184  {
185  $$.id=NULL;
186  $$.value=M_PI;
187  }
188  | _INF
189  {
190  $$.id=NULL;
191  $$.value=INF;
192  }
193  | _SIN '(' expr ')'
194  {
195  if ($3.id!=NULL)
196  ReadcuiksystemSemanticError("No operation is allowed with variables");
197 
198  $$.id=NULL;
199  $$.value=sin($3.value);
200  }
201  | _COS '(' expr ')'
202  {
203  if ($3.id!=NULL)
204  ReadcuiksystemSemanticError("No operation is allowed with variables");
205 
206  $$.id=NULL;
207  $$.value=cos($3.value);
208  }
209  | _TAN '(' expr ')'
210  {
211  if ($3.id!=NULL)
212  ReadcuiksystemSemanticError("No operation is allowed with variables");
213 
214  $$.id=NULL;
215  $$.value=tan($3.value);
216  }
217  | _EXP '(' expr ')'
218  {
219  if ($3.id!=NULL)
220  ReadcuiksystemSemanticError("No operation is allowed with variables");
221 
222  $$.id=NULL;
223  $$.value=exp($3.value);
224  }
225  | _PWP '(' expr ')'
226  {
227  if ($3.id!=NULL)
228  ReadcuiksystemSemanticError("No operation is allowed with variables");
229 
230  $$.id=NULL;
231  if ($3.value<0.0)
232  $$.value=$3.value*$3.value;
233  else
234  $$.value=0.0;
235  }
236  | _SQRT '(' expr ')'
237  {
238  if ($3.id!=NULL)
239  ReadcuiksystemSemanticError("No operation is allowed with variables");
240 
241  $$.id=NULL;
242  $$.value=sqrt($3.value);
243  }
244  | _IDENTIFIER
245  {
246  unsigned int nc;
247 
248  nc=GetConstantWithName($1,rcs_constants);
249 
250  if (nc!=NO_UINT)
251  {
252  $$.id=NULL;
253  $$.value=GetConstantValue(nc,rcs_constants);
254  free($1);
255  }
256  else
257  {
258  if (GetCSVariableID($1,rcs_cuiksystem)==NO_UINT)
259  {
260  char s[300];
261 
262  sprintf(s,"Undefined variable %s",$1);
264  free($1);
265  }
266  else
267  $$.id=$1;
268 
269  }
270  }
271  | _INTEGER
272  {
273  $$.id=NULL;
274  $$.value=(double)$1;
275  }
276  | _REAL
277  {
278  $$.id=NULL;
279  $$.value=$1;
280  }
281  ;
282 
283 var_defs : var_block var_defs
284  |
285  ;
286 
287 var_block : system_vars
288  | secondary_vars
289  | dummy_vars
290  | cartesian_vars
291  ;
292 
293 system_vars: _SYSTEM_VARS
294  {
295  rcs_var_type=SYSTEM_VAR;
296  }
297  range_list
298  ;
299 
300 secondary_vars: _SECONDARY_VARS
301  {
302  rcs_var_type=SECONDARY_VAR;
303  }
304  range_list
305  ;
306 
307 dummy_vars: _DUMMY_VARS
308  {
309  rcs_var_type=DUMMY_VAR;
310  }
311  range_list
312  ;
313 
314 cartesian_vars: _CARTESIAN_VARS
315  {
316  rcs_var_type=CARTESIAN_VAR;
317  }
318  range_list
319  ;
320 
321 range_list: range_definition range_list
322  |
323  ;
324 
325 topology: ':'
326  {
327  rcs_topology=TOPOLOGY_R;
328  }
329  | '~'
330  {
331  rcs_topology=TOPOLOGY_S;
332  }
333  ;
334 
335 range_definition : _IDENTIFIER topology '[' expr ',' expr ']'
336  {
337  Tinterval i_user;
338  Tvariable v;
339 
340  if (($4.id!=NULL)||($6.id!=NULL))
341  ReadcuiksystemSemanticError("Can not define a range with variables");
342 
343  if (GetConstantWithName($1,rcs_constants)!=NO_UINT)
344  {
345  char s[300];
346 
347  sprintf(s,"Constant %s redefined as a variable",$1);
349  }
350 
351  if (GetCSVariableID($1,rcs_cuiksystem)!=NO_UINT)
352  {
353  char s[300];
354 
355  sprintf(s,"Repeated range declaration for variable %s",$1);
357  }
358 
359  if (rcs_topology==TOPOLOGY_S)
360  NewInterval(ROUND2SYMBOL($4.value),ROUND2SYMBOL($6.value),&i_user);
361  else
362  NewInterval($4.value,$6.value,&i_user);
363 
364  if (EmptyInterval(&i_user))
365  ReadcuiksystemSemanticError("Empty Interval");
366 
367  NewVariable(rcs_var_type,$1,&v);
368  SetVariableInterval(&i_user,&v);
369  if (rcs_topology==TOPOLOGY_S)
371 
372  AddVariable2CS(&v,rcs_cuiksystem);
373 
374  DeleteVariable(&v);
375  free($1);
376  }
377  ;
378 
379 system_eqs : _SYSTEM_EQS
380  {
381  rcs_eq_type=SYSTEM_EQ;
382  }
383  eq_list
384  meq_list
385  |
386  ;
387 
388 coord_eqs : _COORD_EQS
389  {
390  rcs_eq_type=COORD_EQ;
391  }
392  eq_list
393  |
394  ;
395 
396 dummy_eqs : _DUMMY_EQS
397  {
398  rcs_eq_type=DUMMY_EQ;
399  }
400  eq_list
401  |
402  ;
403 
404 search: _SEARCH
405  search_type
406  |
407  {
408  SetCSSearchMode(DEPTH_FIRST_SEARCH,NULL,rcs_cuiksystem);
409  }
410  ;
411 
412 search_type: _DEPTH _FIRST
413  {
414  SetCSSearchMode(DEPTH_FIRST_SEARCH,NULL,rcs_cuiksystem);
415  }
416  | _BREADTH _FIRST
417  {
418  SetCSSearchMode(BREADTH_FIRST_SEARCH,NULL,rcs_cuiksystem);
419  }
420  | _MIN monomials
421  {
422  SetEquationType(SYSTEM_EQ,&rcs_equation);
423  SetEquationCmp(EQU,&rcs_equation);
424  SetCSSearchMode(MINIMIZATION_SEARCH,&(rcs_equation),rcs_cuiksystem);
425  ResetEquation(&rcs_equation);
426  }
427  ;
428 
429 eq_list: equation
430  {
431  AddEquation2CS(rcs_parameters,&rcs_equation,rcs_cuiksystem);
432 
433  /*Get ready for next equation definition*/
434  ResetEquation(&rcs_equation);
435  }
436  eq_list
437  |
438  ;
439 
440 equation: monomials cmp
441  {
442  rcs_sgn=-1.0;
443  }
444  monomials ';'
445  {
446  SetEquationType(rcs_eq_type,&rcs_equation);
447  SetEquationCmp($2,&rcs_equation);
448 
449  rcs_sgn=1.0;
450  }
451  ;
452 
453 monomials : opt_sign monomial
454  {
455  AddCt2Monomial(rcs_sgn,&rcs_monomial);
456  AddMonomial(&rcs_monomial,&rcs_equation);
457  ResetMonomial(&rcs_monomial);
458 
459 
460  }
461  more_monomials
462  ;
463 
464 more_monomials: sign monomial
465  {
466  AddCt2Monomial(rcs_sgn,&rcs_monomial);
467  AddMonomial(&rcs_monomial,&rcs_equation);
468  ResetMonomial(&rcs_monomial);
469  }
470  more_monomials
471  |
472  ;
473 
474 opt_sign : sign
475  |
476  ;
477 
478 sign : '+'
479  | '-'
480  {
481  AddCt2Monomial(-1.0,&rcs_monomial);
482  }
483  ;
484 
485 monomial : item '*' monomial
486  | item
487  ;
488 
489 item : _REAL power
490  {
491  if ($2==1)
492  AddCt2Monomial($1,&rcs_monomial);
493  else
494  AddCt2Monomial(pow($1,(double)$2),&rcs_monomial);
495  }
496  | _INTEGER power
497  {
498  if ($2==1)
499  AddCt2Monomial((double)$1,&rcs_monomial);
500  else
501  AddCt2Monomial(pow((double)$1,(double)$2),&rcs_monomial);
502  }
503  | _SIN '(' expr ')' power
504  {
505  if ($3.id!=NULL)
506  {
507  unsigned int id;
508 
509  id=GetCSVariableID($3.id,rcs_cuiksystem);
510  if (id!=NO_UINT) /*a known variable*/
511  AddVariable2Monomial(SINV,id,$5,&rcs_monomial);
512  else
513  {
514  char s[300];
515 
516  sprintf(s,"Unknown variable %s",$3.id);
518  }
519  free($3.id);
520  }
521  else
522  {
523  if ($5==1)
524  AddCt2Monomial(sin($3.value),&rcs_monomial);
525  else
526  AddCt2Monomial(pow(sin($3.value),(double)$5),&rcs_monomial);
527  }
528  }
529  | _COS '(' expr ')' power
530  {
531  if ($3.id!=NULL)
532  {
533  unsigned int id;
534 
535  id=GetCSVariableID($3.id,rcs_cuiksystem);
536  if (id!=NO_UINT) /*a known variable*/
537  AddVariable2Monomial(COSV,id,$5,&rcs_monomial);
538  else
539  {
540  char s[300];
541 
542  sprintf(s,"Unknown variable %s",$3.id);
544  }
545  free($3.id);
546  }
547  else
548  {
549  if ($5==1)
550  AddCt2Monomial(cos($3.value),&rcs_monomial);
551  else
552  AddCt2Monomial(pow(cos($3.value),(double)$5),&rcs_monomial);
553  }
554  }
555  | _TAN '(' expr ')' power
556  {
557  if ($3.id!=NULL)
558  {
559  unsigned int id;
560 
561  id=GetCSVariableID($3.id,rcs_cuiksystem);
562  if (id!=NO_UINT) /*a known variable*/
563  AddVariable2Monomial(TANV,id,$5,&rcs_monomial);
564  else
565  {
566  char s[300];
567 
568  sprintf(s,"Unknown variable %s",$3.id);
570  }
571  free($3.id);
572  }
573  else
574  {
575  if ($5==1)
576  AddCt2Monomial(tan($3.value),&rcs_monomial);
577  else
578  AddCt2Monomial(pow(tan($3.value),(double)$5),&rcs_monomial);
579  }
580  }
581  | _EXP '(' expr ')' power
582  {
583  if ($3.id!=NULL)
584  {
585  unsigned int id;
586 
587  id=GetCSVariableID($3.id,rcs_cuiksystem);
588  if (id!=NO_UINT) /*a known variable*/
589  AddVariable2Monomial(EXPV,id,$5,&rcs_monomial);
590  else
591  {
592  char s[300];
593 
594  sprintf(s,"Unknown variable %s",$3.id);
596  }
597  free($3.id);
598  }
599  else
600  {
601  if ($5==1)
602  AddCt2Monomial(exp($3.value),&rcs_monomial);
603  else
604  AddCt2Monomial(pow(exp($3.value),(double)$5),&rcs_monomial);
605  }
606  }
607  | _PWP '(' expr ')' power
608  {
609  if ($3.id!=NULL)
610  {
611  unsigned int id;
612 
613  id=GetCSVariableID($3.id,rcs_cuiksystem);
614  if (id!=NO_UINT) /*a known variable*/
615  AddVariable2Monomial(PWPV,id,$5,&rcs_monomial);
616  else
617  {
618  char s[300];
619 
620  sprintf(s,"Unknown variable %s",$3.id);
622  }
623  free($3.id);
624  }
625  else
626  {
627  double v;
628 
629  if ($3.value<0.0)
630  v=$3.value*$3.value;
631  else
632  v=0.0;
633 
634  if ($5==1)
635  AddCt2Monomial(v,&rcs_monomial);
636  else
637  AddCt2Monomial(pow(v,(double)$5),&rcs_monomial);
638  }
639  }
640  | _IDENTIFIER power
641  {
642  unsigned int id;
643  unsigned int nc;
644 
645  nc=GetConstantWithName($1,rcs_constants);
646 
647  if (nc!=NO_UINT)
648  AddCt2Monomial(pow(GetConstantValue(nc,rcs_constants),(double)($2)),&rcs_monomial);
649  else
650  {
651  id=GetCSVariableID($1,rcs_cuiksystem);
652  if (id!=NO_UINT) /*a known variable*/
653  AddVariable2Monomial(NFUN,id,$2,&rcs_monomial);
654  else
655  {
656  char s[300];
657 
658  sprintf(s,"Unknown variable or constant %s",$1);
660  }
661  }
662  free($1);
663  }
664  ;
665 
666 power : '^' _INTEGER
667  {
668  $$=$2;
669  }
670  |
671  {
672  $$=1;
673  }
674  ;
675 
676 cmp : _EQU
677  {
678  $$=EQU;
679  }
680  | _LEQ
681  {
682  $$=LEQ;
683  }
684  | _GEQ
685  {
686  $$=GEQ;
687  }
688  ;
689 
690 meq_list: mequation _EQU _ID ';'
691  {
692  SimplifyMEquation(&rcs_mequation);
693  AddMatrixEquation2CS(rcs_parameters,&rcs_mequation,rcs_cuiksystem);
694 
695  ResetMEquation(&rcs_mequation);
696  }
697  meq_list
698  |
699  ;
700 mequation : mitem '*' mequation
701  | mitem
702  ;
703 
704 mitem: _T '(' expr ',' expr ',' expr ',' expr ';' expr ',' expr ',' expr ',' expr ';' expr ',' expr ',' expr ',' expr ')' opt_invert
705  {
706  THTransform t;
707 
708  if (($3.id!=NULL)||($5.id!=NULL)||($7.id!=NULL)||($9.id!=NULL)||
709  ($11.id!=NULL)||($13.id!=NULL)||($15.id!=NULL)||($17.id!=NULL)||
710  ($19.id!=NULL)||($21.id!=NULL)||($23.id!=NULL)||($25.id!=NULL))
711  ReadcuiksystemSemanticError("Error defining a constant transform");
712 
713  HTransformIdentity(&t);
714 
715  HTransformSetElement(0,0,$3.value,&t);
716  HTransformSetElement(0,1,$5.value,&t);
717  HTransformSetElement(0,2,$7.value,&t);
718  HTransformSetElement(0,3,$9.value,&t);
719  HTransformSetElement(1,0,$11.value,&t);
720  HTransformSetElement(1,1,$13.value,&t);
721  HTransformSetElement(1,2,$15.value,&t);
722  HTransformSetElement(1,3,$17.value,&t);
723  HTransformSetElement(2,0,$19.value,&t);
724  HTransformSetElement(2,1,$21.value,&t);
725  HTransformSetElement(2,2,$23.value,&t);
726  HTransformSetElement(2,3,$25.value,&t);
727 
728  if ($27<0)
729  HTransformInverse(&t,&t);
730 
731  AddCtTrans2MEquation(&t,&rcs_mequation);
732 
733  HTransformDelete(&t);
734  }
735  | _TV '(' expr ',' expr ',' expr ',' expr ')' opt_invert
736  {
737  unsigned int nv,nc;
738  double ctValue;
739  boolean constant;
740 
741  /* Translation along a vector */
742 
743  if (($3.id!=NULL)||($5.id!=NULL)||($7.id!=NULL))
744  ReadcuiksystemSemanticError("Error defining a TV transform");
745 
746  constant=FALSE;
747  if ($9.id==NULL)
748  {
749  constant=TRUE;
750  ctValue=(double)$11*$9.value;
751  }
752  else
753  {
754  nc=GetConstantWithName($9.id,rcs_constants);
755  if (nc!=NO_UINT)
756  {
757  constant=TRUE;
758  ctValue=(double)$11*GetConstantValue(nc,rcs_constants);
759  }
760  }
761 
762  if (constant)
763  {
764  /* Actually defining a ct transform */
765  THTransform t;
766 
767  HTransformTxyz(ctValue*$3.value,ctValue*$5.value,ctValue*$7.value,&t);
768  AddCtTrans2MEquation(&t,&rcs_mequation);
769  HTransformDelete(&t);
770  }
771  else
772  {
773  nv=GetCSVariableID($9.id,rcs_cuiksystem);
774 
775  rcs_vect[0]=$3.value;
776  rcs_vect[1]=$5.value;
777  rcs_vect[2]=$7.value;
778 
779  AddDispTrans2MEquation($11,nv,rcs_vect,&rcs_mequation);
780  }
781  if ($9.id!=NULL)
782  free($9.id);
783  }
784  | trans_type '(' expr ')' opt_invert
785  {
786  unsigned int nv,nc;
787  double ctValue;
788  boolean constant;
789 
790  constant=FALSE;
791  if ($3.id==NULL)
792  {
793  constant=TRUE;
794  ctValue=(double)$5*$3.value;
795  }
796  else
797  {
798  nc=GetConstantWithName($3.id,rcs_constants);
799  if (nc!=NO_UINT)
800  {
801  constant=TRUE;
802  ctValue=(double)$5*GetConstantValue(nc,rcs_constants);
803  }
804  }
805 
806  if (constant)
807  {
808  /* Actually defining a ct transform */
809  THTransform t;
810 
811  if (($1!=TX)&&($1!=TY)&&($1!=TZ)&&($1!=RX)&&($1!=RY)&&($1!=RZ))
812  ReadcuiksystemSemanticError("Only basic transforms (Tx,Ty,Tz,Rx,Ry,Rz) can be set to constant");
813 
814  HTransformCreate($1,ctValue,&t);
815  AddCtTrans2MEquation(&t,&rcs_mequation);
816  HTransformDelete(&t);
817  }
818  else
819  {
820  nv=GetCSVariableID($3.id,rcs_cuiksystem);
821  AddVarTrans2MEquation($1,$5,nv,&rcs_mequation);
822  }
823  if ($3.id!=NULL)
824  free($3.id);
825  }
826  | patch_type '(' four_points ';' _IDENTIFIER ',' _IDENTIFIER ')' opt_invert
827  {
828  unsigned int u,v;
829 
830  u=GetCSVariableID($5,rcs_cuiksystem);
831  if (u==NO_UINT)
832  {
833  char s[300];
834 
835  sprintf(s,"Undefined variable %s",$5);
837  }
838 
839  v=GetCSVariableID($7,rcs_cuiksystem);
840  if (v==NO_UINT)
841  {
842  char s[300];
843 
844  sprintf(s,"Undefined variable %s",$7);
846  }
847 
848  AddPatchTrans2MEquation($1,$9,u,v,rcs_point,&rcs_mequation);
849  }
850  ;
851 
852 opt_invert : _INV
853  {
854  $$=-1;
855  }
856  |
857  {
858  $$=1;
859  }
860  ;
861 
862 trans_type : _TX
863  {
864  $$=TX;
865  }
866  | _TY
867  {
868  $$=TY;
869  }
870  | _TZ
871  {
872  $$=TZ;
873  }
874  | _RX
875  {
876  $$=RX;
877  }
878  | _RY
879  {
880  $$=RY;
881  }
882  | _RZ
883  {
884  $$=RZ;
885  }
886  | _DRX
887  {
888  $$=dRX;
889  }
890  | _DRY
891  {
892  $$=dRY;
893  }
894  | _DRZ
895  {
896  $$=dRZ;
897  }
898  | _DDRX
899  {
900  $$=ddRX;
901  }
902  | _DDRY
903  {
904  $$=ddRY;
905  }
906  | _DDRZ
907  {
908  $$=ddRZ;
909  }
910  ;
911 
912 patch_type : _PA
913  {
914  $$=PA;
915  }
916  | _DPA_U
917  {
918  $$=dPA_U;
919  }
920  | _DPA_V
921  {
922  $$=dPA_V;
923  }
924  | _DDPA_UU
925  {
926  $$=ddPA_UU;
927  }
928  | _DDPA_UV
929  {
930  $$=ddPA_UV;
931  }
932  | _DDPA_VV
933  {
934  $$=ddPA_VV;
935  }
936  ;
937 
938 four_points : expr ',' expr ',' expr ';' expr ',' expr ',' expr ';' expr ',' expr ',' expr ';' expr ',' expr ',' expr
939  {
940  if (($1.id!=NULL)||($3.id!=NULL)||($5.id!=NULL)||
941  ($7.id!=NULL)||($9.id!=NULL)||($11.id!=NULL)||
942  ($13.id!=NULL)||($15.id!=NULL)||($17.id!=NULL)||
943  ($19.id!=NULL)||($21.id!=NULL)||($23.id!=NULL))
944  ReadcuiksystemSemanticError("Error defining a patch transform");
945 
946  rcs_point[0][0]=$1.value;
947  rcs_point[0][1]=$3.value;
948  rcs_point[0][2]=$5.value;
949 
950  rcs_point[1][0]=$7.value;
951  rcs_point[1][1]=$9.value;
952  rcs_point[1][2]=$11.value;
953 
954  rcs_point[2][0]=$13.value;
955  rcs_point[2][1]=$15.value;
956  rcs_point[2][2]=$17.value;
957 
958  rcs_point[3][0]=$19.value;
959  rcs_point[3][1]=$21.value;
960  rcs_point[3][2]=$23.value;
961  }
962  ;
963 
964 %%
966 /*
967  * Reads a file containing the constants definitions, kinematic equations to be solved,
968  * and the range constrains for the variables.
969  */
970 void InitCuikSystemFromFile(Tparameters *p,char *filename,TCuikSystem *cs)
971 {
972 
973  /*Start the data structures*/
974  InitCuikSystem(cs);
975 
976  /*Add information to the data structure */
977  AddCuikSystemFromFile(p,filename,cs);
978 }
979 
980 void AddCuikSystemFromFile(Tparameters *p,char *filename,TCuikSystem *cs)
981 {
982  unsigned int i;
983 
984  rcs_parameters=p;
985 
986  Readcuiksystemin=fopen(filename,"r");
987  if (!Readcuiksystemin)
988  {
989  char ErrorText[500];
990 
991  sprintf(ErrorText,"File %s does not exists",filename);
992  Error(ErrorText);
993  }
994 
995  rcs_constants=&(cs->constants);
996 
997  /*Reset the lines numbering*/
998  RCSline=1;
999 
1000  /*we initalize the global pointer to make the parameters accesibles to any one inside the YACC module*/
1001  rcs_cuiksystem=cs;
1002 
1003  /*Get ready for first equation*/
1004  InitEquation(&rcs_equation);
1005  InitMEquation(&rcs_mequation);
1006  InitMonomial(&rcs_monomial);
1007 
1008  /* space for points */
1009  NEW(rcs_point,4,double *);
1010  for(i=0;i<4;i++)
1011  { NEW(rcs_point[i],3,double); }
1012 
1013  /*and process the file*/
1014  Readcuiksystemparse();
1015 
1016  /* and release structures */
1017  for(i=0;i<4;i++)
1018  free(rcs_point[i]);
1019  free(rcs_point);
1020 
1021  DeleteEquation(&rcs_equation);
1022  DeleteMEquation(&rcs_mequation);
1023  DeleteMonomial(&rcs_monomial);
1024 
1025  cs->updated=FALSE;
1026  fclose(Readcuiksystemin);
1027 }
1028 
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:140
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:1013
#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:1748
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:2511
#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:201
#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:89
#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:81
#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:70
#define TRUE
TRUE.
Definition: boolean.h:21
#define LEQ
In a Tequation, the equation relational operator is less equal.
Definition: equation.h:195
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:2490
#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:299
#define COSV
Cosine of the variable.
Definition: variable_set.h:50
Matrix equation.
Definition: mequation.h:38
void AddMonomial(Tmonomial *f, Tequation *eq)
Adds a new monomial to the equation.
Definition: equation.c:1356
#define GEQ
In a Tequation, the equation relational operator is great equal.
Definition: equation.h:189
#define ddPA_UU
Double derivative of a PA transform.
Definition: trans_seq.h:95
#define ROUND2SYMBOL(a)
Round to +/-PI, +/-PI/2.
Definition: defines.h:362
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:1018
#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:468
#define TX
One of the types of homogeneous transforms in R^3.
Definition: htransform.h:35
An equation.
Definition: equation.h:236
void DeleteVariable(Tvariable *v)
Destructor.
Definition: variable.c:95
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.
void NewVariable(unsigned int type, char *name, Tvariable *v)
Constructor.
Definition: variable.c:21
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:2155
void AddEquation2CS(Tparameters *p, Tequation *eq, TCuikSystem *cs)
Adds an equation to the system.
Definition: cuiksystem.c:2481
#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:44
void HTransformDelete(THTransform *t)
Destructor.
Definition: htransform.c:833
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
#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:306
#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:2418
unsigned int GetCSVariableID(char *name, TCuikSystem *cs)
Gets the numerical identifier of a variable given its name.
Definition: cuiksystem.c:2586
void HTransformCreate(unsigned int dof_r3, double v, THTransform *t)
Constructor.
Definition: htransform.c:272
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:432
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.