organization of the new course on complier construction in novi sad vladimir kurbalija, mirjana...

32
Organization of the Organization of the N N ew ew C C ourse on ourse on C C omplier omplier C C onstruction in Novi Sad onstruction in Novi Sad Vladimir Kurbalija Vladimir Kurbalija , Mirjana Ivanović , Mirjana Ivanović Department of Mathematics and Department of Mathematics and Informatics Informatics University of Novi Sad University of Novi Sad Serbia Serbia

Post on 18-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Organization of the Organization of the NNew ew CCourse on ourse on CComplier omplier

CConstruction in Novi Sad onstruction in Novi Sad

Vladimir KurbalijaVladimir Kurbalija, Mirjana Ivanović, Mirjana IvanovićDepartment of Mathematics and InformaticsDepartment of Mathematics and Informatics

University of Novi SadUniversity of Novi SadSerbiaSerbia

V. Kurbalija, M. IvanovV. Kurbalija, M. Ivanovićić

Organization of the New Course oOrganization of the New Course on CC in Novi Sad n CC in Novi Sad

AgendaAgenda

Previous Previous CC CourseCC Course Current CC CourseCurrent CC Course Assessment by students in Novi SadAssessment by students in Novi Sad Questionnaire and Exam resultsQuestionnaire and Exam results JCCC – MaterialJCCC – Material ConclusionConclusion

V. Kurbalija, M. IvanovV. Kurbalija, M. Ivanovićić

Organization of the New Course oOrganization of the New Course on CC in Novi Sad n CC in Novi Sad

CC CourseCC Course in Novi Sad in Novi Sad

One of core software courses at One of core software courses at Computer Science directionsComputer Science directions

7th semester CC1 (obligatory), 8th 7th semester CC1 (obligatory), 8th semester CC2 (elective), for students semester CC2 (elective), for students ofof Computer Science, Computer Science, Business Computer Science, Business Computer Science, Teaching of Computer Science Teaching of Computer Science

V. Kurbalija, M. IvanovV. Kurbalija, M. Ivanovićić

Organization of the New Course oOrganization of the New Course on CC in Novi Sad n CC in Novi Sad

Previous Previous CC CourseCC Course Practical approach Practical approach Development of Pascal- compiler Development of Pascal- compiler Subset of Pascal language:Subset of Pascal language:

data typesdata types: : booleanboolean and and integerinteger standard types, standard types, arrays and fixed records as structured types; arrays and fixed records as structured types;

basic statementsbasic statements: assignment statement, procedure : assignment statement, procedure call, call, ifif and and whilewhile statements; statements;

Standard input/outputStandard input/output ( (readread and and writewrite) procedures, ) procedures, user defined procedures including recursion.user defined procedures including recursion.

The implementation:The implementation: recursive-descent manner for syntax analysisrecursive-descent manner for syntax analysis code generation for abstract P machinecode generation for abstract P machine

V. Kurbalija, M. IvanovV. Kurbalija, M. Ivanovićić

Organization of the New Course oOrganization of the New Course on CC in Novi Sad n CC in Novi Sad

Previous Previous CC Course - CC Course - ExercisesExercises

Students repeat and train practical skills gained Students repeat and train practical skills gained during lecturesduring lectures

Several independent tasks – small grammarsSeveral independent tasks – small grammars Implementation language is Modula-2Implementation language is Modula-2 Compiler generator Coco/RCompiler generator Coco/R Tasks:Tasks:

Lexical and syntax analysis and some parts of semantic Lexical and syntax analysis and some parts of semantic analysis using Coco/Ranalysis using Coco/R

““Hand written” parsers (LA & SA)Hand written” parsers (LA & SA) ““Hand written” parsers with semantic analysis and rarely Hand written” parsers with semantic analysis and rarely

with code generation or interpretationwith code generation or interpretation Some algorithms on grammars (memory organisation, Some algorithms on grammars (memory organisation,

checking consistency, computing checking consistency, computing firstfirst and and follow follow sets…)sets…)

V. Kurbalija, M. IvanovV. Kurbalija, M. Ivanovićić

Organization of the New Course oOrganization of the New Course on CC in Novi Sad n CC in Novi Sad

