day17 - COP 3503 Computer Science II CLASS NOTES - DAY #17...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
COP 3503 – Computer Science II CLASS NOTES - DAY #17 PART III - APPLICATIONS Chapter 11 – Stacks and Compilers Stacks are a commonly used data structure in compilers. We will examine two of the basic uses of the stack data structure in a compiler, (1) basic syntax checking operations and (2) operator precedence parsing. Basic Syntax Checking Common programmer errors lead to a situation where the source code cannot be properly interpreted by the compiler to convert the source code into object code. Common errors include: too many opening parentheses, too many closing parentheses, symbol mismatch (i.e., expected ) saw }). The order of appearance of each symbol is important, simply counting the number of occurrences of each symbol is not sufficient for handling the problem as [(a)] is legal but [(a]) clearly is not. The symbols must be properly balanced in terms of their order of appearance. A basic algorithm for checking symbol balance is shown below: Day 17 - 1 Simple Algorithm for Checking Symbol Balance 1 – Make an empty stack. 2 – Read symbols until the end of the file. a – if the symbol is an opening symbol – push it onto the stack. b – if the symbol is a closing symbol and the stack is empty – return error. c – otherwise, pop the stack. if the symbol does not match the popped symbol – report an error.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/22/2009 for the course COP 3503c taught by Professor Staff during the Spring '08 term at University of Central Florida.

Page1 / 4

day17 - COP 3503 Computer Science II CLASS NOTES - DAY #17...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online