CS 3240: Languages and Computation Course Overview Sasha Boldyreva.

Slides:



Advertisements
Similar presentations
Compilers Course 379K, TTH 9:30-11:00 Instructor: Dr. Doron A. Peled Office Hours: Mon 11:00-12:00.
Advertisements

CS 3240: Languages and Computation
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.
CPSC Compiler Tutorial 9 Review of Compiler.
1 Semantic Processing. 2 Contents Introduction Introduction A Simple Compiler A Simple Compiler Scanning – Theory and Practice Scanning – Theory and Practice.
PZ02A - Language translation
College of Computer Science & Technology Compiler Construction Principles & Implementation Techniques -1- Compiler Construction Principles & Implementation.
Compiler Construction
BİL744 Derleyici Gerçekleştirimi (Compiler Design)1.
CS 153: Concepts of Compiler Design August 25 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
CPSC 388 – Compiler Design and Construction Lecture: MWF 11:00am-12:20pm, Room 106 Colton.
C Chuen-Liang Chen, NTUCS&IE / 1 COMPILER Chuen-Liang Chen Department of Computer Science and Information Engineering National Taiwan University Taipei,
Invitation to Computer Science 5th Edition
2.2 A Simple Syntax-Directed Translator Syntax-Directed Translation 2.4 Parsing 2.5 A Translator for Simple Expressions 2.6 Lexical Analysis.
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.
1 Programming Languages Tevfik Koşar Lecture - II January 19 th, 2006.
CSC 338: Compiler design and implementation
Lexical Analysis - An Introduction Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at.
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.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 2.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
May 31, May 31, 2016May 31, 2016May 31, 2016 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University Azusa Pacific University,
CS453 LectureIntroduction1 CS453 Compiler Construction Instructor:Wim Bohm Computer Science Building 470 TA: tba
Compiler design Lecture 1: Compiler Overview Sulaimany University 2 Oct
Chapter 1 Introduction. Chapter 1 - Introduction 2 The Goal of Chapter 1 Introduce different forms of language translators Give a high level overview.
Topic #1: Introduction EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
1 Compiler Design (40-414)  Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007  Evaluation:  Midterm.
Introduction to Compiling
Muhammad Idrees, Lecturer University of Lahore 1 Top-Down Parsing Top down parsing can be viewed as an attempt to find a leftmost derivation for an input.
Introduction CPSC 388 Ellen Walker Hiram College.
1 Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Compiler Design Introduction 1. 2 Course Outline Introduction to Compiling Lexical Analysis Syntax Analysis –Context Free Grammars –Top-Down Parsing –Bottom-Up.
Compiler Construction (CS-636)
Compiler Introduction 1 Kavita Patel. Outlines 2  1.1 What Do Compilers Do?  1.2 The Structure of a Compiler  1.3 Compilation Process  1.4 Phases.
Compiler Construction By: Muhammad Nadeem Edited By: M. Bilal Qureshi.
1 Compiler & its Phases Krishan Kumar Asstt. Prof. (CSE) BPRCE, Gohana.
Compiler Construction CPCS302 Dr. Manal Abdulaziz.
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.
Overview of Compilation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 2.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
1 Compiler Construction Vana Doufexi office CS dept.
Presented by : A best website designer company. Chapter 1 Introduction Prof Chung. 1.
CS416 Compiler Design1. 2 Course Information Instructor : Dr. Ilyas Cicekli –Office: EA504, –Phone: , – Course Web.
CS510 Compiler Lecture 1. Sources Lecture Notes Book 1 : “Compiler construction principles and practice”, Kenneth C. Louden. Book 2 : “Compilers Principles,
Objective of the course Understanding the fundamentals of the compilation technique Assist you in writing you own compiler (or any part of compiler)
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 12–Compilers.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Compiler Design (40-414) Main Text Book:
Chapter 1 Introduction.
CS 326 Programming Languages, Concepts and Implementation
Overview of Compilation The Compiler Front End
Chapter 1 Introduction.
-by Nisarg Vasavada (Compiled*)
课程名 编译原理 Compiling Techniques
Compiler Lecture 1 CS510.
CS416 Compiler Design lec00-outline September 19, 2018
Course supervisor: Lubna Siddiqui
Introduction CI612 Compiler Design CI612 Compiler Design.
CPSC 388 – Compiler Design and Construction
Compiler design.
CS416 Compiler Design lec00-outline February 23, 2019
Introduction to Compiler Construction
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Compiler Construction
Lec00-outline May 18, 2019 Compiler Design CS416 Compiler Design.
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Introduction to Compiler Construction
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Presentation transcript:

