-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparse_command.c
More file actions
45 lines (42 loc) · 855 Bytes
/
parse_command.c
File metadata and controls
45 lines (42 loc) · 855 Bytes
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
#include "monty.h"
/**
* parse_command - parses commands from the line op
* @stack: the pointer to the head of the stack
* @op: the line with commands/instructions
* @line_num: a number of the line
*
* Return: void
*/
void parse_command(stack_t **stack, char *op, unsigned int line_num)
{
int i;
instruction_t ops[] = {
{"push", push},
{"pall", pall},
{"pint", pint},
{"pop", pop},
{"swap", swap},
{"add", add},
{"nop", nop},
{"sub", sub},
{"div", _div},
{"mul", mul},
{"mod", mod},
{"pchar", pchar},
{"pstr", pstr},
{"rotl", rotl},
{"rotr", rotr},
{NULL, NULL}
};
for (i = 0; ops[i].opcode; i++)
if (strcmp(op, ops[i].opcode) == 0)
{
ops[i].f(stack, line_num);
return;
}
if (strlen(op) != 0 && op[0] != '#')
{
printf("L%u: unknown instruction %s\n", line_num, op);
exit(EXIT_FAILURE);
}
}