Pascal requires that real constants have either a decimal point, or an exponent (starting with the letter e or E, and officially called a scale factor), or both, in addition to the usual collection of decimal digits. If a decimal point isincluded it must have at least one decimal digit on each side of it As expected, a sign ( or -). may precede the entire number, or the exponent, or both Exponents may not include fractional digits Blanks may precede or follow thereal constant.. , but they may not be embedded within it. Note that the Pascalsyntax rules for real constants make no assumptions about the range of real values, and neither does this problem. Your task in this problem is to identify legal Pascal real constants. Input and Output Each line of the input data contains a candidate which you are to classify. For eachline of the input, display your finding as illustrated in the example shown below. The input terminates with a line that contains only an asterisk in column one. Sample INPUT1.2
1.
1.0e-55
E-12
6.5E
1e-12
4.1234567890E-99999
7.6e 12.5
99
* Sample output1.2 is legal.
IS ILLEGAL.
1.0e-55 is legal.
E-12 IS ILLEGAL.
6.5e IS ILLEGAL.
1e-12 IS legal.
.
7.6E 12.5 IS ILLEGAL.
99 IS ILLEGAL. #Include
#include
Using namespace std;
void main ()
{
ENUM State {pre_num, siGN1, pre_point, point, fraction, e, siGN2, exp, folowblank, error}
CHAR CH;
Char Str [1000];
State State;
While (CIN >> CH, CH! = '*')
{
INT IDX = 0;
State = pre_num;
While (ch! = '/ n')
{
Switch (state)
{
Case pre_num:
IF (CH == ' ' || CH == '-')
{
State = SIGN1;
Break;
}
IF (ch> = '0' && ch <= '9') {
State = pre_point;
Break;
}
State = Error;
Break;
Case Sign1:
IF (CH> = '0' && ch <= '9')
{
State = pre_point;
}
Else
State = Error;
Break;
Case pre_point:
IF (CH == '.')
{
State = POINT;
Break;
}
IF (CH == 'E' || CH == 'E')
{
State = E;
Break;
}
IF (! (ch> = '0' && ch <= '9')))
{
State = Error;
}
Break;
Case Point:
IF (CH> = '0' && ch <= '9')
{
State = FRACTION;
}
Else
State = Error;
Break;
Case Fraction:
IF (CH == 'E' || CH == 'E')
{
State = E;
Break;
}
IF (CH == '')
{
State = followblank;
Break;
}
IF (! (ch> = '0' && ch <= '9')))
{
State = Error;
}
Break;
Case E:
IF (CH == ' ' || CH == '-')
{
State = SIGN2;
Break;
}
IF (CH> = '0' && ch <= '9')
{
State = exp;
Break;
}
State = Error;
Break;
Case Sign2:
IF (CH> = '0' && ch <= '9')
{
State = exp;
}
Else
State = Error;
Break;
Case EXP:
IF (CH == '')
{
State = followblank;
Break;
}
IF (! (ch> = '0' && ch <= '9')))
State = Error;
Break;
Case Followblank:
IF (ch! = '')
State = Error;
DEFAULT:
Break;
}
STR [IDX ] = CH;
Cin.get (CH);
}
STR [IDX] = '/ 0';
While (Str [Idx] == ')
STR [IDX] = '/ 0';
COUT << str << "IS";
IF (state == error || state == pre_point || state == points || state == Sign1 || State == Sign2 || State == E) cout << "illegal./n";
Else
COUT << "legal./n";
MEMSET (STR, 0, idx * sizeof (char));
}
}