CS 3240: Languages and Computation Course Overview Sasha Boldyreva

Personnel Instructor: Alexandra (Sasha) Boldyreva   Office: Klaus 3444  Office Hours: Tue. & Wed. at 2:00 to 3:00 pm Or by appointment TAs: TBA  TBA  Office Hours: TBA

Required Textbooks Bundle ISBN# , including “Compiler Construction Principles and Practice” by Kenneth C. Louden, Thompson Course Technology, 1997, ISBN “Introduction to Theory of Computation, Second Edition” by Michael Sipser, Thompson Course Technology, 2005, ISBN

Course Objectives Formal languages  Understand definitions of regular and context-free languages and their corresponding “machines”  Understand their computational powers and limitations Compiler concepts  Understand their applications in compilers  Front-end of compiler  Lexical analysis, parsing, semantic analysis Theory of computation  Understand Turing machines  Understand decidability

Course Syllabus Lexical analysis, scanners, pattern matching Regular expressions, DFAs, NFAs and automata Limits on regular expressions, pumping lemma Practical parsing, LL and LR parsing Context-free languages, grammars, Chomsky Hierarchy Pushdown automata, deterministic vs. non-deterministic Attribute grammars, type inferencing Context-free vs. context-sensitive grammars Decidable vs. Undecidable problems, Turing Machines, Halting Problem Complexity of computation, classes of languages P/NP, space and time completeness

Grading Homeworks: 25% Mini-project: 15% Midterm : 30% Final: 30% Homeworks to be submitted in class - hardcopy No late homework or assignments Homework should be concise, complete, and precise Tests will be in class

Class Policies Students must write solutions to assignments completely independently General discussions are allowed on assignments among students, but names of collaborators must be reported Cell phones off, silence please

Resources Class webpage: see T-Square Check for schedule changes.

Introduction to Compiler Concepts

Compilers What is a compiler?  A program that translates an executable program from source language into target language  Usually source language is high-level language, and target language is object (or machine) code  Related to interpreters Why compilers?  Programming in machine (or assembly) language is tedious, error prone, and machine dependent  Historical note: In 1954, IBM started developing FORTRAN language and its compiler

Why study theory of compiler? Besides it is required… Prerequisite for developing advanced compilers, which continues to be active as new computer architectures emerge Useful to develop software tools that parse computer codes or strings  E.g., editors, debuggers, interpreters, preprocessors, … Important to understand how compliers work to program more effectively

How Does Compiler Work? Scanner Parser Semantic Action Intermediate Representation Intermediate Representation Semantic Error Request Token Get Token Checking Start Front End: Analysis of program syntax and semantics

Parts of Compilers 1. Lexical Analysis 2. Syntax Analysis 3. Semantic Analysis 4. Code Generation 5. Optimization Analysis Synthesis Front End Back End Focus of this class.

The Big Picture Parsing: Translating code to rules of grammar. Building representation of code. Scanning: Converting input text into stream of known objects called tokens. Simplifies parsing process. Grammar dictates syntactic rules of language i.e., how legal sentence could be formed Lexical rules of language dictate how legal word is formed by concatenating alphabet.

Overall Operation Parser is in control of the overall operation  Demands scanner to produce a token Scanner reads input file into token buffer & forms a token (How?)  Token is returned to parser Parser attempts to match the token (How?)  Failure: Syntax Error!  Success: Does nothing and returns to get next token, or Takes semantic action

Overall Operation Semantic action: look up variable name  If found okay  If not: put in symbol table If semantic checks succeed, do code- generation (How?) Continue to get next token No more tokens? Done!

Scanning/Tokenization Input File Token Buffer What does the Token Buffer contain?  Token being identified Why a two-way ( ) street?  Characters can be read  and unread  Termination of a token

Example main() m

Example main() am

Example main() iam

Example main() niam

