Automata theory problem!!!

I'm creating a program with an input string and follows the ff. rules in Dev C++.

PROGRAM RULES
1st rule Identifiers: starts with [_][a-z] and ends with [a-z][_]and [0-9].
2nd rule Numbers: starts with [0-9][0-9]*[.] and ends with [0-9][0-9]*.
3rd rule Operators: accept operators (+,-,*,/ including = sign).
4th rule Open parenthesis: accept open parenthesis.
5th rule Close parenthesis: accept close parenthesis.

SYNTAX RULES
1 All opening/closing parenthesis must be in pair
2 Numbers may only contain 1 decimal sign per count
3 Numbers followed immediately by a letter will result in an error
4 No more than one count of an operator at a time.
5 No operator before a closing parenthesis
6 Open parenthesis must always be first than a closing one.

As of now this is all I've got.

#include<iostream>
using namespace std;
int main()
{
int id_count=0,num_count=0,op_count=0,illegal_count=0,open_count=0,close_count=0;
char input[50];
cout<<"Input string: ";
cin>>input;
cout<<endl;
for(int ctr=0;ctr<strlen(input);ctr++)
{
if(isalpha(input[ctr]))
{
do
{
cout<<input[ctr];
ctr++;
}
while(isalpha(input[ctr]) || isdigit(input[ctr]));
cout<<" - is an identifier \n";
ctr--;
id_count++;
}
else if(isdigit(input[ctr]))
{
do
{
cout<<input[ctr];
ctr++;
}
while(isdigit(input[ctr]));
cout<<" - is a number \n";
ctr--;
num_count++;
}
else if(input[ctr]=='+' || input[ctr]=='-' || input[ctr]=='/' || input[ctr]=='*' || input[ctr]=='=')
{
cout<<input[ctr]<<" - is an operator\n";
op_count++;
}
else if(input[ctr]=='(')
{
cout<<input[ctr]<<" - is an open parenthesis\n";
open_count++;
}
else if(input[ctr]==')')
{
cout<<input[ctr]<<" - is an close parenthesis\n";
close_count++;
}
else
{
cout<<input[ctr]<<" - illegal character\n";
illegal_count++;
}
}
cout<<"\nIdentifier(s) found: "<<id_count;
cout<<"\nNumber(s) found: "<<num_count;
cout<<"\nOperator(s) found: "<<op_count;
cout<<"\nOpen Parenthesis found: "<<open_count;
cout<<"\nClose Parenthesis found: "<<close_count;
cout<<"\nIllegal(s) found: "<<illegal_count<<"\n\n";
system("pause");
}
Topic archived. No new replies allowed.