Résultat du TP en C sur Forth
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

exec.c 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include "exec.h"
  2. #include "pile.h"
  3. #include "functions.h"
  4. #include <stdlib.h>
  5. #include <ctype.h>
  6. #include <stdio.h>
  7. #include <string.h>
  8. void execute(struct State *state, struct CmdList* cmds) {
  9. struct NumContainer num1;
  10. char* instruction;
  11. while (state->instructionPointer < (programPointer) state->prog->taille) {
  12. instruction = getCurrentToken(state);
  13. if (state->mode == EXECUTE) {
  14. if ( isdigit(instruction[0]) ) {
  15. num1 = readNum(instruction);
  16. push(&(state->pile), num1);
  17. } else if ( !tryCallCmds( cmds, instruction, state ) ) {
  18. if (!tryCallFunctions(instruction, state)) {
  19. fprintf(stderr, "%s is not a known symbol\n", instruction);
  20. exit(1);
  21. }
  22. }
  23. } else if (state->mode == PRINT){
  24. if (!strncmp(instruction, "\"", 2)) {
  25. state->mode = EXECUTE;
  26. } else {
  27. printf("%s ", instruction);
  28. }
  29. } else {
  30. tryCallCmds(cmds, instruction, state);
  31. }
  32. ++(state->instructionPointer);
  33. }
  34. }