Skip to content

Commit f521a17

Browse files
committed
Ready for Release 0.35.1
1 parent 4186034 commit f521a17

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ Windows needs Internet Information Services (IIS) Manager to be enabled and set
7878

7979
Note that inputs to the running program have to be entered into the text field bottom-right **before** the program is run, these being separated by commas. Also the user is prompted to clear the output window when it is full. These are the only significant differences to running the Javascript in a console window.
8080

81+
![Screenshot](https://raw.githubusercontent.com/cpp-tutor/pseudocode-compiler/main/screenshot.png)
82+
8183
## License
8284

8385
This software is released under the highly permissive MIT License. If you do modify or improve parts of this software, especially the web front-end, I hope you would want to share your efforts, but this is not a requirement.

Tree.hpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ class Tree {
1212
return right = next;
1313
}
1414
virtual void emit() = 0;
15+
static void setOutput(std::ostream *os) {
16+
Output::out = os;
17+
}
1518
protected:
1619
Tree *left{ nullptr }, *right{ nullptr };
1720
class Indenter {
@@ -25,7 +28,18 @@ class Tree {
2528
friend inline std::ostream& operator<<(std::ostream&, const Indenter&);
2629
};
2730
inline static Indenter indent{};
28-
inline static std::ostream& output = std::cout;
31+
class Output {
32+
inline static std::ostream *out = nullptr;
33+
friend void Tree::setOutput(std::ostream *os);
34+
public:
35+
Output() = default;
36+
Output(std::ostream *os) { out = os; }
37+
template<typename T>
38+
std::ostream& operator<<(const T& v) {
39+
return *out << v;
40+
}
41+
};
42+
inline static Output output{};
2943
public:
3044
friend inline std::ostream& operator<<(std::ostream&, const Tree::Indenter&);
3145
};

main.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,31 +120,33 @@ int main(const int argc, const char *argv[]) {
120120
}
121121
}
122122
if (infile && *infile) {
123-
std::cin.rdbuf(infile->rdbuf());
124123
if (args.size() == 1) {
125124
std::string outfilename{ args.front() };
126125
outfile = new std::ofstream{ outfilename.replace(outfilename.find('.'), std::string::npos, ".js") };
127126
}
128127
else if (args.size() == 2) {
129128
outfile = new std::ofstream{ args.back() };
130129
}
131-
if (outfile && *outfile) {
132-
std::cout.rdbuf(outfile->rdbuf());
133-
}
134130
else if (!cgi_program) {
135131
std::cerr << "Error: could not open file for writing: " << args.back() << '\n';
136132
return returncode;
137133
}
138134
}
139-
yy::Lexer scanner{};
135+
yy::Lexer scanner{ (infile && *infile) ? infile : &std::cin, &std::cerr };
140136
Symbol table{};
141137
Decls start{ &table };
142138
yy::Parser parser{ &scanner, &table, &start, &error_stream };
139+
Tree::setOutput((outfile && *outfile) ? outfile : &std::cout);
143140

144141
try {
145142
if (!parser.parse()) {
146143
if (support_nodejs) {
147-
std::cout << support_nodejs_code;
144+
if (outfile && *outfile) {
145+
*outfile << support_nodejs_code;
146+
}
147+
else {
148+
std::cout << support_nodejs_code;
149+
}
148150
}
149151
start.emit();
150152
returncode = 0;
@@ -169,5 +171,7 @@ int main(const int argc, const char *argv[]) {
169171
std::cerr << error_stream.str();
170172
}
171173
}
174+
delete infile;
175+
delete outfile;
172176
return returncode;
173177
}

0 commit comments

Comments
 (0)