answersLogoWhite

0


Best Answer

Well, this is a matter of opinion, and different language designers do things differently.

Most languages use operator precedence, so that the programmer can say things like:

z = 2 * x + 3 * y

without having to mark everything up with parenthesis:

z = ((2 * x) + (3 * y))

Forcing the programmer to always use parenthesis eases the strain of remembering syntax and precedence, at the cost of less freedom for the programmer to express herself naturally.

User Avatar

Wiki User

16y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: It is a good idea to eliminate all operator procedence rules and require parenthesis to show the desired precedence in expression why or why not?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Can a while statement end in a semicolon?

Yes. A while statement ends in a statement...while (expression) statement...and that statement can be a null statement, a single statement, or a block of statements. In the case of the block of statements, there is also a set of braces surrounding them...while (expression);while (expression) statement;while (expression) {statement1;statement2;...statementN;}In the case where the body of the statement is null, there is no body. This is often done while taking advantage of side effects. For instance, to copy a string you could use...char *strcpy (char *pszDestination, char *pszSource) {char *pszTemp = pszDestination;while ((*pszDestination++ = *pszSource++) != '\0');return pszTemp;}...this works because the post-increment (++) operator has higher precedence than the dereference (*) operator, and because the assignment (=) operator has the value of the assignment, which is compared using the not equal (!=) operator against the string terminator null.Note, carefully, the inner parentheses. They are needed because != has higher precedence than =, and you want it the other way around. Also, some compilers will let you eliminate the != '\0' terms and the inner parentheses, but that is not portable, and most compilers will warn you about assignment in a conditional expression.In the case of a single statement you could use...i= -1;while (++i < argc) printf ("%d %s\n", i, argv[i]);...here the while statement also ends in a semicolon.The case of the block of statements is not shown, because it seems to be understood from the context of the question.


How do infix notation and postfix notation differ?

It's simply a matter of where the operators are placed in relation to their operands: infix: X + Y prefix: + X Y postfix: X Y + All of the above are equivalent. Prefix notation is also known as Polish notation, hence postfix is also known as reverse Polish notation. Given the infix equation A * B + C / D, the order of evaluation is always parenthesis, orders, divide/multiply, add/subtract (PODMAS), thus we must multiply A by B first, then divide C by D, and finally add the two results together. If we wish to perform the addition first, then we must re-write the equation with parenthesis: A * (B + C) / D. With postfix and prefix notation, operator precedence becomes superfluous because we always evaluate these expressions in left-to-right order: Infix A * B + C / D becomes postfix A B * C D / + or prefix / * A + B C D Infix A * (B + C) / D becomes postfix A B C + * D / or prefix + * A B / C D When we eliminate operator precedence with postfix or prefix notation, we greatly simplify the algorithm required to evaluate complex expressions. For example, given the postfix expression A B C + * D /, we simply read the symbols one at a time, placing them on a stack, until we encounter an operator. We then pop the first two elements off the stack, perform the operation, and then pop the result back on the stack. We repeat this process until there are no more symbols left, at which point the stack holds just one value: the result. With prefix notation, we place the operators on the stack instead of the operands. When we read the first operand we simply store it in an accumulator. We continue pushing operators onto the stack until we encounter the second operand, at which point we can pop the first operator off the stack, perform the operation and update the accumulator. We repeat this process until there are no symbols left, at which point the accumulator holds the final result. Note that when presented with an infix expression, a machine has to convert the expression to the equivalent prefix or postfix expression before it can be evaluated. By eliminating this conversion process, computation by machine can be performed with much greater speed.


What is the purpose of the flag variable in a bubble sort?

to eliminate unnecessary swaps to eliminate unnecessary comparisons to stop as soon as the list is sorted to sort an array of unknown size


Is intended to eliminate single points of failure?

Redundancy


How do you eliminate all of humanity?

find out how to grow some wings and fly to london.

Related questions

How do you eliminate the parenthesis in algebra equation?

You can remove parenthesis or bracket by multiplying the number outside, with the number inside the bracket.


What is y2x-5 eliminated?

7


What is the importance of the conjugate in rationalizing the denominator of a rational expression that has a radical expression in the denominator?

To eliminate the radical in the denominator.


How do you slove equations with parenthesis?

Eliminate them from the equation. Note: This must be accomplished through the use of legitimate algebraic operations. Erasure is not permitted.


What is 6 divided by 2 times 2 plus 1 equals?

6/2(2+1) =1 In order of operations you do parenthesis first, so it becomes 6/2(3) Then, to eliminate the parenthesis completely, you multiply 2 by 3 and get: 6/6 which equals 1


Nazi policy to eliminate all of Europe's Jews resulted in?

It seems you're looking for expression the Holocaust.


How can you eliminate the absolute value from a b a-b?

Since there are no absolute values in the expression, it would appear that the task has already been accomplished!


What is conciseness in communication?

Conciseness in writing means to eliminate wordy expression, include only relevant information and avoid unnecessary repitition.


What is concise communication?

Conciseness in writing means to eliminate wordy expression, include only relevant information and avoid unnecessary repitition.


How do you simplify an expression that contains a fraction bar?

If there is a common factor between the numerator and the denominator, you can eliminate it. Otherwise, there is usually not much to simplify.


Do percent signs go inside or outside parenthesis for negative numbers?

I believe the parentheses eliminate the need for the negative sign. For example: negative $100,000 would be expressed $(100,000). Using the negative sign, it would read: -$100,000.


What is the simplified expression for 2(x - 5)?

That's as simple as it gets. You can use the distributive property to eliminate the parentheses, but that wouldn't make it any simpler.