Implemented the one-liner operators ` ( )
[fridhskrift.git] / main.cpp
blob06fb835e37e04149f60761a73a91e93447e13eb9
1 #include <iostream>
2 #include <string>
3 #include <vector>
5 #include <fridh/lexer.hpp>
6 #include <fridh/parser.hpp>
7 #include <fridh/interpreter.hpp>
9 #include <ail/file.hpp>
11 bool perform_lexer_test(std::string const & input, std::string const & output)
13 std::string code;
14 if(!ail::read_file(input, code))
16 std::cout << "Unable to read input" << std::endl;
17 return false;
20 fridh::lines_of_code lines;
21 fridh::lexer lexer(code, lines);
23 std::string error;
24 if(!lexer.parse(error))
26 std::cout << "Error: " << error << std::endl;
27 return false;
30 std::cout << "Processed " << lines.size() << " line(s) of code" << std::endl;
32 std::string data = fridh::visualise_lexemes(lines);
34 std::cout << "Output: " << data.size() << " byte(s)" << std::endl;
36 ail::write_file(output, data);
37 return true;
40 bool perform_parser_test(std::string const & input, std::string const & output)
42 std::string code;
43 if(!ail::read_file(input, code))
45 std::cout << "Unable to read input" << std::endl;
46 return false;
49 fridh::module module;
50 fridh::parser parser;
52 std::string error;
53 if(!parser.process_module(input, "test", module, error))
55 std::cout << "Error: " << error << std::endl;
56 return false;
59 return true;
62 int main(int argc, char ** argv)
64 if(argc != 4)
66 std::cout << argv[0] << " lexer <input> <output>" << std::endl;
67 std::cout << argv[0] << " parser <input> <output>" << std::endl;
68 return 1;
71 std::string
72 command = argv[1],
73 input = argv[2],
74 output = argv[3];
76 if(command == "lexer")
77 perform_lexer_test(input, output);
78 else if(command == "parser")
79 perform_parser_test(input, output);
80 else
82 std::cout << "Unknown command" << std::endl;
83 std::cin.get();
84 return 1;
87 std::cin.get();
88 return 0;