neopb/neopb.cpp

42 lines
978 B
C++

#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include "tokenizer.hpp"
std::vector<PBToken> tokenize(std::string code);
std::string readFileContents(std::string fname) {
std::ifstream ifs(fname);
std::string contents( (std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>()) );
return contents;
}
int main(int argc, char* argv[]) {
#ifdef DEBUG
for (int n = 0; n < argc; n++) {
std::cout << "arg" << n << ": " << argv[n] << std::endl;
}
#endif
std::string infile = argc > 1 ? argv[1] : "";
std::string code = "";
if(infile.length() > 0) {
code = readFileContents(infile);
}
Tokenizer tokenizer = Tokenizer(code);
#ifdef DEBUG
std::cout << "code: " << tokenizer.dump() << std::endl;
#endif
std::vector<PBToken> tokens = tokenizer.tokenize();
for(int i = 0; i < tokens.size(); i++) {
std::cout << tokens[i].value << std::endl;
}
return 0;
}