我自己编写的Deadfish解释器
查看原帖
我自己编写的Deadfish解释器
1213524
C_plus_plus_12345楼主2024/10/7 22:00
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
void deadfish(string com)
{
	long long acc = 0;
	for(int i=0;i<com.length();i++)
	{
		switch (com[i])
		{
			case 'i':
				acc++;
				break;
			case 'd':
				acc--;
				break;
			case 's':
				acc = acc * acc;
				break;
			case 'o':
				cout << acc << " ";
				break;
			case 'w':
				cout << char(acc);
				break;
			default:
				// Do nothing
				break;
		}
	}
}
int main()
{
	printf("Deadfish interpreter by PSTF\n");
	string a;
	while(1)
	{
		cout << ">>> ";
		cin >> a;
		if(a == "exit")
		{
			cout << "Thank you for using!";
			return 0;
		}
		else
		{
			deadfish(a);
			cout << "\n\n";
		}
	}
}

注:此处多了一个w的命令,表示将累加器输出为字符。

关于Deadfish:这个网站上有介绍

2024/10/7 22:00
加载中...