CSC 313 – Advanced Programming Topics. Today’s Goal  Make you forget reading that was assigned  I went back & reviewed others; none like this one 

Slides:



Advertisements
Similar presentations
Compilers and Language Translation
Advertisements

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.
Compiler Construction Dr. Naveed Ejaz Lecture 2. 2 Two-pass Compiler Front End Back End source code IR machine code errors.
1 Foundations of Software Design Lecture 24: Compilers, Lexers, and Parsers; Intro to Graphs Marti Hearst Fall 2002.
Chapter3: Language Translation issues
College of Computer Science & Technology Compiler Construction Principles & Implementation Techniques -1- Compiler Construction Principles & Implementation.
BİL744 Derleyici Gerçekleştirimi (Compiler Design)1.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
Compiled by Benjamin Muganzi 3.2 Functions and Purposes of Translators Computing 9691 Paper 3 1.
Introduction to Programming Lecture Number:. What is Programming Programming is to instruct the computer on what it has to do in a language that the computer.
ICS611 Introduction to Compilers Set 1. What is a Compiler? A compiler is software (a program) that translates a high-level programming language to machine.
INTRODUCTION TO COMPUTING CHAPTER NO. 06. Compilers and Language Translation Introduction The Compilation Process Phase 1 – Lexical Analysis Phase 2 –
COP4020 Programming Languages
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.
Chapter 10: Compilers and Language Translation Invitation to Computer Science, Java Version, Third Edition.
1 Programming Languages Tevfik Koşar Lecture - II January 19 th, 2006.
CSC 338: Compiler design and implementation
Lexical Analysis - An Introduction. The Front End The purpose of the front end is to deal with the input language Perform a membership test: code  source.
Lexical Analysis - An Introduction Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 2.
D. M. Akbar Hussain: Department of Software & Media Technology 1 Compiler is tool: which translate notations from one system to another, usually from source.
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 3, 09/11/2003 Prof. Roy Levow.
Review 1.Lexical Analysis 2.Syntax Analysis 3.Semantic Analysis 4.Code Generation 5.Code Optimization.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
Lexical Analysis: Finite Automata CS 471 September 5, 2007.
CPS 506 Comparative Programming Languages Syntax Specification.
What on Earth? LEXEMETOKENPATTERN print p,r,i,n,t (leftpar( 4number4 *arith* 5number5 )rightpar) userAnswerID Letter followed by letters and digits “Game.
Compiler design Lecture 1: Compiler Overview Sulaimany University 2 Oct
Introduction Lecture 1 Wed, Jan 12, The Stages of Compilation Lexical analysis. Syntactic analysis. Semantic analysis. Intermediate code generation.
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.
D Goforth COSC Translating High Level Languages Note error in assignment 1: #4 - refer to Example grammar 3.4, p. 126.
IN LINE FUNCTION AND MACRO Macro is processed at precompilation time. An Inline function is processed at compilation time. Example : let us consider this.
The Functions and Purposes of Translators Syntax (& Semantic) Analysis.
. n COMPILERS n n AND n n INTERPRETERS. -Compilers nA compiler is a program thatt reads a program written in one language - the source language- and translates.
Introduction to Compiling
Compiler Design Introduction 1. 2 Course Outline Introduction to Compiling Lexical Analysis Syntax Analysis –Context Free Grammars –Top-Down Parsing –Bottom-Up.
Compiler Construction By: Muhammad Nadeem Edited By: M. Bilal Qureshi.
The Model of Compilation Natawut Nupairoj, Ph.D. Department of Computer Engineering Chulalongkorn University.
What am I? while b != 0 if a > b a := a − b else b := b − a return a AST == Abstract Syntax Tree.
Lexical Analysis – Part II EECS 483 – Lecture 3 University of Michigan Wednesday, September 13, 2006.
CSC 4181 Compiler Construction
LECTURE 3 Compiler Phases. COMPILER PHASES Compilation of a program proceeds through a fixed series of phases.  Each phase uses an (intermediate) form.
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
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.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
CS416 Compiler Design1. 2 Course Information Instructor : Dr. Ilyas Cicekli –Office: EA504, –Phone: , – Course Web.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture Ahmed Ezzat.
Advanced Computer Systems
Intro to compilers Based on end of Ch. 1 and start of Ch. 2 of textbook, plus a few additional references.
PRINCIPLES OF COMPILER DESIGN
Introduction to Compiler Construction
CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Lexical and Syntax Analysis
PROGRAMMING LANGUAGES
Finite-State Machines (FSMs)
-by Nisarg Vasavada (Compiled*)
Formal Language Theory
Compiler Lecture 1 CS510.
CS416 Compiler Design lec00-outline September 19, 2018
Introduction CI612 Compiler Design CI612 Compiler Design.
Compilers B V Sai Aravind (11CS10008).
CS 3304 Comparative Languages
Compiler design.
CS416 Compiler Design lec00-outline February 23, 2019
Chapter 10: Compilers and Language Translation
Lec00-outline May 18, 2019 Compiler Design CS416 Compiler Design.
Presentation transcript:

