Download presentation
Presentation is loading. Please wait.
Published byHope Patrick Modified over 9 years ago
1
Lecture 1 Overview Topics InstructionsReadings: January 9, 2006 CSCE 531 Compiler Construction
2
– 2 – CSCE 531 Spring 2006 Overview Today’s Lecture Pragmatics A little History Compilers vs Interpreter Data-Flow View of Compilers Why Study Compilers? Course PragmaticsReferences Chapter 1 Lord J.M. Keyne's Aphorism "What's not worth doing isn't worth doing well."
3
– 3 – CSCE 531 Spring 2006 Course Pragmatics Instructor: Manton Matthews Office: 3A57 Swearingen Office Hours: 9:15-10:30 M-TH others by appointment Phone: 777-3285 Email: “mm” at “sc” in domain “edu” Class Web Site: http://www.cse.sc.edu/class/csce531-001/ http://www.cse.sc.edu/class/csce531-001/ Class Directory on Linux Machines /class/csce531-001
4
– 4 – CSCE 531 Spring 2006 Class Directory on Linux Boxes /class/csce531-001/Subdirectories Web – web pages, lectures etc. Submissions - where dropboxed assignments go Handouts Examples Overview C tutorial (by end of day) Assignments
5
– 5 – CSCE 531 Spring 2006 Evolution of Programming First electronic computers – programmed by plugboard First electronic computers – programmed by plugboard Von Neumann – concept of stored program computer Von Neumann – concept of stored program computer Program stored in memory as data (1946) Fortran – first compiler, John Backus (1957) (BNF) Fortran – first compiler, John Backus (1957) (BNF) Lisp 1958 Lisp 1958 Cobol 1959 Cobol 1959 Algol68, Pascal Algol68, Pascal C Ritchie 1972 C Ritchie 1972 http://cm.bell-labs.com/cm/cs/who/dmr/chist.html C++, Java C++, Java Perl, python, ruby scripting languages Perl, python, ruby scripting languages
6
– 6 – CSCE 531 Spring 2006 Compiler vs Interpreter InterpreterCompiler
7
– 7 – CSCE 531 Spring 2006 Where’s Java? Hybrid Compilation step – translate source to bytecode Compilation step – translate source to bytecode Interpretive step – run bytecode program on Java Virtual Machine (JVM) Interpretive step – run bytecode program on Java Virtual Machine (JVM)
8
– 8 – CSCE 531 Spring 2006 Dataflow of Compilation Process
9
– 9 – CSCE 531 Spring 2006 Example of Dataflow of Compilation Process Source Program in file /class/csce531-001/Examples/ex1.cmain(){ int i, sum; int i, sum; for(i=0, sum=0; i < 100; ++i){ for(i=0, sum=0; i < 100; ++i){ sum = sum + i; sum = sum + i; } printf("Sum=%d\n", sum); printf("Sum=%d\n", sum);} Token Stream TokenCodeLexeme IDmain LPAREN( RPAREN) LBRACE{ INTint ”keyword” IDI COMMA, IDsum SEMICOLON ; …
10
– 10 – CSCE 531 Spring 2006 Intermediate Representation (Parse Tree)
11
– 11 – CSCE 531 Spring 2006 Assembly Code more ex1.s.file "ex1.c".file "ex1.c".def ___main;.def ___main;.text.textLC0:.ascii "Sum=%d\12\0".ascii "Sum=%d\12\0".globl _main.def _main;.scl.def _main;.scl_main: pushl %ebp pushl %ebp movl %esp, %ebp movl %esp, %ebp subl $24, %esp subl $24, %esp andl $-16, %esp andl $-16, %esp movl $0, %eax movl $0, %eax movl %eax, -12(%ebp) movl %eax, -12(%ebp) movl -12(%ebp), %eax movl -12(%ebp), %eax call __alloca call __alloca call ___main call ___main movl $0, -4(%ebp) movl $0, -4(%ebp) movl $0, -8(%ebp) movl $0, -8(%ebp) L2: cmpl $99, -4(%ebp) cmpl $99, -4(%ebp) jle L5 jle L5 jmp L3 jmp L3L5: movl -4(%ebp), %eax movl -4(%ebp), %eax leal -8(%ebp), %edx leal -8(%ebp), %edx addl %eax, (%edx) addl %eax, (%edx) leal -4(%ebp), %eax leal -4(%ebp), %eax incl (%eax) incl (%eax) jmp L2 jmp L2L3: movl -8(%ebp), %eax movl -8(%ebp), %eax movl %eax, 4(%esp) movl %eax, 4(%esp) movl $LC0, (%esp) movl $LC0, (%esp) call _printf call _printf leave leave ret ret.def _printf;.def _printf;
12
– 12 – CSCE 531 Spring 2006 Machine Code Loader phase – link in libraries #include #include /usr/lib/libc.a - standard library
13
– 13 – CSCE 531 Spring 2006 GCC and some of its flags GCC – Gnu (Gnu is Not Unix) C compiler gcc phases Preprocessor only gcc –E ex1.c > ex1.i Preprocessor only gcc –E ex1.c > ex1.i Stop with assembly gcc –S ex1.c Stop with assembly gcc –S ex1.c Compile onlygcc –c ex1.c Compile onlygcc –c ex1.c Loader- link in libraries Loader- link in librariesDisaasemblersobjdump
14
– 14 – CSCE 531 Spring 2006 Formal Language Theory Mathematical Models of languages where a language is just a set of strings of characters from a particular alphabet Examples L1 = {legitimate English words} L2 = {Keywords of C} L3 = { strings of zeroes and ones that have more zeroes} L3 = { strings of zeroes and ones that have more zeroes}
15
– 15 – CSCE 531 Spring 2006 Chomsky Hierarchy Noam Chomsky – famous Linguist came up with the Chomsky Hierarchy Level 1 – regular languages Level 2 – context free languages Level 3 – context sensitive languages Level 4 – unrestricted languages We will look at a few of these in our attempts to define efficient compilers
16
– 16 – CSCE 531 Spring 2006 Regular languages (level 1) Regular Expressions are expressions that represent regular languages The operators (the base ones are) Concatentation. Or juxtaposition Concatentation. Or juxtaposition Alternation | Alternation | Kleene closure * Kleene closure * For a regular expression R the language that is represents is denoted L(R)
17
– 17 – CSCE 531 Spring 2006 Deterministic Finite Automata A Deterministic finite automaton (DFA) is a mathematical model that consists of 1. a set of states S 2. a set of input symbols ∑, the input alphabet 3. a transition function δ: S x ∑ S that for each state and each input maps to the next state 4. a state s 0 that is distinguished as the start state 5. a set of states F distinguished as accepting (or final) states
18
– 18 – CSCE 531 Spring 2006 Example
19
– 19 – CSCE 531 Spring 2006 Lexical Analysis
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.