Atholton High School Columbia, Maryland Nifty Assignments: Mighty Cabbage Patch Micro.

Slides:



Advertisements
Similar presentations
Operators and Arithmetic Operations. Operators An operator is a symbol that instructs the code to perform some operations or actions on one or more operands.
Advertisements

INFIX, PREFIX, & POSTFIX EXPRESSIONS. Infix Notation We usually write algebraic expressions like this: a + b This is called infix notation, because the.
CS Data Structures ( 資料結構 ) Chapter 3: Stacks and Queues Spring 2012.
Stacks & Their Applications COP Stacks  A stack is a data structure that stores information arranged like a stack.  We have seen stacks before.
Stacks - 3 Nour El-Kadri CSI Evaluating arithmetic expressions Stack-based algorithms are used for syntactical analysis (parsing). For example.
Prefix, Postfix, Infix Notation
Arithmetic Expressions Infix form –operand operator operand 2+3 or a+b –Need precedence rules –May use parentheses 4*(3+5) or a*(b+c)
COSC 2006 Chapter 7 Stacks III
Yinchong Han Linjia Jiang. Introduction There are three forms of expressions which are prefix, infix and postfix notation. The project will evaluate infix.
D ATA S TRUCTURE MSc.IT Ali Abdul Karem Habib. S TACK A PPLICATIONS Web browser: stores the addresses of recently visited sites on a stack. Each time.
Joseph Lindo Abstract Data Types Sir Joseph Lindo University of the Cordilleras.
C o n f i d e n t i a l Developed By Nitendra NextHome Subject Name: Data Structure Using C Title : Overview of Stack.
1BA3 G Lacey Lecture 51 Evaluating mathematical expressions  How do computers evaluate x + y or any mathematical expression ?  Answer : “Reverse Polish.
Arithmetic Expressions
Department of Technical Education Andhra Pradesh
Stacks.
Infix to postfix conversion Process the tokens from a vector infixVect of tokens (strings) of an infix expression one by one When the token is an operand.
Infix, Postfix, Prefix.
1 CSCD 326 Data Structures I Infix Expressions. 2 Infix Expressions Binary operators appear between operands: W - X / Y - Z Order of evaluation is determined.
) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression.
More About Stacks: Stack Applications Dan Nguyen CS 146, Spring 2004 Professor Sin-Min Lee.
Evaluation of Expressions
The Stack and Queue Types Lecture 10 Hartmut Kaiser
Exam 1 –Monday June 25 th –open Book / Open Notes –No Electronic Devices (calculators, laptops, etc) –Room Number: W –Time: 5:30pm to 8:00pm.
Data Structures Lecture : Stacks (Infix, Postfix and Prefix Expressions) Azhar Maqsood NUST Institute of Information Technology (NIIT)
Stack Data Structure By : Imam M Shofi. What is stack? A stack is a limited version of an array. A stack is a limited version of an array. New elements,
Stack Applications.
CSC 205 Programming II Postfix Expressions. Recap: Stack Stack features Orderly linear structure Access from one side only – top item Stack operations.
Computer Science Department Data Structure & Algorithms Problem Solving with Stack.
Stacks  Introduction  Applications  Implementations  Complex Applications.
1 C++ Classes and Data Structures Jeffrey S. Childs Chapter 2 Overloaded Operators, Class Templates, and Abstraction Jeffrey S. Childs Clarion University.
EC-211 DATA STRUCTURES LECTURE 8. STACK APPLICATIONS Infix, Prefix, and Postfix Expressions Example – Infix: A+B – Prefix: +AB – Postfix: AB+
Stack Applications Qamar Rehman.
Stacks An Abstract Data Type. Restricted Access Unlike arrays, stacks only allow the top most item to be accessed at any time The interface of a stack.
Wednesday, March 2 Homework #2 is posted Homework #2 is posted Due Friday, March 4 (BOC) Due Friday, March 4 (BOC) Program #5 is posted Program #5 is posted.
CHP-3 STACKS.
Prefix, Postfix, Infix Notation. Infix Notation  To add A, B, we write A+B  To multiply A, B, we write A*B  The operators ('+' and '*') go in between.
Stacks A stack is a linear data structure that can be accessed only at one of its ends for storing and retrieving data LIFO (Last In First Out) structure.
DATA STRUCTURES Application of Stack – Infix to Postfix conversion a Joshua Presentation.
Prof. I. J. Chung Data Structure #5 Professor I. J. Chung.
CC 215 DATA STRUCTURES MORE ABOUT STACK APPLICATIONS Dr. Manal Helal - Fall 2014 Lecture 6 AASTMT Engineering and Technology College 1.
Applications of Stack Maitrayee Mukerji. Stacks Last In First Out (LIFO List) ◦ FILO? Insertions and Deletions from the same end called the Top Push(),
Operators & Expressions
Review Use of Stack Introduction Stack in our life Stack Operations
Revised based on textbook author’s notes.
COMPSCI 107 Computer Science Fundamentals
Infix to postfix conversion
Data Structures and Algorithms
MEMORY REPRESENTATION OF STACKS
Stacks.
CSC 172 DATA STRUCTURES.
Data Structures and Algorithms
Copyright ©2012 by Pearson Education, Inc. All rights reserved
STACKS.
Stacks Chapter 4.
Stack application: postponing data usage
Algorithms and Data Structures
STACK CHAPTER 03 Developed By :- Misha Ann Alexander Data Structures.
Visit for more Learning Resources
PART II STACK APPLICATIONS
Stacks Chapter 5 Adapted from Pearson Education, Inc.
More About Stacks: Stack Applications
Lecture No.07 Data Structures Dr. Sohail Aslam
Queue Applications Lecture 31 Mon, Apr 9, 2007.
(Part 2) Infix, Prefix & Postfix
Stack.
Queue Applications Lecture 31 Tue, Apr 11, 2006.
More About Stacks: Stack Applications
Stacks A stack is an ordered set of elements, for which only the last element placed into the stack is accessible. The stack data type is also known as.
Presentation transcript:

Atholton High School Columbia, Maryland Nifty Assignments: Mighty Cabbage Patch Micro

Infix Expressions A + B * C Postfix Expressions ABC*+ Prefix Expressions +A*BC Operators Operands

Infix Expressions Converting Postfix String Assembly Language Code

Step 1 Creating a postfix string using a stack Let’s try a simple one: A + B * C

Infix String Operator Stack Postfix String A+B*CA+B*CA+B*CA+B*CRule Every operator gets pushed onto the operator stack but not until all operators with equal or greater precedence have been popped. Operands are appended to the postfix string immediately. + AABA + *AB AB+ C+* * +

Let’s try a more difficult one: A – B / C $ D * E

Infix String Operator Stack Postfix String A–B/C$D*EA–B/C$D*EA–B/C$D*EA–B/C$D*E A – A B A – /AB AB– C–/ –/ $ABC –/$ ABC$/ – *–* D ABCD ABC$/DE One for you to try: V + W * X $ Y – Z * –

What about parentheses? (A + B) * (C – D) $ E * F

Infix String Operator Stack Postfix String A ( A B A – ( * (A+B)*(C–D)$E*F(A+B)*(C–D)$E*F(A+B)*(C–D)$E*F(A+B)*(C–D)$E*F ( +(+ AB+ AB+* ( AB+ AB+C *( AB+C *( AB+C D – *( AB+C D – * * $ AB+C D – *$ AB+C D – E * AB+C D – E $ * * AB+C D – E $ * F *

Step 2 Creating assembly language code using a stack

Concept and Terminology Accumulator: Where arithmetic takes place LDA A: Load the accumulator with number stored in location A ADD B: Add to the accumulator the number stored in location B STA T 0 : Store value from accumulator in T 0

Postfix String Operand Stack ALC ABC*+ABC*+ABC*+ABC*+Rule When you meet an operator, pop two elements from the stack. The first element becomes the right operand; the other becomes the left. B A C A A BA LDA B MUL C STA T 0 T0T0T0T0 LDA A ADD T 0 STA T 1 T1T1T1T1

Postfix String Operand Stack ALC A LDA A B AB+CD–E$*F*AB+CD–E$*F*AB+CD–E$*F*AB+CD–E$*F* T0T0T0T0 C A ADD B STA T 0 T0T0T0T0 T0T0T0T0C D T0T0T0T0 LDA C SUB D STA T 1 T1T1T1T1 T0T0T0T0 T1T1T1T1E T0T0T0T0 LDA T 1 EXP E STA T 2 T2T2T2T2 T3T3T3T3 LDA T 0 MUL T 2 STA T 3 T3T3T3T3 F T4T4T4T4 LDA T 3 MUL F STA T 4 One for you to try: A B + C D E – / F + * G –

Pseudocode Infix Expression Postfix String Infix [i] Action Push onto operator stack postfix string += infix [i] operator.pop (temp) while (temp != '('){ postfix string += temp operator.pop (temp)} '+', '-', '*', '/' while (!done && !operator.isEmpty ()) if (precedence (operator.top (), infix [i]) postfix string += operator.pop (temp) else else done = true '(' 'A'…'Z' ')'

Pseudocode Postfix Expression ALC Postfix [i] Action Push onto operand stack operand.pop (rtopnd) operand.pop (ltopnd) Write ALC Push temp onto operand stack Increase value of temp position '+', '-', '*', '/' 'A'...'Z'