This preview shows pages 1–14. Sign up to view the full content.

CSE302: Compiler Design Instructor: Dr. Liang Cheng Department of Computer Science and Engineering P.C. Rossin College of Engineering & Applied Science Lehigh University January 18, 2007

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

View Full Document
Instructor: Dr. Liang Cheng CSE302: Compiler Design 01/18/07 Today’s Outline Recap A simple syntax-directed translator (Chapter 2) Introduction (Section 2.1) Syntax definition (Section 2.2) Parsing (Section 2.4) Summary and homework
Instructor: Dr. Liang Cheng CSE302: Compiler Design 01/18/07 Six Compilation Phases Lexical analysis Syntax analysis Semantic analysis Intermediate code generation Code optimization Code generation

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

View Full Document
Instructor: Dr. Liang Cheng CSE302: Compiler Design 01/18/07 Outline Recap A simple syntax-directed translator (Chapter 2) Introduction (Section 2.1) Syntax definition (Section 2.2) Parsing (Section 2.4) Summary and homework
Instructor: Dr. Liang Cheng CSE302: Compiler Design 01/18/07 Contents in Chapter 2 Illustrate some compiler techniques via developing a simple language translator coded in Java (Appendix A) Source language Target language: three-address code The front-end of a compiler

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

View Full Document
Instructor: Dr. Liang Cheng CSE302: Compiler Design 01/18/07 Six Compilation Phases Lexical analysis Syntax analysis Semantic analysis Intermediate code generation Code optimization Code generation
Instructor: Dr. Liang Cheng CSE302: Compiler Design 01/18/07 A Simplified Model of A Compiler Front End do i=i+1; while (a[i]>v); 1: i = i + 1 t1 = a[i] if t1>v goto 1

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

View Full Document
Instructor: Dr. Liang Cheng CSE302: Compiler Design 01/18/07 Outline Recap A simple syntax-directed translator (Chapter 2) Introduction (Section 2.1) Syntax definition (Section 2.2) Parsing (Section 2.4) Summary and homework
Instructor: Dr. Liang Cheng CSE302: Compiler Design 01/18/07 A Formal Method of Describing Syntax Backus-Naur Form (1959) For Algol 58 (John Backus, the Peter Naur) BNF is equivalent to context-free grammars Context-free grammars were developed by Noam Chomsky in mid-1950s to define a class of languages called context-free languages A BNF grammar defines a language Recognizer vs. generators A BNF grammar or description is a production- rule collection

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

View Full Document
Instructor: Dr. Liang Cheng CSE302: Compiler Design 01/18/07 BNF Rules A BNF rule defines an abstraction for syntactic structure <while_stmt> while ( <logic_expr> ) <stmt> Abstractions are used to represent classes of syntactic structures: they act like syntactic variables (also called nonterminal symbols ) Terminal symbols : lexemes and tokens
Instructor: Dr. Liang Cheng CSE302: Compiler Design 01/18/07 LHS & RHS of BNF Rules A rule has a left-hand side (LHS) and a right-hand side (RHS), and consists of terminal and/or nonterminal symbols An abstraction (or nonterminal symbol) can have more than one RHS <stmt> <single_stmt> | begin <stmt_list> end

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

View Full Document
Instructor: Dr. Liang Cheng CSE302: Compiler Design 01/18/07 BNF Functionality Describe grammars and derivations Describe lists of similar constructs Parse trees Powerful enough to avoid grammar ambiguity Operator precedence and associativity
Instructor: Dr. Liang Cheng

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern