| 159 | //========================================================================== |
| 160 | |
| 161 | static FProduction *ParseExpression (FCommandLine &argv, int &parsept) |
| 162 | { |
| 163 | if (parsept >= argv.argc()) |
| 164 | return NULL; |
| 165 | |
| 166 | const char *token = argv[parsept++]; |
| 167 | FProduction *prod1 = NULL, *prod2 = NULL, *prod3 = NULL; |
| 168 | |
| 169 | if (IsFloat (token)) |
| 170 | { |
| 171 | return NewDoubleProd (atof(token)); |
| 172 | } |
| 173 | else if (stricmp (token, "true") == 0) |
| 174 | { |
| 175 | return NewDoubleProd (1.0); |
| 176 | } |
| 177 | else if (stricmp (token, "false") == 0) |
| 178 | { |
| 179 | return NewDoubleProd (0.0); |
| 180 | } |
| 181 | else |
| 182 | { |
| 183 | for (size_t i = 0; i < countof(Producers); ++i) |
| 184 | { |
| 185 | if (strcmp (Producers[i].Token, token) == 0) |
| 186 | { |
| 187 | prod1 = ParseExpression (argv, parsept); |
| 188 | prod2 = ParseExpression (argv, parsept); |
| 189 | if (prod1 == NULL || prod2 == NULL) |
| 190 | { |
| 191 | goto missing; |
| 192 | } |
| 193 | if (Producers[i].StringProducer == NULL) |
| 194 | { |
| 195 | DoubleCoerce (prod1, prod2); |
| 196 | } |
| 197 | else if (Producers[i].DoubleProducer == NULL) |
| 198 | { |
| 199 | MustStringCoerce (prod1, prod2); |
| 200 | } |
| 201 | else |
| 202 | { |
| 203 | MaybeStringCoerce (prod1, prod2); |
| 204 | } |
| 205 | if (prod1->Type == PROD_String) |
| 206 | { |
| 207 | prod3 = Producers[i].StringProducer ((FStringProd *)prod1, (FStringProd *)prod2); |
| 208 | } |
| 209 | else |
| 210 | { |
| 211 | prod3 = Producers[i].DoubleProducer ((FDoubleProd *)prod1, (FDoubleProd *)prod2); |
| 212 | } |
| 213 | goto done; |
| 214 | } |
| 215 | } |
| 216 | if (strcmp ("!", token) == 0) |
| 217 | { |
| 218 | prod1 = ParseExpression (argv, parsept); |
no test coverage detected