-
Notifications
You must be signed in to change notification settings - Fork 1
/
monty.c
47 lines (45 loc) · 893 Bytes
/
monty.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
#include "monty.h"
/**
* exec_op - find and execute opcodes
*
* @args: arguments
* @h: head node
* @ltr: line number
*/
void exec_op(char **args, stack_t **h, int *ltr)
{
int i, *p_id;
instruction_t op[] = {
{"pint", _pint}, {"pall", _pall},
{"pop", _pop}, {"swap", _swap},
{"add", _add}, {"sub", _sub},
{"mul", _mul}, {"div", _div},
{"mod", _mod}, {"nop", _nop},
{"pchar", _pchar}, {"pstr", _pstr},
{"rotl", _rotl}, {"rotr", _rotr},
{"stack", _stack}, {"queue", _queue},
{NULL, NULL}};
if (strcmp("push", args[0]) == 0)
{
_push(h, args, *ltr);
}
else if (check_instruction(op, args))
{
fprintf(stderr, "L%d: unknown instruction %s\n", *ltr, args[0]);
free_dlistint(h);
p_id = &id;
*p_id = -1;
return;
}
else
{
for (i = 0; op[i].opcode; i++)
{
if (strcmp(op[i].opcode, args[0]) == 0)
{
(op[i].f)(h, *ltr);
break;
}
}
}
}