| 37 | } |
| 38 | |
| 39 | static void print_error_message(const std::string & input_str, size_t error_pos, const std::string & error_msg) { |
| 40 | fprintf(stdout, "Input string is invalid according to the grammar.\n"); |
| 41 | fprintf(stdout, "Error: %s at position %zu\n", error_msg.c_str(), error_pos); |
| 42 | fprintf(stdout, "\n"); |
| 43 | fprintf(stdout, "Input string:\n"); |
| 44 | fprintf(stdout, "%s", input_str.substr(0, error_pos).c_str()); |
| 45 | if (error_pos < input_str.size()) { |
| 46 | fprintf(stdout, "\033[1;31m%c", input_str[error_pos]); |
| 47 | if (error_pos+1 < input_str.size()) { |
| 48 | fprintf(stdout, "\033[0;31m%s", input_str.substr(error_pos+1).c_str()); |
| 49 | } |
| 50 | fprintf(stdout, "\033[0m\n"); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | int main(int argc, char** argv) { |
| 55 | if (argc != 3) { |