SlideShare ist ein Scribd-Unternehmen logo
1 von 8
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]

+
+

Weitere ähnliche Inhalte

Was ist angesagt?

Database Management System-session 3-4-5
Database Management System-session 3-4-5Database Management System-session 3-4-5
Database Management System-session 3-4-5Infinity Tech Solutions
 
Math Functions in C Scanf Printf
Math Functions in C Scanf PrintfMath Functions in C Scanf Printf
Math Functions in C Scanf Printfyarkhosh
 
Dag representation of basic blocks
Dag representation of basic blocksDag representation of basic blocks
Dag representation of basic blocksJothi Lakshmi
 
Syntax-Directed Translation into Three Address Code
Syntax-Directed Translation into Three Address CodeSyntax-Directed Translation into Three Address Code
Syntax-Directed Translation into Three Address Codesanchi29
 
Type Script 3.x - Was war. Was kommt!
Type Script 3.x - Was war. Was kommt!Type Script 3.x - Was war. Was kommt!
Type Script 3.x - Was war. Was kommt!Johannes Dienst
 
The Scheme Language -- Using it on the iPhone
The Scheme Language -- Using it on the iPhoneThe Scheme Language -- Using it on the iPhone
The Scheme Language -- Using it on the iPhoneJames Long
 
Introduction To Algorithm [2]
Introduction To Algorithm [2]Introduction To Algorithm [2]
Introduction To Algorithm [2]ecko_disasterz
 
Main topic 3 problem solving and office automation
Main topic 3 problem solving and office automationMain topic 3 problem solving and office automation
Main topic 3 problem solving and office automationInfinity Tech Solutions
 
Shape Safety in Tensor Programming is Easy for a Theorem Prover -SBTB 2021
Shape Safety in Tensor Programming is Easy for a Theorem Prover -SBTB 2021Shape Safety in Tensor Programming is Easy for a Theorem Prover -SBTB 2021
Shape Safety in Tensor Programming is Easy for a Theorem Prover -SBTB 2021Peng Cheng
 
CLASS VIII COMPUTERS FLOW CHART AND ALGORITHM
CLASS VIII COMPUTERS FLOW CHART AND ALGORITHMCLASS VIII COMPUTERS FLOW CHART AND ALGORITHM
CLASS VIII COMPUTERS FLOW CHART AND ALGORITHMRc Os
 

Was ist angesagt? (15)

Database Management System-session 3-4-5
Database Management System-session 3-4-5Database Management System-session 3-4-5
Database Management System-session 3-4-5
 
Math Functions in C Scanf Printf
Math Functions in C Scanf PrintfMath Functions in C Scanf Printf
Math Functions in C Scanf Printf
 
Programming with matlab session 3 notes
Programming with matlab session 3 notesProgramming with matlab session 3 notes
Programming with matlab session 3 notes
 
Syntaxdirected
SyntaxdirectedSyntaxdirected
Syntaxdirected
 
Dag representation of basic blocks
Dag representation of basic blocksDag representation of basic blocks
Dag representation of basic blocks
 
Lecture three
Lecture threeLecture three
Lecture three
 
Syntax-Directed Translation into Three Address Code
Syntax-Directed Translation into Three Address CodeSyntax-Directed Translation into Three Address Code
Syntax-Directed Translation into Three Address Code
 
Type Script 3.x - Was war. Was kommt!
Type Script 3.x - Was war. Was kommt!Type Script 3.x - Was war. Was kommt!
Type Script 3.x - Was war. Was kommt!
 
The Scheme Language -- Using it on the iPhone
The Scheme Language -- Using it on the iPhoneThe Scheme Language -- Using it on the iPhone
The Scheme Language -- Using it on the iPhone
 
Introduction To Algorithm [2]
Introduction To Algorithm [2]Introduction To Algorithm [2]
Introduction To Algorithm [2]
 
Intermediate code
Intermediate codeIntermediate code
Intermediate code
 
Lab no.08
Lab no.08Lab no.08
Lab no.08
 
Main topic 3 problem solving and office automation
Main topic 3 problem solving and office automationMain topic 3 problem solving and office automation
Main topic 3 problem solving and office automation
 
Shape Safety in Tensor Programming is Easy for a Theorem Prover -SBTB 2021
Shape Safety in Tensor Programming is Easy for a Theorem Prover -SBTB 2021Shape Safety in Tensor Programming is Easy for a Theorem Prover -SBTB 2021
Shape Safety in Tensor Programming is Easy for a Theorem Prover -SBTB 2021
 
CLASS VIII COMPUTERS FLOW CHART AND ALGORITHM
CLASS VIII COMPUTERS FLOW CHART AND ALGORITHMCLASS VIII COMPUTERS FLOW CHART AND ALGORITHM
CLASS VIII COMPUTERS FLOW CHART AND ALGORITHM
 

Ähnlich wie Evaluation expression

LET US C (5th EDITION) CHAPTER 1 ANSWERS
LET US C (5th EDITION) CHAPTER 1 ANSWERSLET US C (5th EDITION) CHAPTER 1 ANSWERS
LET US C (5th EDITION) CHAPTER 1 ANSWERSKavyaSharma65
 
Sept. 15, 2014
Sept. 15, 2014Sept. 15, 2014
Sept. 15, 2014khyps13
 
machine_learning.pptx
machine_learning.pptxmachine_learning.pptx
machine_learning.pptxPanchami V U
 
10b- Rabin Karp String Matching Problem.pptx
10b- Rabin Karp String Matching Problem.pptx10b- Rabin Karp String Matching Problem.pptx
10b- Rabin Karp String Matching Problem.pptxAOUNHAIDER7
 
Lesson 1 see lesson plans
Lesson 1   see lesson plansLesson 1   see lesson plans
Lesson 1 see lesson plansAngela Phillips
 
Order of operations
Order of operationsOrder of operations
Order of operationsformatic20
 
Numerical Methods for Engineers 6th Edition Chapra Solutions Manual
Numerical Methods for Engineers 6th Edition Chapra Solutions ManualNumerical Methods for Engineers 6th Edition Chapra Solutions Manual
Numerical Methods for Engineers 6th Edition Chapra Solutions Manualwebavaq
 
Module For Mathematics
Module For Mathematics Module For Mathematics
Module For Mathematics jrbt2014
 
Topic 2_revised.pptx
Topic 2_revised.pptxTopic 2_revised.pptx
Topic 2_revised.pptxJAYAPRIYAR7
 
Dat 305 dat305 dat 305 education for service uopstudy.com
Dat 305 dat305 dat 305 education for service   uopstudy.comDat 305 dat305 dat 305 education for service   uopstudy.com
Dat 305 dat305 dat 305 education for service uopstudy.comULLPTT
 
Special topics about stocks and bonds using algebra
Special topics about stocks and bonds using algebraSpecial topics about stocks and bonds using algebra
Special topics about stocks and bonds using algebraRomualdoDayrit1
 

Ähnlich wie Evaluation expression (20)

LET US C (5th EDITION) CHAPTER 1 ANSWERS
LET US C (5th EDITION) CHAPTER 1 ANSWERSLET US C (5th EDITION) CHAPTER 1 ANSWERS
LET US C (5th EDITION) CHAPTER 1 ANSWERS
 
Sept. 15, 2014
Sept. 15, 2014Sept. 15, 2014
Sept. 15, 2014
 
3rd Semester Computer Science and Engineering (ACU) Question papers
3rd Semester Computer Science and Engineering  (ACU) Question papers3rd Semester Computer Science and Engineering  (ACU) Question papers
3rd Semester Computer Science and Engineering (ACU) Question papers
 
machine_learning.pptx
machine_learning.pptxmachine_learning.pptx
machine_learning.pptx
 
Lec19
Lec19Lec19
Lec19
 
10b- Rabin Karp String Matching Problem.pptx
10b- Rabin Karp String Matching Problem.pptx10b- Rabin Karp String Matching Problem.pptx
10b- Rabin Karp String Matching Problem.pptx
 
random test
random testrandom test
random test
 
Lesson 1 see lesson plans
Lesson 1   see lesson plansLesson 1   see lesson plans
Lesson 1 see lesson plans
 
lec4.ppt
lec4.pptlec4.ppt
lec4.ppt
 
Order of operations
Order of operationsOrder of operations
Order of operations
 
Numerical Methods for Engineers 6th Edition Chapra Solutions Manual
Numerical Methods for Engineers 6th Edition Chapra Solutions ManualNumerical Methods for Engineers 6th Edition Chapra Solutions Manual
Numerical Methods for Engineers 6th Edition Chapra Solutions Manual
 
Matlab-1.pptx
Matlab-1.pptxMatlab-1.pptx
Matlab-1.pptx
 
Chap01
Chap01Chap01
Chap01
 
Ezmath
EzmathEzmath
Ezmath
 
Module For Mathematics
Module For Mathematics Module For Mathematics
Module For Mathematics
 
Topic 2_revised.pptx
Topic 2_revised.pptxTopic 2_revised.pptx
Topic 2_revised.pptx
 
Java Bytecodes by Example
Java Bytecodes by ExampleJava Bytecodes by Example
Java Bytecodes by Example
 
Dat 305 dat305 dat 305 education for service uopstudy.com
Dat 305 dat305 dat 305 education for service   uopstudy.comDat 305 dat305 dat 305 education for service   uopstudy.com
Dat 305 dat305 dat 305 education for service uopstudy.com
 
Special topics about stocks and bonds using algebra
Special topics about stocks and bonds using algebraSpecial topics about stocks and bonds using algebra
Special topics about stocks and bonds using algebra
 
Syntaxdirected
SyntaxdirectedSyntaxdirected
Syntaxdirected
 

Mehr von Jonghoon Park

Mehr von Jonghoon Park (14)

8150.graphs
8150.graphs8150.graphs
8150.graphs
 
Equivalence relations
Equivalence relationsEquivalence relations
Equivalence relations
 
Sparse matrices
Sparse matricesSparse matrices
Sparse matrices
 
Polynomials
PolynomialsPolynomials
Polynomials
 
Dynamically linked queues
Dynamically linked queuesDynamically linked queues
Dynamically linked queues
 
Dynamically linked stacks
Dynamically linked stacksDynamically linked stacks
Dynamically linked stacks
 
Singly linked lists
Singly linked listsSingly linked lists
Singly linked lists
 
Maze
MazeMaze
Maze
 
Sdoku
SdokuSdoku
Sdoku
 
N queen
N queenN queen
N queen
 
Hemilton cycle circuit
Hemilton cycle circuitHemilton cycle circuit
Hemilton cycle circuit
 
Good numbers
Good numbersGood numbers
Good numbers
 
Min inconmensurable weight
Min inconmensurable weightMin inconmensurable weight
Min inconmensurable weight
 
Garden for princess
Garden for princessGarden for princess
Garden for princess
 

Kürzlich hochgeladen

A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 

Kürzlich hochgeladen (20)

A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 

Evaluation expression

  • 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. 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. 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. 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. 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. 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. 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] + +