1234567891011121314151617181920212223242526272829303132333435363738 |
- #include "exec.h"
-
- #include "pile.h"
- #include "functions.h"
-
- #include <stdlib.h>
- #include <ctype.h>
- #include <stdio.h>
- #include <string.h>
-
-
- void execute(struct State *state, struct CmdList* cmds) {
- struct NumContainer num1;
- char* instruction;
- while (state->instructionPointer < (programPointer) state->prog->taille) {
- instruction = getCurrentToken(state);
- if (state->mode == EXECUTE) {
- if ( isdigit(instruction[0]) ) {
- num1 = readNum(instruction);
- push(&(state->pile), num1);
- } else if ( !tryCallCmds( cmds, instruction, state ) ) {
- if (!tryCallFunctions(instruction, state)) {
- fprintf(stderr, "%s is not a known symbol\n", instruction);
- exit(1);
- }
- }
- } else if (state->mode == PRINT){
- if (!strncmp(instruction, "\"", 2)) {
- state->mode = EXECUTE;
- } else {
- printf("%s ", instruction);
- }
- } else {
- tryCallCmds(cmds, instruction, state);
- }
- ++(state->instructionPointer);
- }
- }
|