Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#include #include std::vector parseCommandLine ( const std::string& aCommandLine ) { std::cout < < in 2 < < std::endl; std::vector tokens; size _ t
#include #include std::vector parseCommandLineconst std::string& aCommandLine std::cout in std::endl; std::vector tokens; sizet start ; while start aCommandLine.size sizet end start; while end aCommandLine.size && aCommandLineend && aCommandLineend && aCommandLineend && aCommandLineend end; std::string token aCommandLine.substrstart end start; Handle file redirection with and if token.empty && tokenback token.back tokens.pushbacktokensubstr token.size; tokens.pushbackstd::string token.back; Handle file redirection with else if token && start tokens.pushbacktoken; Handle pipe else if token tokens.pushbacktoken; Handle other tokens else if token.empty tokens.pushbacktoken; Move to the next nonwhitespace character while end aCommandLine.size && aCommandLineend end; start end; std::cout finished" std::endl; return tokens; int main std::cout in std::endl; std::string commandLine "grep x myfile.textbfin myfile.out"; std::cout ut std::endl; std::vector result parseCommandLinecommandLine; std::cout ut std::endl; Print the parsed tokens for sizet i ; i result.size; i std::cout "Token i : resulti std::endl; return ;
#include
#include
std::vector parseCommandLineconst std::string& aCommandLine
std::cout in std::endl;
std::vector tokens;
sizet start ;
while start aCommandLine.size
sizet end start;
while end aCommandLine.size &&
aCommandLineend &&
aCommandLineend &&
aCommandLineend &&
aCommandLineend
end;
std::string token aCommandLine.substrstart end start;
Handle file redirection with and
if token.empty && tokenback token.back
tokens.pushbacktokensubstr token.size;
tokens.pushbackstd::string token.back;
Handle file redirection with
else if token && start
tokens.pushbacktoken;
Handle pipe
else if token
tokens.pushbacktoken;
Handle other tokens
else if token.empty
tokens.pushbacktoken;
Move to the next nonwhitespace character
while end aCommandLine.size && aCommandLineend
end;
start end;
std::cout finished" std::endl;
return tokens;
int main
std::cout in std::endl;
std::string commandLine "grep x myfile.textbfin myfile.out";
std::cout ut std::endl;
std::vector result parseCommandLinecommandLine;
std::cout ut std::endl;
Print the parsed tokens
for sizet i ; i result.size; i
std::cout "Token i : resulti std::endl;
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started