Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- stack<pair<int, int>> indFunc; //<количество элементов в tid, индекс в полизе, где был $F>
- void operation(stack<token> &st, vector <generation_token> poliz, int &ind) {
- generation_token cur = poliz[ind];
- if(cur.content == "+" || cur.content == "-" || cur.content == "*" || cur.content == "/"
- || cur.content == "%" || cur.content == "^" || cur.content == "|" || cur.content == "&"
- || cur.content == "||" || cur.content == "&&") {
- token fir = st.top();
- st.pop();
- token sec = st.top();
- st.pop();
- variable _fir;
- _fir.content = fir.content;
- _fir.Type = getType(fir.content);
- variable _sec;
- _sec.content = sec.content;
- _sec.Type = getType(sec.content);
- variable ans = mathOperations(_fir, _sec, cur.content);
- token willAdd;
- willAdd.Type = _constant_;
- willAdd.content = ans.content;
- st.push(willAdd);
- } else if(cur.content == "{") {
- tid.emplace_back();
- } else if(cur.content == "}") {
- tid.pop_back();
- } else if(cur.content == "@") {
- token last = st.top();
- st.pop();
- variable *per = &tid[tid.size()-1][last.content];
- token add;
- add.Type = _link_;
- add.link = per;
- st.push(add);
- } else if(cur.content == "?") {
- token last = st.top();
- st.pop();
- variable per = tid[tid.size()-1][last.content];
- token add;
- add.Type = _constant_;
- add.content = per.content;
- st.push(add);
- } else if(cur.content == "#") {
- //создать переменную
- token tokName = st.top();
- st.pop();
- token tokType = st.top();
- st.pop();
- pair<types, string> p;
- string name = tokName.content;
- string typeVar = tokType.content;
- types here = toType(typeVar);
- tid[tid.size()-1][name] = variable(here, "0");
- token backType;
- backType.Type = _name_;
- backType.content = typeVar;
- st.push(backType);
- token varLink;
- varLink.Type = _link_;
- varLink.content = "";
- varLink.link = &tid[tid.size()-1][name];
- st.push(varLink);
- } else if(cur.content == ";") {
- st.pop();
- } else if(cur.content == "#+") {
- token varToken = st.top();
- string varName = varToken.content;
- variable has = tid[tid.size()-1][varName];
- variable one = variable(_int_, "1");
- variable ans = mathOperations(has, one, "+");
- tid[tid.size()-1][varName] = ans;
- token ret;
- ret.Type = _constant_;
- ret.content = ans.content;
- st.push(ret);
- } else if(cur.content == "#-") {
- token varToken = st.top();
- string varName = varToken.content;
- variable has = tid[tid.size()-1][varName];
- variable one = variable(_int_, "1");
- variable ans = mathOperations(has, one, "-");
- tid[tid.size()-1][varName] = ans;
- token ret;
- ret.Type = _constant_;
- ret.content = ans.content;
- st.push(ret);
- } else if(cur.content == "+#") {
- token varToken = st.top();
- string varName = varToken.content;
- variable has = tid[tid.size()-1][varName];
- variable one = variable(_int_, "1");
- variable ans = mathOperations(has, one, "+");
- tid[tid.size()-1][varName] = ans;
- token ret;
- ret.Type = _constant_;
- ret.content = has.content;
- st.push(ret);
- } else if(cur.content == "-#") {
- token varToken = st.top();
- string varName = varToken.content;
- variable has = tid[tid.size()-1][varName];
- variable one = variable(_int_, "1");
- variable ans = mathOperations(has, one, "-");
- tid[tid.size()-1][varName] = ans;
- token ret;
- ret.Type = _constant_;
- ret.content = has.content;
- st.push(ret);
- } else if(cur.content == "!A") {
- token nwIndStr = st.top();
- st.pop();
- int nwInd = atoi(nwIndStr.content.c_str());
- ind = nwInd-1;
- } else if(cur.content == "!F") {
- token nwIndStr = st.top();
- st.pop();
- token needStr = st.top();
- st.pop();
- if(needStr.content == "false") {
- int nwInd = atoi(nwIndStr.content.c_str());
- ind = nwInd;
- }
- } else if(cur.content == "$F") {
- token funcNameTok = st.top();
- st.pop();
- string funcName = funcNameTok.content;
- //stack<pair<int, int>> indFunc; //<количество элементов в tid, индекс в полизе, где был $F>
- indFunc.push({tid.size(), ind});
- /*
- map <string, pair <types, vector <pair <types, string> > > > functions;
- map <string, int> function_begin;
- */
- tid.emplace_back();
- int cntParametrs = functions[funcName].second.size();
- while(cntParametrs > 0) {
- token parametr = st.top();
- st.pop();
- variable par;
- par.Type = functions[funcName].second[cntParametrs-1].first;
- par.content = parametr.content;
- string parName = functions[funcName].second[cntParametrs-1].second;
- tid[tid.size()-1][parName] = par;
- cntParametrs--;
- }
- ind = function_begin[funcName]; // В этом месте точно будет $B, мы его просто пропускаем(в for ++)
- } else if(cur.content == "$E") {
- pair<int, int> p = indFunc.top();
- indFunc.pop();
- while(tid.size() > p.first) {
- tid.pop_back();
- }
- ind = p.second;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement