Plugged parser and lexer into main, updated Makefile.
This commit is contained in:
parent
5703593c9d
commit
66da783857
18
Makefile
18
Makefile
|
@ -1,11 +1,17 @@
|
|||
default: compile cleanautogen
|
||||
|
||||
compile:
|
||||
bison --verbose -d Monicelli.ypp
|
||||
flex -P mc Monicelli.lpp
|
||||
g++ -Wall -Wno-deprecated-register -std=c++11 -DYYDEBUG=0 Monicelli.tab.cpp lex.mc.c Nodes.cpp main.cpp -o mcc
|
||||
rm Monicelli.tab.* lex.*
|
||||
bison Monicelli.ypp
|
||||
flex Monicelli.lpp
|
||||
g++ \
|
||||
-Wall -Wno-deprecated-register -std=c++11 -DYYDEBUG=0 \
|
||||
Parser.cpp lex.yy.cc Nodes.cpp main.cpp -o mcc
|
||||
|
||||
graph:
|
||||
bison --graph Monicelli.y
|
||||
|
||||
clean:
|
||||
rm -f Monicelli.dot Monicelli.tab.* lex.* Monicelli.output location.hh position.hh stack.hh
|
||||
cleanautogen:
|
||||
rm -f Parser.?pp lex.* location.hh position.hh stack.hh
|
||||
|
||||
clean: cleanautogen
|
||||
rm -f Monicelli.dot Monicelli.output
|
||||
|
|
52
main.cpp
52
main.cpp
|
@ -1,56 +1,22 @@
|
|||
#include "Monicelli.tab.hpp"
|
||||
#include "Scanner.hpp"
|
||||
#include "Parser.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
|
||||
using namespace monicelli;
|
||||
|
||||
int lineNumber = 1;
|
||||
Program *program;
|
||||
|
||||
extern FILE *mcin;
|
||||
|
||||
|
||||
void mcerror(const char *message) {
|
||||
std::cerr << "At line " << lineNumber << ": " << message << std::endl;
|
||||
std::exit(1);
|
||||
}
|
||||
|
||||
void mcmeta(const char *text) {
|
||||
while (*text != '\0' && *text == ' ') {
|
||||
text += 1;
|
||||
}
|
||||
std::cerr << "META: " << text << std::endl;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
Program program;
|
||||
Scanner scanner(std::cin);
|
||||
Parser parser(scanner, program);
|
||||
|
||||
#if YYDEBUG
|
||||
mcdebug = 1;
|
||||
parser.set_debug_level(1);
|
||||
#endif
|
||||
|
||||
bool fromFile = argc > 1;
|
||||
bool toFile = argc > 2;
|
||||
|
||||
program = new Program();
|
||||
|
||||
if (fromFile) {
|
||||
mcin = fopen(argv[1], "r");
|
||||
}
|
||||
mcparse();
|
||||
if (fromFile) {
|
||||
fclose(mcin);
|
||||
}
|
||||
if (toFile) {
|
||||
std::ofstream out(argv[2]);
|
||||
program->emit(out);
|
||||
out.close();
|
||||
}
|
||||
else {
|
||||
program->emit(std::cout);
|
||||
}
|
||||
parser.parse();
|
||||
program.emit(std::cout);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Reference in New Issue
Block a user