goran Šuković, university of montenegro 1/21 compiler construction course at university of...

21
Goran Goran Šuković, University of Montenegro Šuković, University of Montenegro 1 1 /21 /21 Compiler Construction Compiler Construction Course at Course at University University of Montenegro of Montenegro 7 7 th th Workshop on “Software Workshop on “Software Engineering Education and Engineering Education and Reverse Engineering”, Risan, Reverse Engineering”, Risan, 9 – 14. Sep. 2007. 9 – 14. Sep. 2007.

Post on 18-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Goran Šuković, University of Montenegro 1/21 Compiler Construction Course at University of Montenegro 7 th Workshop on “Software Engineering Education

Goran Goran Šuković, University of MontenegroŠuković, University of Montenegro 11/21/21

Compiler ConstructionCompiler Construction Course at Course at University of University of

MontenegroMontenegro

77thth Workshop on “Software Workshop on “Software Engineering Education and Reverse Engineering Education and Reverse

Engineering”, Risan, 9 – 14. Sep. Engineering”, Risan, 9 – 14. Sep. 2007.2007.

Page 2: Goran Šuković, University of Montenegro 1/21 Compiler Construction Course at University of Montenegro 7 th Workshop on “Software Engineering Education

Goran Goran Šuković, University of MontenegroŠuković, University of Montenegro 22/21/21

AgendaAgenda

• HistoryHistory

• Module structureModule structure

• WorkloadWorkload

• Learning outcomesLearning outcomes

• Lectures and practicalsLectures and practicals

• Recommended booksRecommended books

• FutureFuture

Page 3: Goran Šuković, University of Montenegro 1/21 Compiler Construction Course at University of Montenegro 7 th Workshop on “Software Engineering Education

Goran Goran Šuković, University of MontenegroŠuković, University of Montenegro 33/21/21

History (1)History (1)

• Started in 1988 – professor Ratko Started in 1988 – professor Ratko OrlandiOrlandićć

• one-semester one-semester elective elective modulemodule for for 4th 4th yearyear students, students, Mathematics and Mathematics and Computer Science Computer Science programmeprogramme

• 2 lectures + 2 2 lectures + 2 practicals per weekpracticals per week

• From 1993 – compulsory From 1993 – compulsory modulemodule

Page 4: Goran Šuković, University of Montenegro 1/21 Compiler Construction Course at University of Montenegro 7 th Workshop on “Software Engineering Education

Goran Goran Šuković, University of MontenegroŠuković, University of Montenegro 44/21/21

History (2)History (2)

• 2001 – first major revision2001 – first major revision

• one-semester compulsory module for 3one-semester compulsory module for 3rdrd year students, academic studies, year students, academic studies, Computer Science programme, Computer Science programme, Mathematics and Computer Science Mathematics and Computer Science programme, and also applied studiesprogramme, and also applied studies

• 3 lectures + 2 practicals per week3 lectures + 2 practicals per week

• 2006 – new revision, 2 lectures + 2 2006 – new revision, 2 lectures + 2 practicals, 5 ECTS credits, starting in 2008practicals, 5 ECTS credits, starting in 2008

Page 5: Goran Šuković, University of Montenegro 1/21 Compiler Construction Course at University of Montenegro 7 th Workshop on “Software Engineering Education

Goran Goran Šuković, University of MontenegroŠuković, University of Montenegro 55/21/21

Why to study compilersWhy to study compilers??

• The number of people who write compilers is The number of people who write compilers is small, so why is a module about compiler small, so why is a module about compiler construction a compulsory part of a computer construction a compulsory part of a computer science course? science course?

• One reason is that, though few graduates of One reason is that, though few graduates of the course will end up writing compilers, all will the course will end up writing compilers, all will have to use them have to use them

• Many of the techniques used in compilers have Many of the techniques used in compilers have application in other areas such as dialogue and application in other areas such as dialogue and human-computer interface designhuman-computer interface design

Page 6: Goran Šuković, University of Montenegro 1/21 Compiler Construction Course at University of Montenegro 7 th Workshop on “Software Engineering Education

Goran Goran Šuković, University of MontenegroŠuković, University of Montenegro 66/21/21

Module structureModule structure

• Number of ECTS credits: 6Number of ECTS credits: 6• Prerequisite knowledgePrerequisite knowledge

– Students must have a prior knowledge of Students must have a prior knowledge of programming in C programming in C

• Prerequisite modulesPrerequisite modules– Programming I Programming I – Programming II Programming II

Page 7: Goran Šuković, University of Montenegro 1/21 Compiler Construction Course at University of Montenegro 7 th Workshop on “Software Engineering Education

Goran Goran Šuković, University of MontenegroŠuković, University of Montenegro 77/21/21

Taken byTaken by

• academic studies, Computer Science academic studies, Computer Science programmeprogramme

• academic studies, Mathematics and academic studies, Mathematics and Computer Science programmeComputer Science programme

• applied studies, Information applied studies, Information technologies programmetechnologies programme

Page 8: Goran Šuković, University of Montenegro 1/21 Compiler Construction Course at University of Montenegro 7 th Workshop on “Software Engineering Education

