Organization of the New Course on Complier Construction in Novi Sad Vladimir Kurbalija, Mirjana Ivanović Department of Mathematics and Informatics University of Novi Sad Serbia Agenda Previous CC Course Current CC Course Assessment by students in Novi Sad Questionnaire and Exam results JCCC – Material Conclusion V. Kurbalija, M. Ivanović Organization of the New Course on CC in Novi Sad CC Course in Novi Sad One of core software courses at Computer Science directions 7th semester CC1 (obligatory), 8th semester CC2 (elective), for students of Computer Science, Business Computer Science, Teaching of Computer Science V. Kurbalija, M. Ivanović Organization of the New Course on CC in Novi Sad Previous CC Course Practical approach Development of Pascal- compiler Subset of Pascal language: data types: boolean and integer standard types, arrays and fixed records as structured types; basic statements: assignment statement, procedure call, if and while statements; Standard input/output (read and write) procedures, user defined procedures including recursion. The implementation: recursive-descent manner for syntax analysis code generation for abstract P machine V. Kurbalija, M. Ivanović Organization of the New Course on CC in Novi Sad Previous CC Course - Exercises Students repeat and train practical skills gained during lectures Several independent tasks – small grammars Implementation language is Modula-2 Compiler generator Coco/R Tasks: Lexical and syntax analysis and some parts of semantic analysis using Coco/R “Hand written” parsers (LA & SA) “Hand written” parsers with semantic analysis and rarely with code generation or interpretation Some algorithms on grammars (memory organisation, checking consistency, computing first and follow sets…) V. Kurbalija, M. Ivanović Organization of the New Course on CC in Novi Sad Agenda Previous CC Course Current CC Course Assessment by students in Novi Sad Questionnaire and Exam results JCCC – Material Conclusion V. Kurbalija, M. Ivanović Organization of the New Course on CC in Novi Sad Current CC Course More theoretical approach on lectures Course goes through all phases of a compiler writing Shows the theoretical concepts underlying each phase as well as how to implement it efficiently Examples: MicroJava compiler in Java, target language – subset of Java byte code Goals of the course acquire the practical skills to write a simple compiler for an imperative programming language understand the concepts of scanning, parsing, name management in nested scopes, and code generation. learn to transfer the skills also to general software engineering tasks V. Kurbalija, M. Ivanović Organization of the New Course on CC in Novi Sad Current CC Course Structure of Lectures Overview (1 week) Lexical Analysis (1 week) Syntax Analysis (2 weeks) --- TEST Attribute Grammars (1 week) Symbol Table (2 weeks) Code Generation (3 weeks) --- TEST BU Parsing (2 weeks) Compiler Generators (1 week) --- TEST V. Kurbalija, M. Ivanović Organization of the New Course on CC in Novi Sad Current CC Course – Exercises Students should acquire practical skills in compiler writing One (big) project divided in smaller subtasks Students should write a small compiler for a Java-like language - MicroJava The implementation language is also Java V. Kurbalija, M. Ivanović Organization of the New Course on CC in Novi Sad Current CC Course – Exercises Study material: Teaching material (slides) Description of the project Specification of MicroJava language (tokens, language grammar, semantic and context constraints) Specification of MicroJava virtual machine (similar but simpler than Java VM) – Memory layout and Instruction set Specification of object file format V. Kurbalija, M. Ivanović Organization of the New Course on CC in Novi Sad Current CC Course – Exercises The project consists of three levels: Level 1 – implementation of a scanner and a parser for the language MicroJava, error handling – 3 TASKS Level 2 - deals with symbol table handling and type checking – 1 TASK Level 3 - deals with code generation for the MicroJava – 1 TASK V. Kurbalija, M. Ivanović Organization of the New Course on CC in Novi Sad Current CC Course – Exercises Level 1 – Task 1 Lexical analysis Implementation of a scanner for MicroJava Scanner should skip blanks, end of line characters, tabulator characters and comments Types of errors: The occurrence of an invalid character (e.g., $) A missing quote at the end of the character constant ('x) Integer constants that are too large Some algorithms for token recognition are explained Given material: A frameworks of Scanner.java and Token.java classes Test examples V. Kurbalija, M. Ivanović Organization of the New Course on CC in Novi Sad Current CC Course – Exercises Level 1 – Task 2 Syntax analysis Implementation of a recursive descent parser for MicroJava Without error handling – stop on first error The algorithm for recursive descent parser is explained Given material: A complete grammar of MicroJava A framework of Parser.java class Test examples – Programs in MicroJava V. Kurbalija, M. Ivanović Organization of the New Course on CC in Novi Sad Current CC Course – Exercises Level 1 – Task 3 Error handling Modification of the parser and error() method 2 kinds of algorithms: method with special anchors method with general anchors These 2 algorithms are explained in detail Given material: Set of anchors V. Kurbalija, M. Ivanović Organization of the New Course on CC in Novi Sad Current CC Course – Exercises Level 2 Semantic analysis Symbol table handling and type checking Semantic analyzer should check Type compatibility Predeclared names Scope Students should implement Obj.java, Struct.java, Scope.java and Tab.java classes and modify parser The functionality of these classes is explained Given material: Frameworks of Obj.java, Struct.java, Scope.java and Tab.java classes Context conditions in the grammar Test examples V. Kurbalija, M. Ivanović Organization of the New Course on CC in Novi Sad Current CC Course – Exercises Level 3 Code generation Generate code for the MicroJava Virtual Machine (stack machine) MicroJava Virtual Machine and its instruction set (57 instructions) are described in detail Students should implement Code.java, Item.java and Label.java classes and modify parser Given material: Full implementation of MicroJava VM Decoder.java class for viewing generated code Frameworks of Code.java, Item.java and Label.java classes Test examples V. Kurbalija, M. Ivanović Organization of the New Course on CC in Novi Sad Agenda Previous CC Course Current CC Course Assessment by students in Novi Sad Questionnaire and Exam results JCCC – Material Conclusion V. Kurbalija, M. Ivanović Organization of the New Course on CC in Novi Sad Assessment by students in Novi Sad Questionnaire - students opinion 52 students, 34 filled questionnaire 26 questions For every question grade 1 to 5 Meaning of answers: 1 – “I do not agree at all” 5 – “I agree completely” V. Kurbalija, M. Ivanović Organization of the New Course on CC in Novi Sad Agenda Previous CC Course Current CC Course Assessment by students in Novi Sad Questionnaire and Exam results JCCC – Material Conclusion V. Kurbalija, M. Ivanović Organization of the New Course on CC in Novi Sad Questionnaire - General The organization of the course was good 1 2 3 4 5 1 1 2 14 16 AVERAGE: 4.26 The possibility of passing the exam using colloquiums and tests is useful 1 2 3 4 5 2 2 2 9 19 AVERAGE: 4.21 Type and difficulty of tasks are correct 1 2 3 4 5 1 2 14 12 5 AVERAGE: 3.53 The amount of material is good 1 2 3 4 5 0 0 7 12 15 AVERAGE: 4.24 V. Kurbalija, M. Ivanović Organization of the New Course on CC in Novi Sad Questionnaire - General Lectures and exercises were good synchronized 1 2 3 4 5 0 0 8 9 17 AVERAGE: 4.26 Teaching material is good 1 2 3 4 5 1 4 15 9 5 AVERAGE: 3.38 The quality of course is good 1 2 3 4 5 0 0 8 18 8 AVERAGE: 4.00 Course is useful 1 2 3 4 5 0 2 7 13 12 AVERAGE: 4.03 V. Kurbalija, M. Ivanović Organization of the New Course on CC in Novi Sad Questionnaire - Lectures Lectures were good prepared 1 2 3 4 5 0 1 2 12 19 Teaching style is good 1 2 3 4 5 1 0 4 14 15 I have learned enough during lectures 1 2 3 4 5 1 2 19 10 2 Lecturer was willing to give additional answers 1 2 3 4 5 0 0 3 9 21 The speed of presentation was adequate 1 2 3 4 5 0 3 9 12 10 Generally, I am satisfied with the lectures 1 2 3 4 5 0 1 6 16 10 V. Kurbalija, M. Ivanović Organization of the New Course on CC in Novi Sad AVERAGE: 4.44 AVERAGE: 4.24 AVERAGE: 3.29 AVERAGE: 4.55 AVERAGE: 3.85 AVERAGE: 4.06 Questionnaire – Exercises Exercises were good prepared 1 2 3 4 0 0 4 8 Teaching style of assistant is good 1 2 3 4 0 1 3 8 Assistant was willing to give additional answers 1 2 3 4 0 0 0 5 I have learned enough during exercises 1 2 3 4 0 0 9 13 The speed of presentation was adequate 1 2 3 4 0 0 5 14 The difficulty of tasks was adequate 1 2 3 4 0 1 10 11 Generally, I am satisfied with the exercises 1 2 3 4 0 0 4 11 V. Kurbalija, M. Ivanović 5 22 AVERAGE: 4.53 5 22 AVERAGE: 4.50 5 29 AVERAGE: 4.85 5 12 AVERAGE: 4.09 5 15 AVERAGE: 4.29 5 11 AVERAGE: 3.97 5 19 AVERAGE: 4.44 Organization of the New Course on CC in Novi Sad Questionnaire - Effort How many times did you miss lectures? <3 3-7 >7 24 9 1 How many times did you miss exercises? <3 3-7 >7 23 10 1 Did you need additional consultations? YES NO 7 27 By your own opinion, how many hours per week should be spent preparing for this course? AVERAGE: 5.66 How many hours per week did you spent preparing for this course? AVERAGE: 4.05 V. Kurbalija, M. Ivanović Organization of the New Course on CC in Novi Sad Exam results 52 students, 41 passed the exam 38 in January 1 in April 2 in June Grade distribution (6-10) 6 – 7 students 7 – 14 students 8 – 16 students 9 – 2 students (+oral exam) 10 – 1 student (+oral exam) V. Kurbalija, M. Ivanović Organization of the New Course on CC in Novi Sad Agenda Previous CC Course Current CC Course Assessment by students in Novi Sad Questionnaire and Exam results JCCC – Material Conclusion V. Kurbalija, M. Ivanović Organization of the New Course on CC in Novi Sad JCCC - Material Novi Sad CC1 obligatory, CC2 elective CC1 – use Teaching material of prof. Mössenböck, Linz CC2 More theoretical, Automata theory, Formal languages theory Other parsing methods (LR, LALR) Detailed presentation of code generation Different techniques of code optimization Exercises and practical work – Real-world (more serious project) V. Kurbalija, M. Ivanović Organization of the New Course on CC in Novi Sad JCCC - Material Belgrad CC1 obligatory, CC2 elective CC1 CC2 Partially use teaching material of prof. Mössenböck, Linz, + more theory, extended version of microJava with object inheritance Similar to Novi Sad .doc file V. Kurbalija, M. Ivanović Organization of the New Course on CC in Novi Sad JCCC - Material Possibilities to prepare common material Belgrad is more ambitious then Novi Sad Novi Sad Will use Linz material, completely for CC1 We are willing to prepare presentations for CC2 topics But also seems that we have not appropriate motivation Open Question: Writing book Dragan want to prepare his own material and slides But he has not time and appropriate motivation for that We have a lot of draft materials Motivation? – project, publishing, … Problem: CC2 is elective, we do not expect students V. Kurbalija, M. Ivanović Organization of the New Course on CC in Novi Sad Agenda Previous CC Course Current CC Course Assessment by students in Novi Sad Questionnaire and Exam results JCCC – Material Conclusion V. Kurbalija, M. Ivanović Organization of the New Course on CC in Novi Sad Conclusion – Novi Sad Approach Advantages of new course: Concepts of compiler construction are shown on formal way Modern and object-oriented language is used (Java and Java byte code) Most of students autonomously write important parts of compiler Better students are able to write (almost) whole compiler The exam can be passed during the semester – continual assessment Some students complain that there is not enough literature on Serbian (enough motivation for book?) V. Kurbalija, M. Ivanović Organization of the New Course on CC in Novi Sad Thank you for your attention