Presentation is loading. Please wait.

Presentation is loading. Please wait.

Planning a compiler Source Language –A subset of C Target Language –Assembler Performance Criteria –Compiler speed –Code quality –Error diagnostics –Portability.

Similar presentations


Presentation on theme: "Planning a compiler Source Language –A subset of C Target Language –Assembler Performance Criteria –Compiler speed –Code quality –Error diagnostics –Portability."— Presentation transcript:

1 Planning a compiler Source Language –A subset of C Target Language –Assembler Performance Criteria –Compiler speed –Code quality –Error diagnostics –Portability Re-target-ability (for a new target language) Re-host-ability (run on a new machine) –Maintainability

2 Approaches to compiler development Bootstrapping –Using the facilities offered by a language to compile itself is the essence of bootstrapping Automatic generator –Lex –Yacc

3 A look at the C Compilers Three-quarters of the code in PCC(Portable C Compiler) is independent of the target machine. All these compilers are essentially two-pass. –The PDP-11comipler has an optional third pass that does optimization ( peephole optimization ) on the assembly-language output

4 Lexical and syntax analysis intermediate code generation Code generation Post optimization Postfix or prefix form for expressions assembly code otherwise Assembly language Source code Assembly language

5 A Programming Project Main tasks –Translate the source program in C into an intermediate representation such as quadruples –Interpret the intermediate representation –Implement a basic components of a compiler for a subset of C.

6 A Programming Project Suggested exercises –Design a symbol-table mechanism (Required) Search the symbol table for a given name Create a new entry for that name if none is present Delete from the symbol table all names local to a given function

7 A Programming Project Suggested exercises –Write an interpreter for quadruples(Optional) –Write the lexical analyzer(Required) Select internal codes for the tokens Decide the representation of constants Count lines for later use by an error-message handler Produce a listing of the source program if desired Write a program to enter the reserved words into the symbol table Design the lexical analyzer to be a function called by the parser Error handling

8 A Programming Project Suggested exercises –Write the semantic actions(Required) Do semantic analysis at this time. Converting integers to real numbers when necessary –Write the parser(Required) LALR parser generator (Yacc) –Write the error-handling routines (Optional)

9 A Programming Project Important Website about Lex/YACC –http://dinosaur.compilertools.net/ (Lex/Yacc Pages) –http://www.cs.princeton.edu/software/lcc/pkg/ –http://www.thefreecountry.com/compilers/cpp.shtml –http://www.thefreecountry.com/programming/ compilerconstruction.shtml –http://www.gnu.org/software/gcc/gcc.html –http://gcc.gnu.org/install/index.html

10 A Yacc/Lex Example Yacc/Lex for Pascal


Download ppt "Planning a compiler Source Language –A subset of C Target Language –Assembler Performance Criteria –Compiler speed –Code quality –Error diagnostics –Portability."

Similar presentations


Ads by Google