back to scratko.xyz
aboutsummaryrefslogtreecommitdiff
path: root/arith_exp.c
diff options
context:
space:
mode:
Diffstat (limited to 'arith_exp.c')
-rw-r--r--arith_exp.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/arith_exp.c b/arith_exp.c
index 8a4c002..c38c821 100644
--- a/arith_exp.c
+++ b/arith_exp.c
@@ -4,18 +4,18 @@
char buffer[BUF_SIZE];
-enum {
+enum {
success = 1,
error = -1,
base = 10
};
enum state { yes, no };
-static int is_higher_priority(const stack *operation_stack,
+static int is_higher_priority(const stack *operation_stack,
int current_operation)
{
int prev_operation = top_stack(operation_stack);
- return (prev_operation == '+' || prev_operation == '-') &&
+ return (prev_operation == '+' || prev_operation == '-') &&
(current_operation == '*' || current_operation == '/');
}
@@ -41,7 +41,7 @@ static void make_operation(stack *rpn_stack, int operation)
push_stack(rpn_stack, result);
}
-static long translate_to_number(const char *begin_address, int size,
+static long translate_to_number(const char *begin_address, int size,
enum state is_negative_number)
{
long number = 0;
@@ -57,7 +57,7 @@ static long translate_to_number(const char *begin_address, int size,
return number;
}
-static int extract_digit(const char *buf, long *number, int buf_length,
+static int extract_digit(const char *buf, long *number, int buf_length,
int *pos)
{
enum state is_negative_number = no;
@@ -79,14 +79,14 @@ static int extract_digit(const char *buf, long *number, int buf_length,
else
return error;
case ')':
- if(is_negative_number == yes &&
+ if(is_negative_number == yes &&
is_end_negative_expression == no)
{
is_end_negative_expression = yes;
continue;
}
- *number =
- translate_to_number(begin_address, number_length,
+ *number =
+ translate_to_number(begin_address, number_length,
is_negative_number == yes ? yes : no);
return ')';
case '+':
@@ -95,7 +95,7 @@ static int extract_digit(const char *buf, long *number, int buf_length,
case '/':
case '\n':
if(is_negative_number == yes || is_positive_number == yes) {
- *number = translate_to_number(begin_address, number_length,
+ *number = translate_to_number(begin_address, number_length,
is_negative_number == yes ? yes : no);
return success;
} else
@@ -117,7 +117,7 @@ static int extract_digit(const char *buf, long *number, int buf_length,
static void clean_operation_stack(stack *operation_stack, stack *rpn_stack)
{
int operation;
- while(!is_empty_stack(operation_stack) &&
+ while(!is_empty_stack(operation_stack) &&
top_stack(operation_stack) != '(')
{
operation = pop_stack(operation_stack);
@@ -158,7 +158,7 @@ static void print_number(stack *rpn_stack)
sys_write(1, string, i);
}
-static void buffer_process(const char* buffer, int length, stack *rpn_stack,
+static void buffer_process(const char *buffer, int length, stack *rpn_stack,
stack *operation_stack)
{
int top, pos, result;
@@ -175,7 +175,7 @@ static void buffer_process(const char* buffer, int length, stack *rpn_stack,
++pos;
continue;
}
- if(symbol == '\n' || symbol == ')' || symbol == '+' || symbol == '-' ||
+ if(symbol == '\n' || symbol == ')' || symbol == '+' || symbol == '-' ||
symbol == '*' || symbol == '/')
{
push_stack(rpn_stack, operand);
@@ -203,14 +203,14 @@ static void buffer_process(const char* buffer, int length, stack *rpn_stack,
case '*':
case '/':
top = top_stack(operation_stack);
- if(top == '(' ||
+ if(top == '(' ||
is_higher_priority(operation_stack, buffer[pos])) {
push_stack(operation_stack, buffer[pos]);
++pos;
continue;
}
else {
- while(top_stack(operation_stack) != '(' &&
+ while(top_stack(operation_stack) != '(' &&
!is_higher_priority(operation_stack, buffer[pos])) {
make_operation(rpn_stack, pop_stack(operation_stack));
}