使用说明
1、定义变量
目前只支持整型变量
int a 5 表示定义一个变量为 ,数值为 。
int a 表示定义一个变量为 。
int a read 表示定义一个变量 并读入。
2、读入
read n 表示读入 ,如果 没有定义会自动定义
read n m t 表示读入 , , 如果 , , 没有定义会自动定义
3、输出
write n 表示输出
putchar abcde 表示输出 abcde 注意不用打引号
puts hello 表示输出 hello 并换行,注意不用打引号。
4、修改
add a b 表示将 增加
sub a b 表示将 减少
mul a b 表示将 乘以
div a b 表示将 除以 ,向下取整
mod a b 表示将 取余
<< a b 表示将 左移
>> a b 表示将 右移
or a b 表示将 位运算或
and a b 表示将 位运算与
xor a b 表示将 位运算异或
copy a b 表示将 赋值为
++a 表示将 的值增加一
--a 表示将 的值减少一
5、if
if a op b
//do something...
endif如果 执行 //do somthing... 。
6、for
两种
1、
for i l r
endfor将 枚举从 到
2、
for i l r a
endfor相当于for(int i = l;i <= r;i += a)
7、其他
delete a 表示删除变量 。
exit 直接结束程序
#include<bits/stdc++.h>
#define pre(i, l, r) for(int i = (l); i <= (r); ++i)
#define fpre(i, r, l) for(int i = (r); i >= (l); --i)
#define fr(i, a) for(int _ = (a).size(), i = 0; i < _; ++i)
#define ll long long
using namespace std;
//8MB
const int maxn = 1048577;
const int inf = 1e9;
char gc(void){ static char *p1, *p2, buf[1000000];return (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++);}
template<typename T> inline void S(T &x){x = 0;int f = 1;char ch = gc();while(!isdigit(ch)){if(ch == '-'){
f = -1;}ch = gc();}; while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = gc();x *= f;}
template<typename type, typename... T>
inline void S(type &x, T&...y) {S(x); S(y...);}
template<typename T = int>T S(void) {T x;S(x);return x;}
map<string,int> f;
int cnt = 0;
ll value[maxn];
string st[maxn] =
{
};
//ll stoll(string x)
//{
// ll ans = 0;
// for(auto y : x)
// ans = ans * 10 + y - 48;
// return ans;
//}
string str(string s, int x)
{
string ans = "";
int sz = s.size();
while(x < sz && s[x] == ' ') x++;
while(x < sz && s[x] != ' ') ans += s[x++];
return ans;
}
ll strdigit(string s, int x)
{
ll ans = 0;
int sz = s.size();
int f = 1;
while(x < sz && !isdigit(s[x]))
{
if(s[x] == '-') f = 0;
x++;
}
while(x < sz && isdigit(s[x])) ans = ans * 10 + (s[x++] ^ 48);
if(!f) ans = -ans;
return ans;
}
int main()
{
system("color B");
f["false"] = ++cnt, value[cnt] = 0;
f["true"] = ++cnt, value[cnt] = 1;
f["INT_MAX"] = ++cnt, value[cnt] = INT_MAX;
f["LLONGMAX"] = ++cnt, value[cnt] = LLONG_MAX;
f["INT_MIN"] = ++cnt, value[cnt] = INT_MIN;
f["LLONG_MAX"] = ++cnt, value[cnt] = LLONG_MAX;
int n = 0;
while(st[n] != "") ++n;
if(!n)
{
while(getline(cin, st[n++]));
n--;
puts("Please Wating...");
}
pre(i, 1, n)
{
string s = st[i - 1];
fr(i, s)
if(i != _ - 1 && s[i] == '/' && s[i + 1] == '/')
{
s.erase(i, s.size());
break;
}
string op = str(s, 0);
if(op == "int")
{
string t = str(s, 3);
f[t] = ++cnt;
string val = str(s, 4 + t.size());
if(val == "") val = "0";
bool ok = true;
for(auto y : val)
if(!isdigit(y) && y != '-') ok = false;
if(ok) f[val] = ++cnt, value[cnt] = stoll(val);
value[f[t]] = value[f[val]];
if(val == "read")
scanf("%lld", &value[f[t]]);
}
else
if(op == "write")
{
int res = 5;
string a = str(s, 5);
bool ok = true;
for(auto y : a)
if(!isdigit(y) && y != '-') ok = false;
if(ok) f[a] = ++cnt, value[cnt] = stoll(a);
printf("%lld", value[f[str(s, 5)]]);
}
else
if(op == "read")
{
int res = 4;
while(str(s, res) != "")
{
if(!f[str(s, res)]) f[str(s, res)] = ++cnt;
scanf("%lld", &value[f[str(s, res)]]);
res += str(s, res).size() + 1;
}
}
else
if(op == "add" || op == "sub" || op == "mul" || op == "div" || op == "mod" || op == "or" || op == "xor" || op == "and" || op == "<<" || op == ">>")
{
/*
0 1 2 3 4 5 6 7 8 9
a d d t t 5 2 3
*/
string r = str(s, 3);
string t = str(s, 4 + r.size());
bool ok = true;
for(auto y : t)
if(!isdigit(y) && y != '-') ok = false;
if(ok) f[t] = ++cnt, value[cnt] = stoll(t);
if(op == "add")
value[f[r]] += value[f[t]];
if(op == "sub")
value[f[r]] -= value[f[t]];
if(op == "mul")
value[f[r]] *= value[f[t]];
if(op == "div")
value[f[r]] /= value[f[t]];
if(op == "mod")
value[f[r]] %= value[f[t]];
if(op == "or")
value[f[r]] |= value[f[t]];
if(op == "xor")
value[f[r]] ^= value[f[t]];
if(op == "and")
value[f[r]] &= value[f[t]];
if(op == "<<")
value[f[r]] <<= value[f[t]];
if(op == ">>")
value[f[r]] >>= value[f[t]];
}
else
if(op == "copy")
{
string a = str(s, 4);
string b = str(s, 5 + a.size());
bool ok = true;
for(auto y : b)
if(!isdigit(y) && y != '-') ok = false;
if(ok) f[b] = ++cnt, value[cnt] = stoll(b);
value[f[a]] = value[f[b]];
}
else
if(op == "goto")
{
i = strdigit(s, 4) - 1;
}
else
/*
0 1 2 3 4 5 6 7 8 9
i f a < b 6
*/
if(op == "if")
{
string a = str(s, 2);
string c = str(s, 3 + a.size());
string b = str(s, 4 + c.size() + a.size());
bool ok = true;
for(auto y : a)
if(!isdigit(y) && y != '-') ok = false;
if(ok) f[a] = ++cnt, value[cnt] = stoll(a);
ok = true;
for(auto y : b)
if(!isdigit(y) && y != '-') ok = false;
if(ok) f[b] = ++cnt, value[cnt] = stoll(b);
int t = strdigit(s, 5 + a.size() + b.size() + c.size());
bool flag = false;
if(c == "=")
{
if(value[f[a]] == value[f[b]]) flag = true;
}
if(c == "!=")
{
if(value[f[a]] != value[f[b]]) flag = true;
}
if(c == "<=")
{
if(value[f[a]] <= value[f[b]]) flag = true;
}
if(c == ">=")
{
if(value[f[a]] >= value[f[b]]) flag = true;
}
if(c == "<")
{
if(value[f[a]] < value[f[b]]) flag = true;
}
if(c == ">")
{
if(value[f[a]] > value[f[b]]) flag = true;
}
if(!flag)
{
int tot = 1;
pre(j, i + 1, n)
{
string op = str(st[j - 1], 0);
if(op == "if")
tot++;
else
if(op == "endif")
tot--;
if(!tot)
{
i = j;
break;
}
}
}
}
else
if(op == "delete")
f[str(s, 6)] = 0;
else
if(op == "swap")
{
string a = str(s, 4);
string b = str(s, 5 + a.size());
swap(f[a], f[b]);
}
else
if(op == "putchar")
{
if(s.size() != 7)
printf("%s", s.substr(8, s.size()).c_str());
}
else
if(op == "exit")
return 0;
else
if(op == "puts")
{
if(s.size() == 4)
puts("");
else
puts(s.substr(5, s.size()).c_str());
}
else
if(op.substr(0, 2) == "++")
value[f[s.substr(2, s.size())]]++;
else
if(op.substr(0, 2) == "--")
value[f[s.substr(2, s.size())]]--;
else
if(op == "max")
{
string a = str(s, 3);
string b = str(s, 4 + a.size());
bool ok = true;
for(auto y : b)
if(!isdigit(y) && y != '-') ok = false;
if(ok) f[b] = ++cnt, value[cnt] = stoll(b);
if(value[f[a]] < value[f[b]])
value[f[a]] = value[f[b]];
}
else
if(op == "min")
{
string a = str(s, 3);
string b = str(s, 4 + a.size());
bool ok = true;
for(auto y : b)
if(!isdigit(y) && y != '-') ok = false;
if(ok) f[b] = ++cnt, value[cnt] = stoll(b);
if(value[f[a]] > value[f[b]])
value[f[a]] = value[f[b]];
}
else
if(op == "for")
{
string t = str(s, 3);
string val = str(s, 4 + t.size());
bool ok = true;
if(!f[t])
{
f[t] = ++cnt;
if(val == "") val = "0";
for(auto y : val)
if(!isdigit(y) && y != '-') ok = false;
if(ok) f[val] = ++cnt, value[cnt] = stoll(val);
value[f[t]] = value[f[val]];
if(val == "read")
scanf("%lld", &value[f[t]]);
}
string r = str(s, 5 + t.size() + val.size());
string sp = str(s, 6 + t.size() + val.size() + r.size());
if(sp == "") sp = "1";
ok = true;
for(auto y : r)
if(!isdigit(y) && y != '-') ok = false;
if(ok) f[r] = ++cnt, value[cnt] = stoll(r);
ok = true;
for(auto y : sp)
if(!isdigit(y) && y != '-') ok = false;
if(ok) f[sp] = ++cnt, value[cnt] = stoll(sp);
if(value[f[t]] > value[f[r]])
{
int tot = 1;
pre(j, i + 1, n)
{
string op = str(st[j - 1], 0);
if(op == "for")
tot++;
else
if(op == "endfor")
tot--;
if(!tot)
{
i = j;
f[t] = 0;
break;
}
}
}
}
else
if(op == "endfor")
{
int tot = 1, u;
fpre(j, i - 1, 1)
{
string op = str(st[j - 1], 0);
if(op == "endfor")
tot++;
else
if(op == "for")
tot--;
if(!tot)
{
u = j;
break;
}
}
string t = str(st[u - 1], 3);
string l = str(st[u - 1], 4 + t.size());
string r = str(st[u - 1], 5 + t.size() + l.size());
string sp = str(st[u - 1], 6 + t.size() + l.size() + r.size());
if(sp == "") sp = "1";
bool ok = true;
for(auto y : sp)
if(!isdigit(y) && y != '-') ok = false;
if(ok) f[sp] = ++cnt, value[cnt] = stoll(sp);
value[f[t]] += value[f[sp]];
i = u - 1;
}
}
getchar();
return 0;
}