CS 153: Concepts of Compiler Design August 24 Class Meeting

Slides:



Advertisements
Similar presentations
1 Pass Compiler 1. 1.Introduction 1.1 Types of compilers 2.Stages of 1 Pass Compiler 2.1 Lexical analysis 2.2. syntactical analyzer 2.3. Code generation.
Advertisements

CS 153: Concepts of Compiler Design August 25 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
CS 235: User Interface Design January 22 Class Meeting
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
CPSC 388 – Compiler Design and Construction Lecture: MWF 11:00am-12:20pm, Room 106 Colton.
CS 153: Concepts of Compiler Design August 24 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
CS 235: User Interface Design August 25 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
CSC 338: Compiler design and implementation
Compiler course 1. Introduction. Outline Scope of the course Disciplines involved in it Abstract view for a compiler Front-end and back-end tasks Modules.
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
1.  10% Assignments/ class participation  10% Pop Quizzes  05% Attendance  25% Mid Term  50% Final Term 2.
CS 152: Programming Language Paradigms April 2 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak
CS453 LectureIntroduction1 CS453 Compiler Construction Instructor:Wim Bohm Computer Science Building 470 TA: tba
CS 153: Concepts of Compiler Design August 26 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 153: Concepts of Compiler Design September 16 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Chapter 1 Introduction. Chapter 1 - Introduction 2 The Goal of Chapter 1 Introduce different forms of language translators Give a high level overview.
1 Compiler Design (40-414)  Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007  Evaluation:  Midterm.
CS 153: Concepts of Compiler Design October 21 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
1 Compiler & its Phases Krishan Kumar Asstt. Prof. (CSE) BPRCE, Gohana.
CS453 LectureIntroduction1 CS453 Compiler Construction Original Design: Michelle Strout Instructor:Wim Bohm
Compiler Construction CPCS302 Dr. Manal Abdulaziz.
CS 152: Programming Language Paradigms April 7 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak
CS 153: Concepts of Compiler Design October 12 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
ICS312 Introduction to Compilers Set 23. What is a Compiler? A compiler is software (a program) that translates a high-level programming language to machine.
COMP 3002: Compiler Construction Pat Morin School of Computer Science.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
CS 432: Compiler Construction Lecture 1
Lecture 1b- Introduction
Advanced Computer Systems
CS 153: Concepts of Compiler Design September 14 Class Meeting
Compiler Design (40-414) Main Text Book:
Introduction to Compiler Construction
CS 3304 Comparative Languages
CS 153: Concepts of Compiler Design August 29 Class Meeting
Compiler Construction (CS-636)
Overview of Compilation The Compiler Front End
Overview of Compilation The Compiler Front End
CS 153: Concepts of Compiler Design October 17 Class Meeting
课程名 编译原理 Compiling Techniques
CS 153: Concepts of Compiler Design November 30 Class Meeting
CMPE 152: Compiler Design December 5 Class Meeting
CMPE 152: Compiler Design January 25 Class Meeting
Compiler Construction
CS416 Compiler Design lec00-outline September 19, 2018
Introduction to Compiler Construction
Course supervisor: Lubna Siddiqui
Compiler Construction
CMPE 152: Compiler Design September 18 Class Meeting
CMPE 152: Compiler Design August 21 Class Meeting
CMPE 152: Compiler Design September 11/13 Lab
CSE401 Introduction to Compiler Construction
CMPE 152: Compiler Design August 23 Class Meeting
CMPE 152: Compiler Design August 21/23 Lab
CMPE 152: Compiler Design December 6 Class Meeting
CMPE 152: Compiler Design January 24 Class Meeting
CS416 Compiler Design lec00-outline February 23, 2019
CMPE 152: Compiler Design February 28 Class Meeting
Introduction to Compiler Construction
CMPE 152: Compiler Design January 29 Class Meeting
CMPE 152: Compiler Design February 21/26 Lab
Chapter 10: Compilers and Language Translation
Compiler Construction
Introduction to Compiler Construction
CMPE 152: Compiler Design March 19 Class Meeting
CMPE 152: Compiler Design August 22 Class Meeting
CMPE 152: Compiler Design August 27 Class Meeting
CMPE 152: Compiler Design September 17 Class Meeting
CMPE 152: Compiler Design September 19 Class Meeting
Presentation transcript:

