LL 语法(9. 8 更新)

· · 科技·工程

编译器(C++)

#include <bits/stdc++.h>
#define int long long
using namespace std;

string s;
vector<string> p;
string ope;
map <string, int> bianliang;

signed main(){
    while (cin >> s){
        if (s == "RUN")
            break;
        p.push_back(s);
    }
    for (int x = 0; x < p.size(); x++){
        string code = p[x];
        if (ope == "in"){
            int inputcode;
            cin >> inputcode;
            bianliang[code] = inputcode;
            ope = "";
        }
        if (ope == "out"){
            if (code == "NL")
                cout << endl;
            else if (code[0] == '"' && code[code.size() - 1] == '"')
                cout << code;
            else
                cout << bianliang[code];
            ope = "";
        }
        if (ope == "int"){
            int now = 0;
            int flag = 0;
            string now_bl;
            for (int i = 0; i < code.size(); i++){
                if (code[i] == '='){
                    flag = 1;
                    continue;
                }
                if (flag == 0)
                    now_bl += code[i];
                else
                    now = now * 10 + code[i] - '0';
            }
            bianliang[now_bl] = now;
            ope = "";
        }
        if (code == "in")
            ope = code;
        if (code == "out")
            ope = code;
        if (code == "int")
        ope = code;
    }
    return 0;
}

运行方法