This repository has been archived on 2024-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
pacciani/main.cpp

58 lines
945 B
C++
Raw Normal View History

#include "Monicelli.tab.h"
#include <iostream>
2014-11-27 20:42:55 +01:00
#include <fstream>
#include <cstdlib>
2014-11-27 20:42:55 +01:00
#include <cstdio>
using namespace monicelli;
int lineNumber = 1;
Program *program;
extern FILE *mcin;
2014-11-27 20:42:55 +01:00
void mcerror(const char *message) {
std::cerr << "At line " << lineNumber << ": " << message << std::endl;
std::exit(1);
}
void mcmeta(const char *text) {
2014-11-27 22:16:12 +01:00
while (*text != '\0' && *text == ' ') {
text += 1;
}
std::cerr << "META: " << text << std::endl;
}
2014-11-27 20:42:55 +01:00
int main(int argc, char **argv) {
#if YYDEBUG
mcdebug = 1;
#endif
2014-11-27 20:42:55 +01:00
bool fromFile = argc > 1;
bool toFile = argc > 2;
2014-11-27 20:42:55 +01:00
program = new Program();
2014-11-27 20:42:55 +01:00
if (fromFile) {
mcin = fopen(argv[1], "r");
2014-11-27 20:42:55 +01:00
}
mcparse();
2014-11-27 20:42:55 +01:00
if (fromFile) {
fclose(mcin);
2014-11-27 20:42:55 +01:00
}
if (toFile) {
std::ofstream out(argv[2]);
program->emit(out);
out.close();
}
else {
program->emit(std::cout);
}
return 0;
}