CS 153: Concepts of Compiler Design August 24 Class Meeting Department of Computer Science San Jose State University Fall 2017 Instructor: Ron Mak www.cs.sjsu.edu/~mak

Basic Info Office hours Website TuTh 3:00 – 4:00 PM ENG 250 Faculty webpage: http://www.cs.sjsu.edu/~mak/ Class webpage: http://www.cs.sjsu.edu/~mak/CS153/index.html Syllabus Assignments Lecture notes

Permission Codes? If you need a permission code to enroll in this class, please fill out and hand in a filled-out and signed “Add Code Information” form. Be sure to list prerequisite courses that you’ve successfully completed. Prerequisites: CS 47 or CMPE 102, CS 146, and CS 154 (with a grade of "C-" or better in each); Computer Science, Applied and Computational Math, or Software Engineering majors only. Priority will be given to graduating seniors. You must show your graduating senior card.

Goals of the Course Understand the concepts of compilers and interpreters. Parser, scanner, tokens Symbol tables, intermediate code Executors, code generators Compiler-compilers

Goals of the Course, cont’d Learn important job skills that employers want! Work on a small programming team. Understand and modify a Big Hairy Legacy Application. Use modern software engineering practices to develop a complex application.

Course Overview First half: Modify a Pascal interpreter. Midterm The interpreter is written in Java (the implementation language). The source programs are written in Pascal (the source language). The implementation code for the interpreter will be presented to you incrementally. Midterm

Course Overview, cont’d Second half: Your compiler project. ANTLR 4 compiler-compiler Java Virtual Machine (JVM) architecture Jasmin assembly language Back end code generator Final

Required Textbooks Writing Compilers and Interpreters, 3rd edition Author: Ronald Mak Publisher: Wiley ISBN: 978-0-470-17707-5 Source code: http://www.cs.sjsu.edu/~mak/CS153/sources/ (Java and C++) The Definitive ANTLR 4 Reference Author: Terence Parr Publisher: Pragmatic Bookshelf ISBN: 978-1934356999 URL: http://www.antlr.org Use during the entire semester. Use during the second half of the semester.

Project Teams Projects will be done by small project teams. Projects will be broken up into assignments. Form your own teams of 4 members each. Choose your team members wisely! Be sure you’ll be able to meet and communicate with each other and work together well. No moving from team to team. Each team member will receive the same score on each team assignment and team project.

Project Teams, cont’d Each team email to ron.mak@sjsu.edu by Wednesday, August 30: Your team name A list of team members and email addresses Subject: CS 153 Team Team Name Example: CS 153 Team Hyper Hackers

Individual Responsibilities You are personally responsible for participating and contributing to your team’s work, and for understanding each part of the work for every assignment whether or not you worked on that part.

Postmortem Assessment Report At the end of the semester, each student will individually turn in a short (one page) report: A brief description of what you learned in the course. An assessment of your personal accomplishments for your project team. An assessment of the contributions of each of your project team members. This report will be seen only by the instructor.

Your Individual Overall Class Grade Your final class grade will be adjusted up or down depending on your level and quality of participation, as reported by your teammates’ postmortem reports. 30% assignments 35% project 15% midterm 20% final During the semester, keep track of your progress in Canvas. At the end of the semester, students with the median score will get the B grade. Higher and lower grades will then be assigned based on how the scores cluster above and below the median. Therefore, your final class grade will be based primarily on your performance relative to the other students in the class.

Participation is Important Can move your final grade up or down, especially in borderline cases. Participation in class. Participation in your team. As reported by the postmortem assessment reports.

Take roll!

Compiler Magic? C compiler: Pascal compiler: Java compiler: int main() { printf("Hello, C world!\n"); } Pascal compiler: PROGRAM hello; BEGIN writeln('Hello, Pascal world!'); END. Java compiler: public class Hello { public static void main(String args[]) System.out.println("Hello, Java world!"); }

