compilers
play

Compilers Structure of a Compiler Alex Aiken Intro to Compilers - PowerPoint PPT Presentation

Compilers Structure of a Compiler Alex Aiken Intro to Compilers 1. Lexical Analysis 2. Parsing 3. Semantic Analysis 4. Optimization 5. Code Generation Alex Aiken Intro to Compilers First step: recognize words. Smallest unit above


  1. Compilers Structure of a Compiler Alex Aiken

  2. Intro to Compilers 1. Lexical Analysis 2. Parsing 3. Semantic Analysis 4. Optimization 5. Code Generation Alex Aiken

  3. Intro to Compilers • First step: recognize words. – Smallest unit above letters This is a sentence. Alex Aiken

  4. Intro to Compilers ist his ase nte nce Alex Aiken

  5. Intro to Compilers • Lexical analysis divides program text into “words” or “tokens” if x == y then z = 1; else z = 2; Alex Aiken

  6. Intro to Compilers • Once words are understood, the next step is to understand sentence structure • Parsing = Diagramming Sentences – The diagram is a tree Alex Aiken

  7. Intro to Compilers This line is a longer sentence article noun verb article adjective noun subject object sentence Alex Aiken

  8. Intro to Compilers if x == y then z = 1; else z = 2; == y z x 2 z 1 relation assign assign predicate then-stmt else-stmt if-then-else Alex Aiken

  9. Intro to Compilers • Once sentence structure is understood, we can try to understand “meaning” – This is hard! • Compilers perform limited semantic analysis to catch inconsistencies Alex Aiken

  10. Intro to Compilers • Example: Jack said Jerry left his assignment at home. • Even worse: Jack said Jack left his assignment at home? Alex Aiken

  11. Intro to Compilers { • Programming languages int Jack = 3; define strict rules to { avoid such ambiguities int Jack = 4; cout << Jack; } } Alex Aiken

  12. Intro to Compilers • Compilers perform many semantic checks besides variable bindings • Example: Jack left her homework at home. • A “type mismatch” between her and Jack; we know they are different people Alex Aiken

  13. Intro to Compilers • Optimization has no strong counterpart in English – But a little bit like editing • Automatically modify programs so that they – Run faster – Use less memory Alex Aiken

  14. Intro to Compilers X = Y * 0 is the same as X = 0 Alex Aiken

  15. Intro to Compilers • Produces assembly code (usually) • A translation into another language – Analogous to human translation Alex Aiken

  16. Intro to Compilers • The overall structure of almost every compiler adheres to our outline • The proportions have changed since FORTRAN Alex Aiken

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend