readparameters.y
Go to the documentation of this file.00001 %{
00003 #include "parameters.h"
00004 #include "error.h"
00005 #include "boolean.h"
00006 #include "defines.h"
00007
00008 #include <stdlib.h>
00009 #include <stdio.h>
00010
00011 Tparameters *rp_ps;
00012
00013
00014
00015 extern FILE *ReadParametersin;
00016
00017
00018 int ReadParameterslex(void);
00019
00020
00021 extern unsigned int RPNline;
00022
00023 %}
00024
00025 %union
00026 {
00027 int int_number;
00028 double real_number;
00029 }
00030
00031 %start parameters
00032
00033 %token _TRUE _FALSE _INF _EPSILON _SIGMA _SMALL_SIGMA _RHO _STATE_PERIOD _DUMMIFY _ERROR_SPLIT _SAFE_SIMPLEX _SIMPLIFICATION_LEVEL _LR2TM_Q _LR2TM_S
00034
00035 %token <int_number> _INTEGER
00036 %token <real_number> _REAL
00037
00038 %type <real_number> ct_expr
00039 %type <real_number> boolean_value
00040
00041 %left _MIN_PRECEDENCE
00042 %left '+' '-'
00043 %left '*' '/'
00044 %right _MAX_PRECEDENCE
00045
00046 %%
00047
00048 parameters : parameter parameters
00049 |
00050 ;
00051
00052 parameter : _EPSILON '=' ct_expr
00053 {
00054 if ($3<0.0)
00055 Error("Parameter EPSILON must be greater than (or equal to) 0.0");
00056 SetParameter(CT_EPSILON,"Epsilon",$3,rp_ps);
00057 }
00058 | _RHO '=' ct_expr
00059 {
00060 if (($3>0.0)&&($3<1.0))
00061 SetParameter(CT_RHO,"Rho",$3,rp_ps);
00062 else
00063 Error("Parameter RHO must in the interval (0,1)");
00064 }
00065 | _SIGMA '=' ct_expr
00066 {
00067 if ($3<0.0)
00068 Error("Parameter SIGMA must be greater than (or equal to) 0.0");
00069 SetParameter(CT_SIGMA,"Sigma",$3,rp_ps);
00070 }
00071 | _SMALL_SIGMA '=' ct_expr
00072 {
00073 if ($3<0.0)
00074 Error("Parameter SMALL SIGMA must be greater than (or equal to) 0.0");
00075 SetParameter(CT_SMALL_SIGMA,"Small Sigma",$3,rp_ps);
00076 }
00077 | _STATE_PERIOD '=' ct_expr
00078 {
00079 if ($3<0)
00080 Error("Parameter STATE_PERIOD must be greater than (or equal to) 0");
00081 SetParameter(CT_STATE_PERIOD,"Period between state files",$3,rp_ps);
00082 }
00083 | _DUMMIFY '=' ct_expr
00084 {
00085 SetParameter(CT_DUMMIFY,"Dummification Level",$3,rp_ps);
00086 }
00087 | _ERROR_SPLIT '=' boolean_value
00088 {
00089 SetParameter(CT_SPLIT_TYPE,"Error Split ",$3,rp_ps);
00090 }
00091 | _SAFE_SIMPLEX '=' ct_expr
00092 {
00093 SetParameter(CT_SAFE_SIMPLEX,"Save Simplex",$3,rp_ps);
00094 }
00095 | _SIMPLIFICATION_LEVEL '=' ct_expr
00096 {
00097 SetParameter(CT_SIMPLIFICATION_LEVEL,"Simplification Level",$3,rp_ps);
00098 }
00099 | _LR2TM_Q '=' ct_expr
00100 {
00101 SetParameter(CT_LR2TM_Q,"LR2TM_Q",$3,rp_ps);
00102 }
00103 | _LR2TM_S '=' ct_expr
00104 {
00105 SetParameter(CT_LR2TM_S,"LR2TM_S",$3,rp_ps);
00106 }
00107 ;
00108
00109 boolean_value : _TRUE
00110 {
00111 $$=1.0;
00112 }
00113 | _FALSE
00114 {
00115 $$=0.0;
00116 }
00117 ;
00118
00119 ct_expr : '+' ct_expr %prec _MAX_PRECEDENCE
00120 {
00121 $$=$2;
00122 }
00123 | '-' ct_expr %prec _MAX_PRECEDENCE
00124 {
00125 $$=-$2;
00126 }
00127 | ct_expr '+' ct_expr
00128 {
00129 $$=$1+$3;
00130 }
00131 | ct_expr '-' ct_expr
00132 {
00133 $$=$1-$3;
00134 }
00135 | ct_expr '*' ct_expr
00136 {
00137 $$=$1*$3;
00138 }
00139 | ct_expr '/' ct_expr
00140 {
00141 $$=$1/$3;
00142 }
00143 | '(' ct_expr ')'
00144 {
00145 $$=$2;
00146 }
00147 | _INF
00148 {
00149 $$=(double)INF;
00150 }
00151
00152 | _INTEGER
00153 {
00154 $$=(double)$1;
00155 }
00156 | _REAL
00157 {
00158 $$=$1;
00159 }
00160 ;
00161
00162 %%
00164 boolean ReadParameters(char *file,Tparameters *p)
00165 {
00166 unsigned int i;
00167 boolean fileExists;
00168
00169 ReadParametersin=fopen(file,"r");
00170 if (!ReadParametersin)
00171 fileExists=FALSE;
00172 else
00173 {
00174 fileExists=TRUE;
00175
00176
00177
00178 rp_ps=p;
00179
00180
00181 RPNline=1;
00182
00183
00184 ReadParametersparse();
00185
00186 for(i=0;i<NPARAMETERS;i++)
00187 {
00188 if ((*p)[i].name==NULL)
00189 {
00190 char ErrorText[200];
00191
00192 sprintf(ErrorText,"Parameter number %u is undefined (see sources/parameters.h to see parameter numbering)",i);
00193 Error(ErrorText);
00194 }
00195 }
00196
00197 if (GetParameter(CT_SMALL_SIGMA,p)>GetParameter(CT_SIGMA,p))
00198 Error("SMALL_SIGMA can not be larger than SIGMA!!!");
00199
00200 if (GetParameter(CT_EPSILON,p)>GetParameter(CT_SIGMA,p))
00201 Error("EPSILON can not be larger than SIGMA!!!");
00202
00203 fclose(ReadParametersin);
00204 }
00205
00206 return(fileExists);
00207 }