Example main() (niam

Example main() niam Keyword : main

Parser Translating code to rules of a grammar Control the overall operation Demands scanner to produce a token Failure: Syntax Error! Success:  Does nothing and returns to get next token, or  Takes semantic action

Grammar Rules  MAIN OPENPAR CLOSEPAR  NULL  VAR , VAR  NULL  CURLYOPEN CURLYCLOSE  VAR ;  VAR = ;  VAR  +  -  INT  FLOAT

Demo main() { int a,b; a = b; } Parser Scanner Token Buffer

Demo main() { int a,b; a = b; } Parser Scanner "Please, get me the next token" Token Buffer

Demo main() { int a,b; a = b; } Parser Scanner m

Demo main() { int a,b; a = b; } Parser Scanner am

Demo main() { int a,b; a = b; } Parser Scanner iam

Demo main() { int a,b; a = b; } Parser Scanner niam

Demo main() { int a,b; a = b; } Parser Scanner (niam

Demo main() { int a,b; a = b; } Parser Scanner niam

Demo main() { int a,b; a = b; } Parser Scanner Token: main Token Buffer

Demo main() { int a,b; a = b; } Parser Scanner "I recognize this" Token Buffer

Parsing (Matching) Start matching using a rule When match takes place at certain position, move further (get next token & repeat) If expansion needs to be done, choose appropriate rule (How to decide which rule to choose?) If no rule found, declare error If several rules found, the grammar (set of rules) is ambiguous

Scanning & Parsing Combined main() { int a,b; a = b; } Parser Scanner "Please, get me the next token"

Scanning & Parsing Combined main() { int a,b; a = b; } Parser Scanner Token: MAIN  MAIN OPENPAR CLOSEPAR

Scanning & Parsing Combined main() { int a,b; a = b; } Parser Scanner "Please, get me the next token"  MAIN OPENPAR CLOSEPAR

Scanning & Parsing Combined main() { int a,b; a = b; } Parser Scanner Token: OPENPAR  MAIN OPENPAR CLOSEPAR

Scanning & Parsing Combined main() { int a,b; a = b; } Parser Scanner Token: CLOSEPAR  MAIN OPENPAR CLOSEPAR  NULL

Scanning & Parsing Combined main() { int a,b; a = b; } Parser Scanner Token: CLOSEPAR  MAIN OPENPAR CLOSEPAR  NULL

Scanning & Parsing Combined main() { int a,b; a = b; } Parser Scanner Token: CLOSEPAR  MAIN OPENPAR CLOSEPAR

Scanning & Parsing Combined main() { int a,b; a = b; } Parser Scanner Token: CURLYOPEN  MAIN OPENPAR CLOSEPAR  CURLYOPEN CURLYCLOSE

Scanning & Parsing Combined main() { int a,b; a = b; } Parser Scanner Token: INT  MAIN OPENPAR CLOSEPAR  CURLYOPEN CURLYCLOSE  VAR ;  INT

Scanning & Parsing Combined main() { int a,b; a = b; } Parser Scanner Token: INT  MAIN OPENPAR CLOSEPAR  CURLYOPEN CURLYCLOSE  VAR ;  INT

Scanning & Parsing Combined main() { int a,b; a = b; } Parser Scanner Token: INT  MAIN OPENPAR CLOSEPAR  CURLYOPEN CURLYCLOSE  VAR ;  INT

Scanning & Parsing Combined main() { int a,b; a = b; } Parser Scanner Token: VAR  MAIN OPENPAR CLOSEPAR  CURLYOPEN CURLYCLOSE  VAR ; , VAR  NULL

Scanning & Parsing Combined main() { int a,b; a = b; } Parser Scanner Token: ',' [COMMA]  MAIN OPENPAR CLOSEPAR  CURLYOPEN CURLYCLOSE  VAR ; , VAR  NULL

Scanning & Parsing Combined main() { int a,b; a = b; } Parser Scanner Token: VAR  MAIN OPENPAR CLOSEPAR  CURLYOPEN CURLYCLOSE  VAR ; , VAR  NULL

Scanning & Parsing Combined main() { int a,b; a = b; } Parser Scanner Token: ';'  MAIN OPENPAR CLOSEPAR  CURLYOPEN CURLYCLOSE  VAR ; , VAR  NULL

Scanning & Parsing Combined main() { int a,b; a = b; } Parser Scanner Token: ';'  MAIN OPENPAR CLOSEPAR  CURLYOPEN CURLYCLOSE  VAR ; , VAR  NULL

Scanning & Parsing Combined main() { int a,b; a = b; } Parser Scanner Token: ';'  MAIN OPENPAR CLOSEPAR  CURLYOPEN CURLYCLOSE  VAR ; , VAR  NULL

Scanning & Parsing Combined main() { int a,b; a = b; } Parser Scanner Token: ';'  MAIN OPENPAR CLOSEPAR  CURLYOPEN CURLYCLOSE  VAR ; , VAR  NULL

Scanning & Parsing Combined main() { int a,b; a = b; } Parser Scanner Token: ';'  MAIN OPENPAR CLOSEPAR  CURLYOPEN CURLYCLOSE  VAR ;

Scanning & Parsing Combined main() { int a,b; a = b; } Parser Scanner Token: ';'  MAIN OPENPAR CLOSEPAR  CURLYOPEN CURLYCLOSE  VAR ;

Scanning & Parsing Combined main() { int a,b; a = b; } Parser Scanner Token: VAR  MAIN OPENPAR CLOSEPAR  CURLYOPEN CURLYCLOSE  VAR = ;  VAR

Scanning & Parsing Combined main() { int a,b; a = b; } Parser Scanner Token: '='  MAIN OPENPAR CLOSEPAR  CURLYOPEN CURLYCLOSE  VAR = ;  VAR

Scanning & Parsing Combined main() { int a,b; a = b; } Parser Scanner Token: VAR  MAIN OPENPAR CLOSEPAR  CURLYOPEN CURLYCLOSE  VAR = ;  VAR

Scanning & Parsing Combined main() { int a,b; a = b; } Parser Scanner Token: VAR  MAIN OPENPAR CLOSEPAR  CURLYOPEN CURLYCLOSE  VAR = ;  VAR

Scanning & Parsing Combined main() { int a,b; a = b; } Parser Scanner Token: VAR  MAIN OPENPAR CLOSEPAR  CURLYOPEN CURLYCLOSE  VAR = ;  VAR

Scanning & Parsing Combined main() { int a,b; a = b; } Parser Scanner Token: ';'  MAIN OPENPAR CLOSEPAR  CURLYOPEN CURLYCLOSE  VAR = ;

Scanning & Parsing Combined main() { int a,b; a = b; } Parser Scanner Token: ';'  MAIN OPENPAR CLOSEPAR  CURLYOPEN CURLYCLOSE  VAR = ;

Scanning & Parsing Combined main() { int a,b; a = b; } Parser Scanner Token: CURLYCLOSE  MAIN OPENPAR CLOSEPAR  CURLYOPEN CURLYCLOSE

What Is Happening? During/after parsing?  Tokens get gobbled Symbol tables  Variables have attributes  Declaration attached attributes to variables Semantic actions  What are semantic actions? Semantic checks

Symbol Table int a,b; Declares a and b  Within current scope  Type integer Use of a and b now legal Basic Symbol Table NameTypeScope aint"main" bint"main"

Typical Semantic Actions Enter variable declaration into symbol table Look up variables in symbol table Do binding of looked-up variables (scoping rules, etc.) Do type checking for compatibility Keep the semantic context of processing a + b + c  t1 = a + b t2 = t1 + c Semantic Context

How Are Semantic Actions Called? Action symbols embedded in the grammar  Each action symbol represents a semantic procedure  These procedures do things and/or return values Semantic procedures are called by parser at appropriate places during parsing Semantic stack implements & stores semantic records

Semantic Actions  #put-type #do-decl  int | float  #add-decl  ID#proc-decl #put-type puts given type on semantic stack #proc-decl builds decl record for var on stack #add-decl builds decl-chain #do-decl traverses chain on semantic stack using backwards pointers entering each var into symbol table id3 id2 id1 type #do-decl  NameTypeScope id113 id213 id313 decl record

Semantic Actions What else can semantic actions do in addition to storing and looking up names in a symbol table? Two type of semantic actions  Checking (binding, type compatibility, scoping, etc.)  Translation (generate temporary values, propagate them to keep semantic context).

Full Compiler Structure Scanner Parser Semantic Action Start Code Generation CODE Semantic Error Most compilers have two pass

Summary Front-end of compiler: scanner and parser Translation takes place in back end Scanner, parser and code generator are automated  How? We will answer this question in this class