Evaluation Expression
Steve Paks
Curriculum Model

A

A

A

A

A

CS

Here I am
A

A

A

CS
A
Java Language Base

CS : Computer
Science
A : Application
EVALUATION OF
EXPRESSIONS
• Evaluation expression
– We will pick the first one among the following answers.

x = a/b-c+d*e...
EVALUATION OF
EXPRESSIONS(Cont’d)
• Evaluation Postfix Expression
– The standard way of expression is infix notation.
– Bu...
EVALUATION OF
EXPRESSIONS(Cont’d)
• Evaluation Postfix Expression(Cont’d)
– To evaluate an expression

Postfix Expression ...
EVALUATION OF
EXPRESSIONS(Cont’d)
• Infix to Postfix
– Algorithm

1. Fully parenthesize the expression.
2. Move all binary...
EVALUATION OF
EXPRESSIONS(Cont’d)
• Infix to Postfix(Cont’d)
– Example 1
Token
a
+
b
*
c
eos

Stack
[0]
+
+
+
+

Top
[1]

...
EVALUATION OF
EXPRESSIONS(Cont’d)
• Infix to Postfix(Cont’d)
– Example 2
Token
a
*
(
b
+
c
)
*
d
eos

Stack
[0]
*
*
*
*
*
...
Upcoming SlideShare
Loading in …5
×

Evaluation expression

613 views

Published on

Published in: Technology, Art & Photos
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
613
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Evaluation expression

  1. 1. Evaluation Expression Steve Paks
  2. 2. Curriculum Model A A A A A CS Here I am A A A CS A Java Language Base CS : Computer Science A : Application
  3. 3. EVALUATION OF EXPRESSIONS • Evaluation expression – We will pick the first one among the following answers. x = a/b-c+d*e-a*c a=4, b=c=2, d=e=3 ((4/2)-2)+(3*3)-(4*2) = 0+9-8 = 1 or (4/2-2+3))*(3-4)*2 = (4/3)*(-1)*2 = -2.6666… – The same precedence have left-to-right associativity. a*b/c%d/e is equivalent to ((((a*b)/c)%d)/e)
  4. 4. EVALUATION OF EXPRESSIONS(Cont’d) • Evaluation Postfix Expression – The standard way of expression is infix notation. – But, compiler does not use it. Infix Postfix 2+3*4 a*b+5 (1+2)*7 a*b/c ((a/(b-c+d))*(e-a)*c a/b-c+d*e-a*c 234*+ ab*5+ 12+7* ab*c/ abc–d+/ea-*c* ab/c–de*+ac*-
  5. 5. EVALUATION OF EXPRESSIONS(Cont’d) • Evaluation Postfix Expression(Cont’d) – To evaluate an expression Postfix Expression 62/3-42*+ Token 6 2 / 3 4 2 * + Stack [0] 6 6 6/2 6/2 6/2-3 6/2-3 6/2-3 6/3-3 6/2-3+4*2 Top [1] [2] 2 3 4 4 4*2 2 0 1 0 1 0 1 2 1 0
  6. 6. EVALUATION OF EXPRESSIONS(Cont’d) • Infix to Postfix – Algorithm 1. Fully parenthesize the expression. 2. Move all binary operators so that they replace their corresponding right parentheses. 3. Delete all parentheses. ((((a/b)-c)+(d*e))-a*c)) → ((((ab/-c)+(d*e))-a*c)) ((((ab/-c)+(d*e))-a*c)) → ((((ab/c-+(d*e))-a*c)) ((((ab/c-+(d*e))-a*c)) → ((((ab/c-+(de*)-a*c)) ((((ab/c-+(de*)-a*c)) → ((((ab/c-(de*+-a*c)) ((((ab/c-(de*+-a*c)) ((((ab/c-(de*+-ac*) ((((ab/c-(de*+-ac*) ((((ab/c-(de*+ac*ab/c-de*+ac*-
  7. 7. EVALUATION OF EXPRESSIONS(Cont’d) • Infix to Postfix(Cont’d) – Example 1 Token a + b * c eos Stack [0] + + + + Top [1] * * Output -1 0 0 1 1 -1 a a ab ab abc abc*- [2]
  8. 8. EVALUATION OF EXPRESSIONS(Cont’d) • Infix to Postfix(Cont’d) – Example 2 Token a * ( b + c ) * d eos Stack [0] * * * * * * * * Top [1] ( ( ( ( Output -1 0 1 1 2 2 0 0 0 0 a a a ab ab abc abc+ abc+* abc+*d abc+*d* [2] + +

×