File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change 11# The bread programming language commands
22
3- ` print/" Hello World!" ` - Prints hello world
3+ ` print/Hello World! ` - Prints hello world, No quotes required!
Original file line number Diff line number Diff line change 11#include < iostream>
22#include < fstream>
33#include < filesystem>
4+ #include < vector>
5+ #include < string>
46
57std::string filename;
68std::filesystem::path tmp_dir = " /tmp/bread/" ;
9+ std::filesystem::path cpp_dir = " /tmp/bread/temp.cpp" ;
710std::string cppname;
11+ std::vector<std::string> file_contents;
812
913int create_tmp_dir_if_not_exist () {
1014 try {
@@ -22,14 +26,34 @@ int create_tmp_dir_if_not_exist() {
2226
2327int compile_to_cpp (std::string filename) {
2428 std::ifstream breadfile;
29+ std::ofstream cpp_file;
2530
2631 breadfile.open (filename);
2732 if (!breadfile.is_open ()) {
2833 std::cerr << " error opening file" << std::endl;
2934 throw 500 ;
3035 return 1 ;
3136 }
37+ std::string c;
38+ while (std::getline (breadfile, c)) {
39+ file_contents.push_back (c);
40+ } // save file into vector
3241 breadfile.close ();
42+ cpp_file.open (cpp_dir);
43+ if (!cpp_file.is_open ()) {
44+ std::cerr << " error creating temporary cpp file" << std::endl;
45+ throw 500 ;
46+ return 1 ;
47+ }
48+ cpp_file << " //transpiled from the bread programming language, do not edit this file\n #include<iostream>\n int main() {\n " ;
49+ for (std::string content : file_contents) {
50+ if (content.find (" print/" ) == 0 ) {
51+ content.erase (0 , 6 );
52+ cpp_file << " std::cout << " << content << " ;\n " ;
53+ }
54+ }
55+ cpp_file << " return 0;\n }\n " ;
56+ cpp_file.close ();
3357 return 0 ;
3458}
3559
You can’t perform that action at this time.
0 commit comments