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
)
14 if(!ail::read_file(input
, code
))
16 std::cout
<< "Unable to read input" << std::endl
;
20 fridh::lines_of_code lines
;
21 fridh::lexer
lexer(code
, lines
);
24 if(!lexer
.parse(error
))
26 std::cout
<< "Error: " << error
<< std::endl
;
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
);
40 bool perform_parser_test(std::string
const & input
, std::string
const & output
)
43 if(!ail::read_file(input
, code
))
45 std::cout
<< "Unable to read input" << std::endl
;
53 if(!parser
.process_module(input
, "test", module
, error
))
55 std::cout
<< "Error: " << error
<< std::endl
;
62 int main(int argc
, char ** argv
)
66 std::cout
<< argv
[0] << " lexer <input> <output>" << std::endl
;
67 std::cout
<< argv
[0] << " parser <input> <output>" << std::endl
;
76 if(command
== "lexer")
77 perform_lexer_test(input
, output
);
78 else if(command
== "parser")
79 perform_parser_test(input
, output
);
82 std::cout
<< "Unknown command" << std::endl
;