Question
ASSIGNMENT: (Do in C++)
There is no additional information for this assignment. I am assuming that the program should only read tokens that satisfy the requirements listed below.
Create a program that will read tokens written to match the following syntax and print the type and value of each token found. The statements will be found in a file that will be passed to the program via a command line argument.
STATEMENTS:
Valid tokens are of one of the following:
1) EVAL
2) VALUE
3) EXP
4) Variable
a) A variable is of the form Vnn where nn ranges from 00 to 99
5) Constant
a) A constant is a number of decimal digits from 0 to 9999999
6) Operator
a) An operator is one of the following:
i) +
ii) –
iii) *
iv) /
7) Symbol
a) A symbol is one of the following:
i) (
ii) )
iii) ;
Explanation / Answer
#include #include #include #include #include "build/pcrecpp.h" void ReadFile(std::vector &lines_in_file); bool ValidateArguments(int arguments); std::string RegexConverter(std::string &user_specified_pattern); void SplitInputLine(std::string &user_specified_pattern, std::vector &users_pattern_split); void TokenValidator(std::vector& users_pattern_split, std::string& users_converted_pattern); std::string TokenToRegex(std::string word_in_user_specified_pattern); bool FindMatchingLines(std::vector lines_in_file, std::string user_specified_pattern); int main(int argc, char *argv[]) { if (!ValidateArguments(argc)) return 1; std::string user_specified_pattern = argv[1]; std::vector lines_in_file; // 2 diminsional vector containing [lines][words] ReadFile(lines_in_file); std::string users_converted_pattern = RegexConverter(user_specified_pattern); FindMatchingLines(lines_in_file, users_converted_pattern); return 0; } void ReadFile(std::vector &lines_in_file) { std::stringstream input_file; input_file