-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser_execution.c
50 lines (49 loc) · 1.01 KB
/
parser_execution.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "monty.h"
/**
* run_ops - parses a string and runs opcodes
* @str: commands
* @head: pointer to head node of a linked list
* @ln_number: command line number
*/
void run_ops(char *str, stack_t **head, int *ln_number)
{
int i, flag;
char *opcode;
void (*operation)(stack_t **stack, unsigned int line_number);
i = flag = 0;
while (str[i] != '\0')
{
if (char_check(str[i]) == 0 && flag == 1)
{
fprintf(stderr, "L%d: usage: push integer\n", *ln_number);
exit(EXIT_FAILURE);
}
else if (char_check(str[i]) == 0 && flag == 0)
{
opcode = get_opcode(str, &i);
operation = get_op(opcode);
if (operation == NULL)
handle_error(*ln_number, opcode);
else
{
if (compare("push", opcode) == 0)
flag = 1;
else
{
operation(head, *ln_number);
free(opcode);
return;
}
}
free(opcode);
}
else if (isdigit(str[i]) && flag == 1)
{
globvar_value = get_argument(str, &i, *ln_number);
operation(head, *ln_number);
flag = 0;
return;
}
i++;
}
}