AgendaAgenda

Previous Previous CC CourseCC Course Current CC CourseCurrent CC Course Assessment by students in Novi SadAssessment by students in Novi Sad Questionnaire and Exam resultsQuestionnaire and Exam results JCCC – MaterialJCCC – Material ConclusionConclusion

V. Kurbalija, M. IvanovV. Kurbalija, M. Ivanovićić

Organization of the New Course oOrganization of the New Course on CC in Novi Sad n CC in Novi Sad

Current CC CourseCurrent CC Course More theoretical approachMore theoretical approach on lectures on lectures Course goes through all phases of a compilerCourse goes through all phases of a compiler

writingwriting Shows the theoretical concepts underlying each Shows the theoretical concepts underlying each

phase as well as how to implement it efficientlyphase as well as how to implement it efficiently ExamplesExamples: MicroJava compiler in Java, target : MicroJava compiler in Java, target

language – subset of Java byte codelanguage – subset of Java byte code

Goals of the courseGoals of the course acquire the practical skills to write a simple compiler for acquire the practical skills to write a simple compiler for

an imperative programming language an imperative programming language understand the concepts of scanning, parsing, name understand the concepts of scanning, parsing, name

management in nested scopes, and code generation.management in nested scopes, and code generation. learn to transfer the skills also to general software learn to transfer the skills also to general software

engineering tasks engineering tasks

V. Kurbalija, M. IvanovV. Kurbalija, M. Ivanovićić

Organization of the New Course oOrganization of the New Course on CC in Novi Sad n CC in Novi Sad

Current CC CourseCurrent CC CourseStructure of LecturesStructure of Lectures

Overview (1 week)Overview (1 week) Lexical Analysis (1 week)Lexical Analysis (1 week) Syntax Analysis (2 weeks) --- TEST Syntax Analysis (2 weeks) --- TEST Attribute Grammars (1 week)Attribute Grammars (1 week) Symbol Table (2 weeks)Symbol Table (2 weeks) Code Generation (3 weeks) --- TESTCode Generation (3 weeks) --- TEST BU Parsing (2 weeks)BU Parsing (2 weeks) Compiler Generators (1 week) --- TESTCompiler Generators (1 week) --- TEST

V. Kurbalija, M. IvanovV. Kurbalija, M. Ivanovićić

Organization of the New Course oOrganization of the New Course on CC in Novi Sad n CC in Novi Sad

Current CC Course Current CC Course – – ExercisesExercises

Students should acquire practical skills Students should acquire practical skills in compiler writing in compiler writing

One (big) project divided in smaller One (big) project divided in smaller subtaskssubtasks

Students should write a small compiler Students should write a small compiler for a Java-like language - MicroJavafor a Java-like language - MicroJava

The implementation language is also The implementation language is also Java Java

V. Kurbalija, M. IvanovV. Kurbalija, M. Ivanovićić

Organization of the New Course oOrganization of the New Course on CC in Novi Sad n CC in Novi Sad

Current CC Course Current CC Course – – ExercisesExercises

Study material:Study material: Teaching material (slides)Teaching material (slides) Description of the projectDescription of the project Specification of MicroJava language (tokens, Specification of MicroJava language (tokens,

language grammar, semantic and context language grammar, semantic and context constraints)constraints)

Specification of MicroJava virtual machine Specification of MicroJava virtual machine (similar but simpler than Java VM) – Memory (similar but simpler than Java VM) – Memory layout and Instruction setlayout and Instruction set

Specification of object file formatSpecification of object file format

V. Kurbalija, M. IvanovV. Kurbalija, M. Ivanovićić

Organization of the New Course oOrganization of the New Course on CC in Novi Sad n CC in Novi Sad

Current Current CC Course – CC Course – ExercisesExercises

The project consists of three levels:The project consists of three levels: Level 1 Level 1 – implementation of a scanner – implementation of a scanner

and a parser for the language MicroJava, and a parser for the language MicroJava, error handling – 3 TASKSerror handling – 3 TASKS

Level 2Level 2 - deals with symbol table - deals with symbol table handling and type checking – 1 TASKhandling and type checking – 1 TASK

