++Ↄ
Jump to navigation
Jump to search
++Ↄ is basically C++ but every program must be written in one line and in reverse order.
A standard-compliant ++Ↄ preprocessor needs to split the source code into lines by whitespace characters and then reverse the line order.
Programs
Here is a Hello World program written in ++Ↄ:
} std::cout<<"Hello,\x20World!\n"; main(){ int #include<iostream>
And this is what the Hello World program should look like after preprocessing:
#include<iostream>
int main()
{
std::cout<<"Hello, World!\n";
return 0;
}
Implementations
Here is a simple ++Ↄ preprocessor written in C++:
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
std::string preprocess(auto &&is, std::string _code = {}, std::string _res = {}) {
std::istringstream iss{ (std::getline(is, _code), std::move(_code)) };
while (iss >> _code) _res = _code + "\n" + _res;
return _res;
}
int main(int argc, char *argv[]) {
if (argc >= 4) std::cout << "Usage: " << argv[0] << " [input file] [output file]\n";
else if (argc == 3) std::ofstream(argv[2]) << preprocess(std::ifstream(argv[1]));
else if (argc == 2) std::cout << preprocess(std::ifstream(argv[1]));
else std::cout << "Enter ++Ↄ source code:\n" << preprocess(std::cin);
}