#include "naredba.hpp" #include using namespace std; void IspisS::izvrsi() const { cout << _s << endl; } Naredba* IspisS::kopija() const { return new IspisS(*this); } IspisE::~IspisE() { delete _i; } IspisE::IspisE(const IspisE& x) { _i = x._i->kopija(); } IspisE& IspisE::operator=(const IspisE& x) { if (this != &x) { delete _i; _i = x._i->kopija(); } return *this; } void IspisE::izvrsi() const { cout << _i->vrednost() << endl; } Naredba* IspisE::kopija() const { return new IspisE(*this); } void Blok::izvrsi() const { for(unsigned i = 0; i < _niz.size(); i++) _niz[i]->izvrsi(); } Blok::~Blok() { for(unsigned i = 0; i < _niz.size(); i++) delete _niz[i]; } Blok::Blok(const Blok& x) { for(unsigned i = 0; i < x._niz.size(); i++) _niz.push_back(x._niz[i]->kopija()); } Blok& Blok::operator=(const Blok& x) { if (this != &x) { for(unsigned i = 0; i < _niz.size(); i++) delete _niz[i]; _niz.resize(0); for(unsigned i = 0; i < x._niz.size(); i++) _niz.push_back(x._niz[i]->kopija()); } return *this; } Naredba* Blok::kopija() const { return new Blok(*this); } extern map tablica_simbola; void Dodela::izvrsi() const { tablica_simbola[_ime] = _i->vrednost(); } Dodela::~Dodela() { delete _i; } Dodela::Dodela(const Dodela& x) { _ime = x._ime; _i = x._i->kopija(); } Dodela& Dodela::operator=(const Dodela& x) { if (this != &x) { delete _i; _ime = x._ime; _i = x._i->kopija(); } return *this; } Naredba* Dodela::kopija() const { return new Dodela(*this); } Naredba* Unos::kopija() const { return new Unos(*this); } void Unos::izvrsi() const { int tmp; cin >> tmp; tablica_simbola[_ime] = tmp; } void AkoJeOndaInace::izvrsi() const { if (_uslov->vrednost() != 0) _n1->izvrsi(); else _n2->izvrsi(); } AkoJeOndaInace::~AkoJeOndaInace() { delete _uslov; delete _n1; delete _n2; } AkoJeOndaInace::AkoJeOndaInace(const AkoJeOndaInace& x) { _uslov = x._uslov->kopija(); _n1 = x._n1->kopija(); _n2 = x._n2->kopija(); } AkoJeOndaInace& AkoJeOndaInace::operator=(const AkoJeOndaInace& x) { if (this != &x) { delete _uslov; delete _n1; delete _n2; _uslov = x._uslov->kopija(); _n1 = x._n1->kopija(); _n2 = x._n2->kopija(); } return *this; } Naredba* AkoJeOndaInace::kopija() const { return new AkoJeOndaInace(*this); } void AkoJeOnda::izvrsi() const { if (_uslov->vrednost() != 0) _n1->izvrsi(); } AkoJeOnda::~AkoJeOnda() { delete _uslov; delete _n1; } AkoJeOnda::AkoJeOnda(const AkoJeOnda& x) { _uslov = x._uslov->kopija(); _n1 = x._n1->kopija(); } AkoJeOnda& AkoJeOnda::operator=(const AkoJeOnda& x) { if (this != &x) { delete _uslov; delete _n1; _uslov = x._uslov->kopija(); _n1 = x._n1->kopija(); } return *this; } Naredba* AkoJeOnda::kopija() const { return new AkoJeOnda(*this); } void DokJe::izvrsi() const { while (_uslov->vrednost() != 0) _n1->izvrsi(); } DokJe::~DokJe() { delete _uslov; delete _n1; } DokJe::DokJe(const DokJe& x) { _uslov = x._uslov->kopija(); _n1 = x._n1->kopija(); } DokJe& DokJe::operator=(const DokJe& x) { if (this != &x) { delete _uslov; delete _n1; _uslov = x._uslov->kopija(); _n1 = x._n1->kopija(); } return *this; } Naredba* DokJe::kopija() const { return new DokJe(*this); } void Prazna::izvrsi() const { //nista } Naredba* Prazna::kopija() const { return new Prazna(*this); } void IspisS::nazubi(int t) const { cout << string(t, '\t'); cout << "ispisi(\"" << _s << "\")"; } void IspisE::nazubi(int t) const { cout << string(t, '\t'); cout << "ispisi("; _i->ispisi(); cout << ")"; } void Blok::nazubi(int t) const { cout << string(t, '\t'); cout << "pocetak" << endl; for (unsigned i = 0; i < _niz.size(); i++) { _niz[i]->nazubi(t+1); if (i != _niz.size() - 1) cout << ";"; cout << endl; } cout << string(t, '\t'); cout << "kraj"; } void Dodela::nazubi(int t) const { cout << string(t, '\t'); cout << _ime << " := "; _i->ispisi(); } void Unos::nazubi(int t) const { cout << string(t, '\t'); cout << "unesi(" << _ime << ")"; } void AkoJeOndaInace::nazubi(int t) const { cout << string(t, '\t'); cout << "ako_je "; _uslov->ispisi(); cout << " onda:" << endl; _n1->nazubi(t+1); cout << endl; cout << string(t, '\t'); cout << "inace:" << endl; _n2->nazubi(t+1); } void AkoJeOnda::nazubi(int t) const { cout << string(t, '\t'); cout << "ako_je "; _uslov->ispisi(); cout << " onda:" << endl; _n1->nazubi(t+1); } void DokJe::nazubi(int t) const { cout << string(t, '\t'); cout << "dok_je "; _uslov->ispisi(); cout << " radi_sledece:" << endl; _n1->nazubi(t+1); } void Prazna::nazubi(int t) const { cout << string(t, '\t'); }