1 / 15

Evaluation of Expressions

Evaluation of Expressions. Yinchong Han Linjia Jiang. Introduction. There are three forms of expressions which are prefix , infix and postfix notation . The project will evaluate infix and postfix expressions then convert one to the other. . Outline Project Specification

maude
Download Presentation

Evaluation of Expressions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Evaluation of Expressions Yinchong Han Linjia Jiang

  2. Introduction There are three forms of expressions which are prefix, infix and postfix notation. The project will evaluate infix and postfix expressions then convert one to the other. Outline Project Specification Applications Design & Testing Conclusion

  3. Project Specification • Basic Concepts • Expressions • Infix Notation • Postfix Notation • Prefix Notation

  4. Expressions X = ((A/(B-C+D)) * (E-A) * C Made of operands,operators, and delimiters. Operands can be any legal variable name or constant. The values that variables take must be consistent with the operations performed on them. These operations are described by the operators. First, there are the basic arithmetic operators: plus, minus, times, and divide (+, −, *, /). Other arithmetic operators include unary minus, and %. A second class is the relational operators: <, <=, ==, < >, >=, and >. These are usually defined to work for arithmetic operands.

  5. Priority of operators Priority of operators Within any pair of parentheses the operators have the highest priority. Priority of operators

  6. Infix Notation X + Y Operators are written in-between their operands. A * ( B + C ) / D means: "First add B and C together, then multiply the result by A, then divide by D to give the final answer." Infix notation needs extra information to make the order of evaluation of the operators clear

  7. Postfix Notation X Y + "Reverse Polish notation“ Operators are written after their operands. The infix expression given above ” A * ( B + C ) / D” is equivalent to A B C + * D / Order. Operators act on values immediately to the left of them. (A (B C +) *) D /)

  8. Prefix Notation + X Y Prefix notation (also known as "Polish notation) Operators are written before their operands. The expression given above ” A * ( B + C ) / D” is equivalent to / * A + B C D Order. Operators act on the two nearest values on the right. /(* A (+ B C) ) D) Compare to Postfix Notation

  9. Converting between Infix and Postfix  It is simple to describe an algorithm for producing postfix from infix: Fully parenthesize the expression. Move all operators so that they replace their corresponding right parentheses. Delete all parentheses.

  10. Converting between Infix and Postfix For example, A/B − C + D *E − A *C, Fully bracket the expression. 2. Move all operators so that they replace their corresponding right brackets. 3. Delete all brackets.

  11. Converting between Infix and Prefix For example, since we want A + B *C to yield ABC * +

  12. Advantages of using postfix notation • Whilst postfix notation might look confusing to begin with, it has several important advantages: • it is unambiguous • it is more concise • it fits naturally with a stack-based system

  13. Design & Testing Run Program:Testing

  14. Conclusion We have understand the theory and basic concepts first. After researching on websites and reading the textbook, we totally understand the concepts and know how to code the program. We are working on our program which can convert infix form and postfix form of expressions one another. After the finishing of the program, we will complete a final report at the end of this semester.

  15. References List 1. Horowitz, E., Sahni, S., & Mehta, D. (1995). Fundamentals of Data Structures in C++, 147-154. 2. Deitel, P., Deitel, H. (2008). Visual C#: How to Program.

More Related