Level 3Level 3 - deals with code generation for - deals with code generation for the MicroJava – 1 TASKthe MicroJava – 1 TASK

V. Kurbalija, M. IvanovV. Kurbalija, M. Ivanovićić

Organization of the New Course oOrganization of the New Course on CC in Novi Sad n CC in Novi Sad

Current Current CC Course – CC Course – ExercisesExercises

Level 1 – Task 1Level 1 – Task 1

Lexical analysisLexical analysis Implementation of a scanner for MicroJavaImplementation of a scanner for MicroJava Scanner should skip blanks, end of line characters, Scanner should skip blanks, end of line characters,

tabulator characters and commentstabulator characters and comments Types of errors:Types of errors:

The occurrence of an invalid character (e.g., $)The occurrence of an invalid character (e.g., $) A missing quote at the end of the character constant ('x)A missing quote at the end of the character constant ('x) Integer constants that are too largeInteger constants that are too large

Some algorithms for token recognition are Some algorithms for token recognition are explainedexplained

Given material:Given material: A frameworks of A frameworks of Scanner.javaScanner.java and and Token.javaToken.java classes classes Test examplesTest examples

V. Kurbalija, M. IvanovV. Kurbalija, M. Ivanovićić

Organization of the New Course oOrganization of the New Course on CC in Novi Sad n CC in Novi Sad

Current Current CC Course – CC Course – ExercisesExercises

Level 1 – Task 2Level 1 – Task 2

Syntax analysisSyntax analysis Implementation of a recursive descent parser for Implementation of a recursive descent parser for

MicroJava MicroJava Without error handling – stop on first errorWithout error handling – stop on first error The algorithm for recursive descent parser is The algorithm for recursive descent parser is

explainedexplained Given material:Given material:

A complete grammar of MicroJavaA complete grammar of MicroJava A framework of A framework of Parser.javaParser.java class class Test examples – Programs in MicroJavaTest examples – Programs in MicroJava

V. Kurbalija, M. IvanovV. Kurbalija, M. Ivanovićić

Organization of the New Course oOrganization of the New Course on CC in Novi Sad n CC in Novi Sad

Current Current CC Course – CC Course – ExercisesExercises

Level 1 – Task 3Level 1 – Task 3

Error handlingError handling Modification of the parser and Modification of the parser and error() error()

methodmethod 2 kinds of algorithms:2 kinds of algorithms:

method with special anchors method with special anchors method with general anchorsmethod with general anchors

These 2 algorithms are explained in detailThese 2 algorithms are explained in detail Given material:Given material:

Set of anchorsSet of anchors

V. Kurbalija, M. IvanovV. Kurbalija, M. Ivanovićić

Organization of the New Course oOrganization of the New Course on CC in Novi Sad n CC in Novi Sad

Current Current CC Course – CC Course – ExercisesExercisesLevel 2Level 2

Semantic analysisSemantic analysis Symbol table handling and type checkingSymbol table handling and type checking Semantic analyzer should checkSemantic analyzer should check

Type compatibilityType compatibility Predeclared namesPredeclared names ScopeScope

Students should implement Students should implement Obj.javaObj.java, , Struct.java, Struct.java, Scope.java Scope.java and and Tab.javaTab.java classes and modify parser classes and modify parser

The functionality of these classes is explained The functionality of these classes is explained Given material:Given material:

Frameworks of Frameworks of Obj.javaObj.java, , Struct.java, Scope.java Struct.java, Scope.java and and Tab.javaTab.java classes classes

Context conditions in the grammarContext conditions in the grammar Test examplesTest examples

V. Kurbalija, M. IvanovV. Kurbalija, M. Ivanovićić

Organization of the New Course oOrganization of the New Course on CC in Novi Sad n CC in Novi Sad

Current Current CC Course – CC Course – ExercisesExercises

Level 3Level 3

Code generationCode generation Generate code for the MicroJava Virtual Machine (stack Generate code for the MicroJava Virtual Machine (stack

machine)machine) MicroJava Virtual Machine and its instruction set (57 MicroJava Virtual Machine and its instruction set (57

instructions) are described in detailinstructions) are described in detail Students should implement Students should implement Code.javaCode.java, , Item.java Item.java and and