Overview of the Compilation Process hello.pas Hello.java What’s in this box? Pascal compiler (you will write this in Java) Java compiler Translation: javac Hello.java ... hello.j Hello.class assembly language object program Jasmin assembler (provided for you) Translation: hello.class binary object program Java linker & loader (provided for you) Java linker & loader java Hello ... Java Virtual Machine (provided for you) Java Virtual Machine Execution:

What is a Compiler? A software utility that is extremely important for developing applications … … usually overlooked and taken for granted ... UNLESS you can’t get your program to compile!

A Compiler is a Translator A compiler translates a program that you’ve written ... in a high-level language C, C++, Java, Pascal, etc. ... into a low-level language assembly language or machine language ... that a computer can understand and eventually execute.

Assignment #1 Posted to the class web page: http://www.cs.sjsu.edu/~mak/CS153/index.html Write a simple Pascal program. An individual (not team) assignment. You may work together to learn the language. But what you turn in must be your own work. Due Friday, September 1.

Assignment #1, cont’d Download and install the Lazarus/Free Pascal IDE for Pascal: https://www.lazarus-ide.org Online Pascal tutorials: https://www.tutorialspoint.com/pascal/ http://www.taoyue.com/tutorials/pascal/

Assignment #1, cont’d Sample Pascal program: http://www.cs.sjsu.edu/~mak/CS153/assignments/1/EmployeeListing.pas Input file: http://www.cs.sjsu.edu/~mak/CS153/assignments/1/employees.txt

More Definitions source program: the program (application) that you write in a high-level language which the compiler will translate Usually stored in a source file. source language: the high-level language in which you write your source program Example: Pascal

More Definitions, cont’d object language: the low-level language (AKA target language) into which the compiler translates the source program Do not confuse object language with object-oriented language. Example: Jasmin assembly language Example: Intel machine code object program: your program after it has been translated into the object language

More Definitions, cont’d target machine: the computer that will eventually execute the object program Example: Your laptop’s hardware Example: The Java Virtual Machine (JVM) The JVM runs on your workstation or laptop (any computer that supports Java) implementation language: the language that the compiler itself is written in Example: Java

Conceptual Design (Version 1) Parser Controls the translation process. Repeatedly asks the scanner for the next token. Scanner Repeatedly reads characters from the source to construct tokens for the parser. Token A source language element identifier (name) number special symbol (+ - * / = etc.) reserved word Also reads from the source Source The source program

Token A low-level element of the source language. AKA lexeme Pascal language tokens Identifiers names of variables, types, procedures, functions, enumeration values, etc. Numbers integer and real (floating-point) Reserved words BEGIN END IF THEN ELSE AND OR NOT etc. Special symbols + - * / := < <= = >= > . , .. : ( ) [ ] { } ′

Parser Controls the translation process. Repeatedly asks the scanner for the next token. Knows the syntax (“grammar”) of the source language’s statements and expressions. Analyzes the sequence of tokens to determine what kind of statement or expression it is translating. Verifies that what it’s seeing is syntactically correct. Flags any syntax errors that it finds and attempts to recover from them.

Parser, cont’d What the parser does is called parsing. It parses the source program in order to translate it. AKA syntax analyzer

Scanner Reads characters sequentially from the source in order to construct and return the next token whenever requested by the parser. Knows the syntax of the source language’s tokens. What the scanner does is called scanning. It scans the source program in order to extract tokens. AKA lexical analyzer

Conceptual Design (Version 2) We can architect a compiler with three major parts:

Major Parts of a Compiler Front end Parser, Scanner, Source, Token Intermediate tier Intermediate code (icode) “Predigested” form of the source code that the back end can process efficiently. Example: parse trees AKA intermediate representation (IR) Symbol table (symtab) Stores information about the symbols (such as the identifiers) contained in the source program. Back end Code generator Processes the icode and the symtab in order to generate the object code. Only the front end needs to be source language-specific. The intermediate tier and the back end can be language-independent!

What Else Can Compilers Do? Compilers allow you to program in a high-level language and think about your algorithms, not about machine architecture. Compilers provide language portability. You can run your C++ and Java programs on different machines because their compilers enforce language standards.

What Else Can Compilers Do? cont’d Compilers can optimize and improve the execution of your programs. Optimize the object code for speed. Optimize the object code for size. Optimize the object code for power consumption.