X-Git-Url: https://secure.softndesign.org/git/?a=blobdiff_plain;f=parser.c;fp=parser.c;h=94f4c73fd0d752910b28d70ca02261c81446ea65;hb=20a645614be5667c1c32169e837b97c067156edb;hp=b9823abaa25f10acd08cc4f40e2667a2e94ea902;hpb=0e1e4e76ddae605f4d587bb7097f7bd86aa6ef16;p=calc.git diff --git a/parser.c b/parser.c index b9823ab..94f4c73 100644 --- a/parser.c +++ b/parser.c @@ -371,51 +371,48 @@ element_t *parser (char *str, char **next, int prio) /* look for number */ - if (((*str >= '0') && (*str <= '9')) || - (*str == '.') || (*str == '+') || (*str == '-')) { - VERBOSE (DEBUG, fprintf (stdout, "start processing value\n")); - char *pt; - double value = strtod (str, &pt); - VERBOSE (INFO, fprintf (stdout, "Value: %f\n", value)); - if (str != pt) { - if ((root == NULL) || (root->prio == 6)) { - new = newelement (Val, 1, 5); - new->value = value; - if (root == NULL) { - root = new; - } else { - for (i = 0; i < root->nbops; i++) { - if (root->ops[i] == NULL) { - root->ops[i] = new; - found = 1; - break; - } - } - if (!found) { - delelement (new); - delelement (root); - return ERROR_OP; + VERBOSE (DEBUG, fprintf (stdout, "start processing value\n")); + char *pt; + double value = (ibase == 10) ? strtod (str, &pt) : strtoul (str, &pt, ibase); + VERBOSE (INFO, fprintf (stdout, "Value: %f\n", value)); + if (str != pt) { + if ((root == NULL) || (root->prio == 6)) { + new = newelement (Val, 1, 5); + new->value = value; + if (root == NULL) { + root = new; + } else { + for (i = 0; i < root->nbops; i++) { + if (root->ops[i] == NULL) { + root->ops[i] = new; + found = 1; + break; } } - str = pt; - } else if ((*str == '+') || (*str == '-')) { - if ((prio) && (prio > 1)) { - VERBOSE (DEBUG, fprintf (stdout, "stop because operator priority\n")); - *next = str; - return root; - } - if (subparser (&root, &str, Add, 2, 1) == ERROR_OP) { + if (!found) { + delelement (new); delelement (root); return ERROR_OP; } - } else { + } + str = pt; + } else if ((*str == '+') || (*str == '-')) { + if ((prio) && (prio > 1)) { + VERBOSE (DEBUG, fprintf (stdout, "stop because operator priority\n")); + *next = str; + return root; + } + if (subparser (&root, &str, Add, 2, 1) == ERROR_OP) { delelement (root); return ERROR_OP; } - found = 1; + } else { + delelement (root); + return ERROR_OP; } - VERBOSE (DEBUG, fprintf (stdout, "stop processing value\n")); + found = 1; } + VERBOSE (DEBUG, fprintf (stdout, "stop processing value\n")); /* error */