CSC 313 – Advanced Programming Topics

Today’s Goal  Make you forget reading that was assigned  I went back & reviewed others; none like this one  Highlight process used by modern compilers  Consider steps taken & how design works  Where optimizations occur will be discussed  Review a kick-ass design honed through years  Understand decisions to see good design in action  See design process that results in design patterns

Translations  Translating docs from English to other language  But all of this material selected from college library  Undecipherable & meaningless documents included  Workers highly-trained & so saving time (& $$) critical  Reject untranslatable documents & explain why  Need to give workers chance to correct mistakes  Money important, so limit time on these documents

Translations  Translating docs from English to other language  But all of this material selected from college library  Undecipherable & meaningless documents included  Workers highly-trained & so saving time (& $$) critical  Reject untranslatable documents & explain why  Need to give workers chance to correct mistakes  Money important, so limit time on these documents How can we do this?

What Errors Can Occur?

 Document read in unreadable or not English  Has “words”, but grammatically incorrect  Meaningless jumble means cannot translate

What Errors Can Occur?  Document read in unreadable or not English αυηθι μςτ ϕϖ κλσροπ χψτν γδζεεθ μςτυ  Has “words”, but grammatically incorrect  Meaningless jumble means cannot translate

What Errors Can Occur?  Document read in unreadable or not English αυηθι μςτ ϕϖ κλσροπ χψτν γδζεεθ μςτυ  Has “words”, but grammatically incorrect 4 u 2 c I sent U pix. ty  Meaningless jumble means cannot translate

What Errors Can Occur?  Document read in unreadable or not English αυηθι μςτ ϕϖ κλσροπ χψτν γδζεεθ μςτυ  Has “words”, but grammatically incorrect 4 u 2 c I sent U pix. ty  Meaningless jumble means cannot translate Mary flow over the swimming pizza

How To Translate?

Money, money, money!  This project useful for many languages  Different alphabet or punctuation may be used  Will need to adjust to different grammar rules  Change in scoping rules & variable declaration types

Money, money, money!

 This project useful for many languages  Different alphabet or punctuation may be used  Will need to adjust to different grammar rules  Change in scoping rules & variable declaration types  Could translate to many different languages  (Unless written by Microsoft or in Alabama)

How To Translate?

How To Translate? (Redux)  Split translations process into multiple layers  Lexical analyzer will check legal words & punctuation  Grammar errors found by parser (syntactic analysis)  Semantic analysis will check document meaningful  Optimizations happen here, since program is valid  Code generator “lowers” results into new language

All About the Benjamins  Most layers’ actions language-dependent  Reusing details hard, but algorithms very similar  Between layers, pass language-independent data  Define protocols specifying how layers interact  Each layer independent & can change easily  Limit rewriting, instead reuse whenever possible  Must follow protocols, but these set out clearly  Popular approach: gcc, XCode, Google Translate

Planning Data & Interactions  Data to be passed depends on work layers do  Individual words & punctuation output by lexer  Parser goes through this data & find sentences  Build paragraphs by checking sentences meaningful  Interactions based on input size needed  Item-by-item analyses needed to build sentences  Semantic analysis works by using whole module  Entire program needed for optimizations & output

Planning Data & Interactions  Data to be passed depends on work layers do  Individual words & punctuation output by lexer  Parser goes through this data & find sentences  Build paragraphs by checking sentences meaningful  Interactions based on input size needed iteration  Item iteration needed to build sentences  Semantic analysis works by using whole module  Entire program needed for optimizations & output

Resulting Design  Lexer is an Iterator for words & punctuation  Illegal characters found & reported as errors  Parser builds syntax trees for each module  Function, class, or file may be language’s module  Must be conservative: outputs result for entire file  Good syntax tree output by semantic analysis  When use found, variable linked to declaration & type  Match calls with functions & all checked if legal HIR  Result called Higher-order Intermediate Representation

Lexical Analysis In Detail  Creates “tokens” from file being compiled  While it does this, checks characters are legal  Keywords identified ( for, int, while …) in input  Code parsed to identify literals (strings, numbers)  Does not understand code; only splitting it out  Only layer looking at code, so skips comments

How Does Lexer Work?  Regular expressions defined for items to find  They’re back!! Turned into big finite state machine  Defines enum or hierarchy for returned data struct Symbol { Token type; String value; } enum Token { NUMBER, STRING, WORD, GT,,... }

Why Use State Machines?  Limits knowledge needed for coding a lexer  Machine has set of states connected by edges  State determines next state, given an input  Need to know initial & accepting states only  States define language; processing unchanged

Why Use State Machines?  Limits knowledge needed for coding a lexer  Machine has set of states connected by edges  State determines next state, given an input  Need to know initial & accepting states only  States define language; processing unchanged  Obviously, this is part of State design pattern (Covered later in term, in case you wondering)  Maximizes reuse of code within lexical analysis  Limits rework to developing regular expressions

For Next Lecture  Read pages 37 – 55 in book  Get back into easier code & design patterns  1-to-many communication is problem why?  Why is this critical to all event-based coding?  Lindsay Lohan's secret to success related to this?