Label.javaLabel.java classes and modify parser classes and modify parser

Given material:Given material: Full implementation of MicroJava VMFull implementation of MicroJava VM Decoder.javaDecoder.java class for viewing generated code class for viewing generated code Frameworks of Frameworks of Code.javaCode.java, , Item.java Item.java and and Label.javaLabel.java classes classes Test examplesTest examples

V. Kurbalija, M. IvanovV. Kurbalija, M. Ivanovićić

Organization of the New Course oOrganization of the New Course on CC in Novi Sad n CC in Novi Sad

AgendaAgenda

Previous Previous CC CourseCC Course Current CC CourseCurrent CC Course Assessment by students in Novi SadAssessment by students in Novi Sad Questionnaire and Exam resultsQuestionnaire and Exam results JCCC – MaterialJCCC – Material ConclusionConclusion

V. Kurbalija, M. IvanovV. Kurbalija, M. Ivanovićić

Organization of the New Course oOrganization of the New Course on CC in Novi Sad n CC in Novi Sad

Assessment by students in Novi Assessment by students in Novi SadSad

Questionnaire - students opinionQuestionnaire - students opinion 52 students, 34 filled questionnaire52 students, 34 filled questionnaire 26 questions26 questions For every question grade 1 to 5For every question grade 1 to 5 Meaning of answers:Meaning of answers:

1 – “I do not agree at all”1 – “I do not agree at all” 5 – “I agree completely” 5 – “I agree completely”

V. Kurbalija, M. IvanovV. Kurbalija, M. Ivanovićić

Organization of the New Course oOrganization of the New Course on CC in Novi Sad n CC in Novi Sad

AgendaAgenda

Previous Previous CC CourseCC Course Current CC CourseCurrent CC Course Assessment by students in Novi SadAssessment by students in Novi Sad Questionnaire and Exam resultsQuestionnaire and Exam results JCCC – MaterialJCCC – Material ConclusionConclusion

V. Kurbalija, M. IvanovV. Kurbalija, M. Ivanovićić

Organization of the New Course oOrganization of the New Course on CC in Novi Sad n CC in Novi Sad

Questionnaire - GeneralQuestionnaire - General

The organization of the course was goodThe organization of the course was good11 22 33 44 5511 11 22 1414 1616 AVERAGE: 4.26AVERAGE: 4.26

The possibility of passing the exam using colloquiums and The possibility of passing the exam using colloquiums and tests is useful tests is useful

11 22 33 44 5522 22 22 99 1919 AVERAGE: 4.21AVERAGE: 4.21

Type and difficulty of tasks are correctType and difficulty of tasks are correct11 22 33 44 5511 22 1414 1212 55 AVERAGE: 3.53AVERAGE: 3.53

The amount of material is goodThe amount of material is good11 22 33 44 5500 00 77 1212 1515 AVERAGE: 4.24AVERAGE: 4.24

V. Kurbalija, M. IvanovV. Kurbalija, M. Ivanovićić

Organization of the New Course oOrganization of the New Course on CC in Novi Sad n CC in Novi Sad

Questionnaire - GeneralQuestionnaire - General

Lectures and exercises were good synchronizedLectures and exercises were good synchronized11 22 33 44 5500 00 88 99 1717 AVERAGE: 4.26AVERAGE: 4.26

Teaching material is good Teaching material is good 11 22 33 44 5511 44 1515 99 55 AVERAGE: 3.38AVERAGE: 3.38

The quality of course is goodThe quality of course is good11 22 33 44 5500 00 88 1818 88 AVERAGE: 4.00AVERAGE: 4.00

Course is useful Course is useful 11 22 33 44 5500 22 77 1313 1212 AVERAGE: 4.03AVERAGE: 4.03

V. Kurbalija, M. IvanovV. Kurbalija, M. Ivanovićić

Organization of the New Course oOrganization of the New Course on CC in Novi Sad n CC in Novi Sad

Questionnaire - LecturesQuestionnaire - Lectures Lectures were good prepared Lectures were good prepared

11 22 33 44 5500 11 22 1212 1919 AVERAGE: 4.44AVERAGE: 4.44

