Here is the better quality. An assignment statement consists of four parts (a) T
ID: 3706409 • Letter: H
Question
Here is the better quality.
An assignment statement consists of four parts (a) The left hand side which must be a variable (b) The assignment operator,- (c) The right hand side which ca nbe any legal expression (d) A semicolon, which terminates the statement. The most complicatedpart is the RHS, for C allows expressions of various sorts (e.g. function calls, variables constants, expressions involving arithmetic operators). But, we will limit the RHS to the one of the following (a) A constant (b) A variable (c) One function call, with only constants or variables as arguments (d) An expression with one binary arithmetic operator (+,-, *, /, %) in which the operands must be constants or variables The following are examples of legal RHS of assignment operators under our rules: X= 12 x - fun( 12); X-y +z; Y=x+12 The following are examples of illegal RHS of assignment operators under our rules: X = fun! (fun2(x)); /* illegal-nested function call */ X = y + z + 10: /* illegal-two operators */ X - funl(x) + z; /*illegal operand*/ We allow any amount of white space to separate parts of the assignment statement. You may assume that no assignment statement consists of more than 50 characters including white space (a tab, blank, and newline counts as a single character) Write a program that promts the user to enter an assignment statement at the keyboardand then tests whether it is legal under our restrcuted syntax. Follow the C rules for identifiers, under which, for example, a variable's name may not begin with a number. The program echoes each statement as it is read and then prints out s message about its legality. The function main does only input, output. Use only getchar for input. The rest of the work must be done by other function(s) Hint: The program needs to remember the previous character read so that the two can be compared. For example, the assignment statement's LHS may not consist of a letter, a white space, and another letterExplanation / Answer
i = 0;
{
printf("invalid variable name in LHS");
exit;
}
i++;
if (i >=j)
{
printf("no = character found);
exit;
}
{
}
if ( (opAdd > 1) || (opMul > 1) || (opSub > 1) || (opDiv > 1) || (opRem > 1) || (brOpen > 1) || (brClose > 1))
printf("Invalid Assignment string as per the rules");
else
printf("Valid Assignment string as per the rules");