I need help developing a program that acts as a command line parser. Essentially, my program needs to ask the user to input a command line: eg - A+B=C. It will then output the following:
A
+
B
=
C.
Although this seems basic, my program needs to recognize different groups of characters and output them correctly. The following are examples my program needs to take into consideration:
1) ABKLJFDLKJLKKDFJ++++++ajkadsl;fkjld;akjk=====daskflj342343
1a)
ABKLJFDLKJLKKDFJ
++++++
ajkadsl
;
fkjld
;
akjk
=====
daskflj342343
Explanation: program groups letters and characters together, but moves to next line when a symbol is reached.
2) It also must recognize whitespace: A + B = C
2a)
A
+
B
=
C
3) It must recognize a matrix: D_1 = [1 3; 2 3 4; ; 4 5 6]
3a)
D_1
=
[1 3; 2 3 4; ; 4 5 6]
4) If the user forgets the second bracket to a matrix: D_1 = [1 3; 2 3 4; ; 4 5 6
4a)
D_1
=
Need ']' to close matrix
5) A regular sentence: Hello How are you
5a)
Hello
How
are
you
6) Anything including invalid segments. The only valid operator segments are +-/* Invalid operator segments could be: +%-, +&!
Valid number segments can start with '.' or a digit. an invalid number would be: 3.abc, which should be parsed as 3. and then abc. Only numbers, whitespace, and ';' should be allowed in the whitespace. a sequence of ';' and ',' is valid: ;;;,;;;,,,;
I have worked on a pseudocode for the main part of my program thus far, and I think I have all the functions named within it that I would need. I was wondering if someone could help me develop the functions correctly for my program, thanks!
Below is my pseudocode:
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
cout << " Welcome to My Command Line Parser!" << endl;
cout << " XXXXXXXXXX, XXXXXXXXXXXXXXXXXXXXXX" << endl;
cout << " XXXXXXXX, 2007\n" << endl;
cout << "\n" << endl;
cout << "Input a Command Line\n";
cin.getline(buffer, 500);
char piece[500];
int st = 0, ed = 0, err_code = 1;
while( buffer[st]!=0 )
{
st = find_first_element( );
if (buffer[st] == 0) err_code = 0;
ed = find_last_element( st ); // err_code can be set inside
if (err_code == 0) break;
else
{
_copy_segment(piece, st, ed);
_display_segment(piece);
st = ed + 1;
}
}
return err_code;
}
//Functions