Teaching style is good Teaching style is good 11 22 33 44 5511 00 44 1414 1515 AVERAGE: 4.24AVERAGE: 4.24

I have learned enough during lecturesI have learned enough during lectures11 22 33 44 5511 22 1919 1010 22 AVERAGE: 3.29AVERAGE: 3.29

Lecturer was willing to give additional answers Lecturer was willing to give additional answers 11 22 33 44 5500 00 33 99 2121 AVERAGE: 4.55AVERAGE: 4.55

The speed of presentation was adequate The speed of presentation was adequate 11 22 33 44 5500 33 99 1212 1010 AVERAGE: 3.85AVERAGE: 3.85

Generally, I am satisfied with the lectures Generally, I am satisfied with the lectures 11 22 33 44 5500 11 66 1616 1010 AVERAGE: 4.06AVERAGE: 4.06

V. Kurbalija, M. IvanovV. Kurbalija, M. Ivanovićić

Organization of the New Course oOrganization of the New Course on CC in Novi Sad n CC in Novi Sad

Questionnaire – Exercises Questionnaire – Exercises Exercises were good prepared Exercises were good prepared

11 22 33 44 5500 00 44 88 2222 AVERAGE: 4.53AVERAGE: 4.53

Teaching style of assistant is good Teaching style of assistant is good 11 22 33 44 5500 11 33 88 2222 AVERAGE: 4.50AVERAGE: 4.50

Assistant was willing to give additional answers Assistant was willing to give additional answers 11 22 33 44 5500 00 00 55 2929 AVERAGE: 4.85AVERAGE: 4.85

I have learned enough during exercisesI have learned enough during exercises11 22 33 44 5500 00 99 1313 1212 AVERAGE: 4.09AVERAGE: 4.09

The speed of presentation was adequate The speed of presentation was adequate 11 22 33 44 5500 00 55 1414 1515 AVERAGE: 4.29AVERAGE: 4.29

The difficulty of tasks was adequate The difficulty of tasks was adequate 11 22 33 44 5500 11 1010 1111 1111 AVERAGE: 3.97AVERAGE: 3.97

Generally, I am satisfied with the exercises Generally, I am satisfied with the exercises 11 22 33 44 5500 00 44 1111 1919 AVERAGE: 4.44AVERAGE: 4.44

V. Kurbalija, M. IvanovV. Kurbalija, M. Ivanovićić

Organization of the New Course oOrganization of the New Course on CC in Novi Sad n CC in Novi Sad

Questionnaire - EffortQuestionnaire - Effort How many times did you miss lectures?How many times did you miss lectures?

<3<3 3-73-7 >7>72424 99 11

How many times did you miss exercises?How many times did you miss exercises?<3<3 3-73-7 >7>72323 1010 11

Did you need additional consultations?Did you need additional consultations?YESYES NONO77 2727

By your own opinion, how many hours per week should By your own opinion, how many hours per week should be spent preparing for this course?be spent preparing for this course?

AVERAGE: 5.66AVERAGE: 5.66 How many hours per week did you spent preparing for How many hours per week did you spent preparing for

this course?this course?AVERAGE: 4.05AVERAGE: 4.05

V. Kurbalija, M. IvanovV. Kurbalija, M. Ivanovićić

Organization of the New Course oOrganization of the New Course on CC in Novi Sad n CC in Novi Sad

Exam results Exam results

52 students, 41 passed the exam 52 students, 41 passed the exam 38 in January38 in January 1 in April1 in April 2 in June2 in June

Grade distribution (6-10)Grade distribution (6-10) 6 – 7 students6 – 7 students 7 – 14 students7 – 14 students 8 – 16 students8 – 16 students 9 – 2 students (+oral exam)9 – 2 students (+oral exam) 10 – 1 student (+oral exam)10 – 1 student (+oral exam)

V. Kurbalija, M. IvanovV. Kurbalija, M. Ivanovićić

Organization of the New Course oOrganization of the New Course on CC in Novi Sad n CC in Novi Sad

AgendaAgenda

Previous Previous CC CourseCC Course Current CC CourseCurrent CC Course Assessment by students in Novi SadAssessment by students in Novi Sad Questionnaire and Exam resultsQuestionnaire and Exam results JCCC – MaterialJCCC – Material ConclusionConclusion

V. Kurbalija, M. IvanovV. Kurbalija, M. Ivanovićić

Organization of the New Course oOrganization of the New Course on CC in Novi Sad n CC in Novi Sad

JCCC - MaterialJCCC - Material Novi SadNovi Sad

CC1 obligatory, CC2 electiveCC1 obligatory, CC2 elective CC1 – use Teaching material of prof. CC1 – use Teaching material of prof.

MMössenböck, Linzössenböck, Linz CC2 CC2

More theoretical, Automata theory, Formal languages More theoretical, Automata theory, Formal languages theory theory

Other parsing methods (LR, LALR)Other parsing methods (LR, LALR) Detailed presentation of code generationDetailed presentation of code generation Different techniques of code optimizationDifferent techniques of code optimization Exercises and practical work – Real-world (more Exercises and practical work – Real-world (more

serious project)serious project)

V. Kurbalija, M. IvanovV. Kurbalija, M. Ivanovićić

Organization of the New Course oOrganization of the New Course on CC in Novi Sad n CC in Novi Sad

JCCC - MaterialJCCC - Material BelgradBelgrad

CC1 obligatory, CC2 electiveCC1 obligatory, CC2 elective CC1 CC1

Partially use teaching material of prof. MPartially use teaching material of prof. Mössenböck, össenböck, Linz,Linz,

+ more theory, + more theory, extended version of microJava with object inheritance extended version of microJava with object inheritance

CC2 CC2 Similar to Novi SadSimilar to Novi Sad

.doc file.doc file

V. Kurbalija, M. IvanovV. Kurbalija, M. Ivanovićić

Organization of the New Course oOrganization of the New Course on CC in Novi Sad n CC in Novi Sad

JCCC - MaterialJCCC - Material Possibilities to prepare common materialPossibilities to prepare common material

BelgradBelgrad is more ambitious then Novi Sad is more ambitious then Novi Sad Dragan want to prepare his own material and slidesDragan want to prepare his own material and slides But he has not time and appropriate motivation for thatBut he has not time and appropriate motivation for that

Novi SadNovi Sad Will use Linz material, completely for CC1Will use Linz material, completely for CC1 We are willing to prepare presentations for CC2 topics We are willing to prepare presentations for CC2 topics But also seems that we have not appropriate motivationBut also seems that we have not appropriate motivation

Open QuestionOpen Question: Writing book: Writing book We have a lot of draft materials We have a lot of draft materials Motivation? – project, publishing, …Motivation? – project, publishing, …

ProblemProblem: CC2 is elective, we do not expect : CC2 is elective, we do not expect students students

V. Kurbalija, M. IvanovV. Kurbalija, M. Ivanovićić

Organization of the New Course oOrganization of the New Course on CC in Novi Sad n CC in Novi Sad

AgendaAgenda

Previous Previous CC CourseCC Course Current CC CourseCurrent CC Course Assessment by students in Novi SadAssessment by students in Novi Sad Questionnaire and Exam resultsQuestionnaire and Exam results JCCC – MaterialJCCC – Material ConclusionConclusion

V. Kurbalija, M. IvanovV. Kurbalija, M. Ivanovićić

Organization of the New Course oOrganization of the New Course on CC in Novi Sad n CC in Novi Sad

Conclusion – Novi Sad Conclusion – Novi Sad Approach Approach

Advantages of new course:Advantages of new course: Concepts of compiler construction are shown on formal Concepts of compiler construction are shown on formal

wayway Modern and object-oriented language is used (Java and Modern and object-oriented language is used (Java and

Java byte code)Java byte code) Most of students autonomously write important parts of Most of students autonomously write important parts of

compilercompiler Better students are able to write (almost) whole compilerBetter students are able to write (almost) whole compiler

The exam can be passed during the semester – The exam can be passed during the semester – continual assessment continual assessment

Some students complain that there is not enough Some students complain that there is not enough literature on Serbian (enough motivation for book?)literature on Serbian (enough motivation for book?)

Thank you for your Thank you for your attentionattention