Goran Goran Šuković, University of MontenegroŠuković, University of Montenegro 88/21/21

WorkloadWorkload

• Lectures: 14 x 2 hr 15 min lectures.Lectures: 14 x 2 hr 15 min lectures.

• Practicals: 14 x 1 hr 30 min practical.Practicals: 14 x 1 hr 30 min practical.

• Private study: 74.5 hrs.Private study: 74.5 hrs.

• Assessment: Assessment: – Midterm – 3 hours written exam (worth 35 Midterm – 3 hours written exam (worth 35

marks)marks)– Final – 3 hours written exam (worth 35 marks)Final – 3 hours written exam (worth 35 marks)– Homeworks – 6 HW (worth 4 marks each)Homeworks – 6 HW (worth 4 marks each)– Quizzes – 3 quizzes (worth 2 marks each)Quizzes – 3 quizzes (worth 2 marks each)

Page 9: Goran Šuković, University of Montenegro 1/21 Compiler Construction Course at University of Montenegro 7 th Workshop on “Software Engineering Education

Goran Goran Šuković, University of MontenegroŠuković, University of Montenegro 99/21/21

Learning Outcomes (1)Learning Outcomes (1)

• The aim of this module is to introduce the The aim of this module is to introduce the student to the theory and practice of student to the theory and practice of programming language compilation programming language compilation

• It works through the “front end” of It works through the “front end” of compilation: lexical and syntax analysis. By compilation: lexical and syntax analysis. By the middle of the module the student will the middle of the module the student will be in a position to write a lexical scanner be in a position to write a lexical scanner and a parser for a context-free language, and a parser for a context-free language, including the use of compiler tools including the use of compiler tools

• Student will also have a solid understanding Student will also have a solid understanding on the underlying theory of formal on the underlying theory of formal languages languages

Page 10: Goran Šuković, University of Montenegro 1/21 Compiler Construction Course at University of Montenegro 7 th Workshop on “Software Engineering Education

Goran Goran Šuković, University of MontenegroŠuković, University of Montenegro 1010/21/21

Learning Outcomes (2)Learning Outcomes (2)

• Student should have a better appreciation of Student should have a better appreciation of good programming practice in terms of good programming practice in terms of program compilation program compilation

• Student should be able to describe compiler Student should be able to describe compiler construction methods and algorithms, and construction methods and algorithms, and especially apply them to examples especially apply them to examples

• Student be able to implement the "back end" Student be able to implement the "back end" of a compiler for a simple programming of a compiler for a simple programming language using the techniques presented in language using the techniques presented in the lectures the lectures

Page 11: Goran Šuković, University of Montenegro 1/21 Compiler Construction Course at University of Montenegro 7 th Workshop on “Software Engineering Education

Goran Goran Šuković, University of MontenegroŠuković, University of Montenegro 1111/21/21

Learning Outcomes (3)Learning Outcomes (3)

• Student assess the advantages of Student assess the advantages of standard programming language features standard programming language features with respect to their implementation and with respect to their implementation and performance costs performance costs

• Student read critically a programming Student read critically a programming language specificationlanguage specification

Page 12: Goran Šuković, University of Montenegro 1/21 Compiler Construction Course at University of Montenegro 7 th Workshop on “Software Engineering Education

Goran Goran Šuković, University of MontenegroŠuković, University of Montenegro 1212/21/21

Content – LecturesContent – Lectures (1) (1)

• Introduction to compilingIntroduction to compiling• Automata. Regular expressions. Intro to Automata. Regular expressions. Intro to

lexical analysis lexical analysis • Lexical analysis.Lexical analysis. Flex. Flex. Grammars and Grammars and

languages languages • TTop-downop-down parsing parsing• Bottom-upBottom-up parsparsing. ing. LR(0), LR(1)LR(0), LR(1), and , and

SLR(1)SLR(1) • LALR parsersLALR parsers• Syntax-directed translationSyntax-directed translation

Page 13: Goran Šuković, University of Montenegro 1/21 Compiler Construction Course at University of Montenegro 7 th Workshop on “Software Engineering Education

Goran Goran Šuković, University of MontenegroŠuković, University of Montenegro 1313/21/21

Content – LecturesContent – Lectures (2) (2)

• SemantiSemantical analysiscal analysis.. Type checking for Type checking for imperative languagesimperative languages

• RRunun--time time organization organization • Object-oriented languagesObject-oriented languages• Intermediate languages Intermediate languages • Code generation Code generation • Program analysis and transformationProgram analysis and transformation • DDataflow analataflow analysisysis• Loop optimization. Register allocationLoop optimization. Register allocation

Page 14: Goran Šuković, University of Montenegro 1/21 Compiler Construction Course at University of Montenegro 7 th Workshop on “Software Engineering Education

Goran Goran Šuković, University of MontenegroŠuković, University of Montenegro 1414/21/21

Content – Practicals (1)Content – Practicals (1)

• DFA and NFADFA and NFA• Regular expressions. Transforming Regular expressions. Transforming

regular expressions to NFAregular expressions to NFA• Transforming NFA to DFA. Minimizing Transforming NFA to DFA. Minimizing

number of states in DFA number of states in DFA • FLEX examplesFLEX examples• Writing and transforming context-Writing and transforming context-

free grammarsfree grammars

Page 15: Goran Šuković, University of Montenegro 1/21 Compiler Construction Course at University of Montenegro 7 th Workshop on “Software Engineering Education

Goran Goran Šuković, University of MontenegroŠuković, University of Montenegro 1515/21/21

Content – Practicals (2)Content – Practicals (2)

• BISON examplesBISON examples

• Intermediate code examplesIntermediate code examples

• Overview of MIPS Overview of MIPS

• Using SPIMUsing SPIM

• Generating MIPS from ASTGenerating MIPS from AST

Page 16: Goran Šuković, University of Montenegro 1/21 Compiler Construction Course at University of Montenegro 7 th Workshop on “Software Engineering Education

Goran Goran Šuković, University of MontenegroŠuković, University of Montenegro 1616/21/21

HomeworksHomeworks

• 11stst HW – Automata HW – Automata

• 22ndnd HW – Flex for Decaf HW – Flex for Decaf

• 33rdrd HW – Grammars and languages HW – Grammars and languages

• 44thth HW – Building AST for Decaf using HW – Building AST for Decaf using BisonBison

• 55thth HW – Semantic analyzer for Decaf HW – Semantic analyzer for Decaf

• 66thth HW – MIPS Code Generation HW – MIPS Code Generation

Page 17: Goran Šuković, University of Montenegro 1/21 Compiler Construction Course at University of Montenegro 7 th Workshop on “Software Engineering Education

Goran Goran Šuković, University of MontenegroŠuković, University of Montenegro 1717/21/21

Recommended BooksRecommended Books

• Torczon, Cooper Torczon, Cooper -- Engineering a CompilerEngineering a Compiler, , Morgan Kaufmann 2002Morgan Kaufmann 2002

• Aho A.V. et al. - Aho A.V. et al. - Compilers: Principles, Compilers: Principles, Techniques and Tools, 2Techniques and Tools, 2ndnd Edition, Edition, Addison Addison Wesley 2006 Wesley 2006

• Andrew W. Appel - Andrew W. Appel - Modern Compiler Modern Compiler Implementation in C/Java/ML, Implementation in C/Java/ML, Cambridge Cambridge University Press 1998/2002University Press 1998/2002

• D Grune et al. - D Grune et al. - Modern Compiler Design, Modern Compiler Design, Wiley 2000Wiley 2000

Page 18: Goran Šuković, University of Montenegro 1/21 Compiler Construction Course at University of Montenegro 7 th Workshop on “Software Engineering Education

Goran Goran Šuković, University of MontenegroŠuković, University of Montenegro 1818/21/21

Teaching MaterialsTeaching Materials

• Notes and exercise sheets are Notes and exercise sheets are providedprovided

• Copies of slides and examples used Copies of slides and examples used in lectures can be downloaded from in lectures can be downloaded from the module web page the module web page

• Information and feedback are posted Information and feedback are posted on the module web pages (on the module web pages (www.pmf.cg.ac.yuwww.pmf.cg.ac.yu))

Page 19: Goran Šuković, University of Montenegro 1/21 Compiler Construction Course at University of Montenegro 7 th Workshop on “Software Engineering Education

Goran Goran Šuković, University of MontenegroŠuković, University of Montenegro 1919/21/21

Students (2006-7)Students (2006-7)Bologna studentsBologna students Non BolognaNon Bologna

20 students, 14 20 students, 14 passed, passed,

A – 0A – 0

B – 3B – 3

C – 3C – 3

D – 2D – 2

E – 6E – 6

F – 6F – 6

26 students, 12 26 students, 12 passedpassed

10 – 010 – 0

9 – 09 – 0

8 – 18 – 1

7 – 67 – 6

6 – 56 – 5

5 – 145 – 14

Page 20: Goran Šuković, University of Montenegro 1/21 Compiler Construction Course at University of Montenegro 7 th Workshop on “Software Engineering Education

Goran Goran Šuković, University of MontenegroŠuković, University of Montenegro 2020/21/21

Student' Student' remarkremarkss

•Practicals/exams/lecturer are too demanding

•Programming in C is very hard

• I need more time for homeworks

• I don't know how to use pointers in C... read data from files ... start Flex ...

Page 21: Goran Šuković, University of Montenegro 1/21 Compiler Construction Course at University of Montenegro 7 th Workshop on “Software Engineering Education

Goran Goran Šuković, University of MontenegroŠuković, University of Montenegro 2121/21/21

FutureFuture

• From 2008From 2008– Substantial reduction of lectures Substantial reduction of lectures – Less demanding homeworksLess demanding homeworks– Using Java instead CUsing Java instead C– Using JLex and JBison instead Flex and BisonUsing JLex and JBison instead Flex and Bison– MIPS or x86 or ...MIPS or x86 or ...

• More informationMore information– www.pmf.cg.ac.yuwww.pmf.cg.ac.yu– [email protected]@rc.pmf.cg.ac.yu