Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using namespace std;
- #include <iostream>
- #include <cmath>
- #include <cstring>
- void interpreta(char);
- void ciclo(const int);
- void azzera();
- void stampa(int *, int);
- void stampa(char *, int);
- const int MAXDIM = 100;
- int cont = 0;
- int * a = new int [MAXDIM];
- char * stringa = new char [1000];
- int main()
- {
- char c;
- int len;
- cin.get(c);
- while(c != '\n')
- {
- stringa[len] = c;
- cin.get(c);
- len++;
- }
- //stampa(stringa, len);
- azzera();
- for(int i = 0; i < len; i++)
- {
- interpreta(stringa[i]);
- }
- //stampa(a, MAXDIM);
- return 0;
- }
- void interpreta(char c)
- {
- //cout << c << " ";
- cout << cont << " ";
- switch(c)
- {
- case '>': cont++; break;
- case '<': cont--; break;
- case ';': cin >> a[cont]; break;
- case ':': cout << a[cont]; break;
- case '[': ciclo(cont); break;
- }
- }
- void ciclo(const int n)
- {
- char c = stringa[n+1];
- int len = 0;
- while(c != ']')
- {
- //cout << c;
- len++;
- c = stringa[n+len];
- }
- char * strciclo = new char [len];
- for(int i = 0; i < len; i++)
- strciclo[i] = a[n+i];
- //stampa(strciclo, len);
- while(a[n] > 0)
- {
- cont = n;
- for (int i = 0; i < strlen(strciclo); i++)
- interpreta(strciclo[i]);
- }
- }
- void azzera()
- {
- for(int i = 0; i < MAXDIM; i++)
- a[i] = 0;
- }
- void stampa(int * b, int l)
- {
- for (int i = 0; i < l; i++)
- cout << b[i];
- }
- void stampa(char * b, int l)
- {
- for (int i = 0; i < l; i++)
- cout << b[i];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement