Optionally read and write to file.
This commit is contained in:
parent
12c5043778
commit
ae7c1f98d9
29
main.cpp
29
main.cpp
|
@ -1,13 +1,18 @@
|
|||
#include "Monicelli.tab.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
|
||||
using namespace monicelli;
|
||||
|
||||
int lineNumber = 1;
|
||||
Program *program;
|
||||
|
||||
extern FILE *monicelli_in;
|
||||
|
||||
|
||||
void monicelli_error(const char *message) {
|
||||
std::cerr << "At line " << lineNumber << ": " << message << std::endl;
|
||||
|
@ -21,15 +26,31 @@ void monicelli_meta(const char *text) {
|
|||
std::cerr << "META: " << text << std::endl;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int main(int argc, char **argv) {
|
||||
#if YYDEBUG
|
||||
yydebug = 1;
|
||||
#endif
|
||||
|
||||
program = new Program();
|
||||
monicelli_parse();
|
||||
bool fromFile = argc > 1;
|
||||
bool toFile = argc > 2;
|
||||
|
||||
program->emit(std::cout);
|
||||
program = new Program();
|
||||
|
||||
if (fromFile) {
|
||||
monicelli_in = fopen(argv[1], "r");
|
||||
}
|
||||
monicelli_parse();
|
||||
if (fromFile) {
|
||||
fclose(monicelli_in);
|
||||
}
|
||||
if (toFile) {
|
||||
std::ofstream out(argv[2]);
|
||||
program->emit(out);
|
||||
out.close();
|
||||
}
|
||||
else {
|
||||
program->emit(std::cout);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Reference in New Issue
Block a user