Question: The language for this assignment should be written in standard C or ANSI C An assignment statement consists of four parts (a) The left hand
The language for this assignment should be written in standard C or ANSI C
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 can be any legal expression (d) A semicolon, which terminates the statement. The most complicated part 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 (+,-, *J, %) in which the operands must be constants or variables. The following are examples of legal RHS of assignment X = 12 operators under our rules x = fun( 12 ); x-y +z Y=x-12 The following are examples of illegal RHS of assignment operators under our rules: X- funl(fun2(x)); /* illegal-nested function call */ X-v+ z + 10; /* illegal-two operators X funl(x) + z, /* illegal operand/ -fun(a1, a2) /* two operands * X = 'c", /*illegal as RHs is not variable or constant, which can only be a number */ X- fun(1c);* illegal variable name on RHS* 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 prompts the user to enter an assignment statement at the keyboard and then tests whether it is legal under our restrcited svntax. Ifthe assionment is legal, output "This statement is legal". else if it is not illegal, output "This statement is illegal" without stating what exactly is wrong with the statement, e.g. X= 12; You echo X- 12 This statement is legal X-y+z+10; You echo X-y+z+ 10 This statement is illegal 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 can be any legal expression (d) A semicolon, which terminates the statement. The most complicated part 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 (+,-, *J, %) in which the operands must be constants or variables. The following are examples of legal RHS of assignment X = 12 operators under our rules x = fun( 12 ); x-y +z Y=x-12 The following are examples of illegal RHS of assignment operators under our rules: X- funl(fun2(x)); /* illegal-nested function call */ X-v+ z + 10; /* illegal-two operators X funl(x) + z, /* illegal operand/ -fun(a1, a2) /* two operands * X = 'c", /*illegal as RHs is not variable or constant, which can only be a number */ X- fun(1c);* illegal variable name on RHS* 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 prompts the user to enter an assignment statement at the keyboard and then tests whether it is legal under our restrcited svntax. Ifthe assionment is legal, output "This statement is legal". else if it is not illegal, output "This statement is illegal" without stating what exactly is wrong with the statement, e.g. X= 12; You echo X- 12 This statement is legal X-y+z+10; You echo X-y+z+ 10 This statement is illegal
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
