Evaluation expression
Upcoming SlideShare
Loading in...5
×
 

Evaluation expression

on

  • 322 views

 

Statistics

Views

Total Views
322
Views on SlideShare
322
Embed Views
0

Actions

Likes
0
Downloads
1
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Evaluation expression Evaluation expression Presentation Transcript

  • 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-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)
  • 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*-
  • 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
  • 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*-
  • 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]
  • 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] + +