Develop C code for parsing a mathematical expression

Closed Posted 6 years ago Paid on delivery
Closed Paid on delivery

A mathematical expression can have variables and operators. The following conditions

are imposed on the construction of an expression.

a. Valid variable names may have at most 6 characters (Allowed characters are

lower/upper case English alphabets, underscore). Space, numbers, and

special characters are not allowed in variable names.

b. Parenthesis is not allowed in the expression.

c. +, -, / and * are the four allowed operators. All operators need two operands.

Unary operators are not allowed.

d. Spaces are allowed between variables, operators. At most 3 spaces may be

allowed.

e. Expression is evaluated from left to right.

Example

1. Valid expression: length * width – area

Variables – length, width, area

Operators: *, -

Note – Spaces are allowed between variables and operators. One space

between variables and operator in the above expression.

2. Valid expression: length*width–area+my_len

Variables – length, width, area, my_len

Operators: *, -, +

No Parenthesis is used

No Spaces used

Develop C code for parsing a mathematical expression as specified by above rules and

determine if it is a valid expression. Print a message “expression is valid” or “expression

is invalid”.

The mathematical expression may be at most 100 characters long. There may be at

most 10 variables in the expression.

If the expression is invalid, print one of the following diagnostic message when

appropriate – “invalid variable” followed by partial name of the variable which is invalid,

“excessive space” for more than 3 spaces.

Algorithm C Programming C# Programming C++ Programming Software Architecture

Project ID: #15829874

About the project

29 proposals Remote project Active 6 years ago