Skip to content

Commit

Permalink
Fixed bug related to variable declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
Usbac committed Jul 10, 2020
1 parent b1e76f9 commit 8a168fa
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<p align="center">
<img src="https://img.shields.io/badge/stability-stable-green.svg">
<img src="https://img.shields.io/badge/version-2.6-blue.svg">
<img src="https://img.shields.io/badge/version-2.6.1-blue.svg">
<img src="https://img.shields.io/badge/license-MIT-orange.svg">
</p>

Expand Down
2 changes: 1 addition & 1 deletion src/main.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef MAIN_H_
#define MAIN_H_
#define OPERATION_BUFFER 512
#define VERSION_MSG "QUICH v2.6\n"
#define VERSION_MSG "QUICH v2.6.1\n"
#define INPUT_LINE "> "
#define DEFINITION_MSG "(definition)\n"
#define STATEMENT_SEPARATOR ";"
Expand Down
34 changes: 19 additions & 15 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ static double getValue(const char *str)
}


static double getOperationResult(const char *operator,
const char *a,
const char *b)
static double getOpResult(const char *operator,
const char *a,
const char *b)
{
double x = 0, y = 0;

Expand Down Expand Up @@ -372,7 +372,7 @@ static void pushResult(struct list *list, const struct token *node)
x = pop(list);
}

result = getOperationResult(node->value, x, y);
result = getOpResult(node->value, x, y);
if (precision >= 0) {
result = round_(result, precision);
}
Expand Down Expand Up @@ -426,6 +426,20 @@ static double getPostfixResult(const struct list *postfix)
}


static void replaceVariable(const char *key, const char *val)
{
struct variable *node = variables_first;

while (node != NULL) {
if (!strcmp(key, node->key)) {
strncpy_(node->value, val, strlen(val) + 1);
}

node = node->next;
}
}


void addVariable(const char *key, const char *val)
{
struct variable *node;
Expand All @@ -435,18 +449,8 @@ void addVariable(const char *key, const char *val)
return;
}

/* Replace value for an existing variable */
if (isVariable(key)) {
node = variables_first;

while (node != NULL) {
if (!strcmp(key, node->key)) {
strncpy_(node->value, val, strlen(val) + 1);
}

node = node->next;
}

replaceVariable(key, val);
return;
}

Expand Down
7 changes: 2 additions & 5 deletions src/tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ static enum TOKEN_TYPE getType(const char ch)
if (ch == '(' || ch == ')' ||
ch == '+' || ch == '-' ||
ch == '/' || ch == '*' ||
ch == '^' || ch == '!') {
ch == '^' || ch == '!' ||
ch == '=') {
return Operator;
}

Expand All @@ -38,10 +39,6 @@ static enum TOKEN_TYPE getType(const char ch)
return Word;
}

if (ch == '=') {
return Equal;
}

return None;
}

Expand Down
1 change: 0 additions & 1 deletion src/tokenizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ enum TOKEN_TYPE {
Operand,
Operator,
Word,
Equal,
None
};

Expand Down

0 comments on commit 8a168fa

Please sign in to comment.