Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define DIM_NASTRO 15
- void stampa_nastro(int* nastro, int dim_nastro, int* cur_start, int* cursore){
- int i;
- for(i = 0; i < dim_nastro; i++)
- printf("|%3d", nastro[i]);
- printf("\n");
- int cur_pos = ((int) (cursore - cur_start) )*4;
- for(i = 0; i < cur_pos; i++)
- printf(" ");
- printf(" ^");
- printf("\n");
- }
- int main()
- {
- // adder
- //char codice[] = "++>+++++[->+<]>.";
- // multiplier
- //char codice[] = "+++++[->+++<]>.";
- // hello world
- char codice[] = "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.";
- // hello world but shorter (doesnt work yet)
- //char codice[] = "--<-<<+[+[<+>--->->->-<<<]>]<<--.<++++++.<<-..<<.<+.>>.>>.<<<.+++.>>.>>-.<<<+.";
- char* istr_ptr = codice;
- int nastro[DIM_NASTRO] = {0};
- int* cursore = nastro;
- //cursore += DIM_NASTRO / 2;
- int par_count;
- while(*istr_ptr){
- //printf("istruzione: %c\n", *istr_ptr);
- switch(*istr_ptr){
- case '+':
- (*cursore)++;
- break;
- case '-':
- (*cursore)--;
- break;
- case '>':
- cursore++;
- break;
- case '<':
- cursore--;
- break;
- case '[':
- par_count = 1;
- if(*cursore == 0){
- istr_ptr++;
- while(par_count != 0){
- if(*istr_ptr == '[') par_count++;
- if(*istr_ptr == ']') par_count--;
- if(par_count == 0) break;
- istr_ptr++;
- }
- }
- break;
- case ']':
- par_count = 1;
- if(*cursore != 0){
- istr_ptr--;
- while(par_count != 0){
- if(*istr_ptr == '[') par_count--;
- if(par_count == 0) break;
- if(*istr_ptr == ']') par_count++;
- istr_ptr--;
- }
- }
- break;
- case '.':
- printf("STDOUT: %3d %c\n", *cursore, (char) *cursore);
- break;
- case ',':
- scanf("%d", cursore);
- while(getchar() != '\n');
- break;
- }
- istr_ptr++;
- //stampa_nastro(nastro, DIM_NASTRO, nastro, cursore);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment