Programming Languages

Slides:



Advertisements
Similar presentations
Chapter 8 ICS 412. Code Generation Final phase of a compiler construction. It generates executable code for a target machine. A compiler may instead generate.
Advertisements

Lecture 01 - Introduction Eran Yahav 1. 2 Who? Eran Yahav Taub 734 Tel: Monday 13:30-14:30
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Defining practical programming languages Carlos Varela RPI.
PLLab, NTHU Cs2403 Programming Languages Implementation Issues Cs2403 Programming Language Spring 2005 Kun-Yuan Hsieh.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 2 Syntax A language that is simple to parse.
Compilation 2007 The What and Why of Compilers Michael I. Schwartzbach BRICS, University of Aarhus.
Reference Book: Modern Compiler Design by Grune, Bal, Jacobs and Langendoen Wiley 2000.
Compiler Design Lexical Analysis Syntactical Analysis Semantic Analysis Optimization Code Generation.
Programming Languages Structure
Overview of Compiler Design CIS 631, CSE 691, CIS400, CSE 400 Compiler Design Dr. Nancy McCracken January 15, 2008.
Introduction and Syntax. Course objectives Discuss features of programming languages. Discuss how the features are implemented in a simple computer architecture.
Compiler design Computer Science Rensselaer Polytechnic Lecture 1.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
Code Generation Introduction. Compiler (scalac, gcc) Compiler (scalac, gcc) machine code (e.g. x86, arm, JVM) efficient to execute i=0 while (i < 10)
CS 415: Programming Languages Chapter 1 Aaron Bloomfield Fall 2005.
Chapter 8 High-Level Programming Languages (modified by Erin Chambers)
High-Level Programming Languages: C++
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.
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.
Java Bytecode What is a.class file anyway? Dan Fleck George Mason University Fall 2007.
LANGUAGE TRANSLATORS: WEEK 24 TRANSLATION TO ‘INTERMEDIATE’ CODE (overview) Labs this week: Tutorial Exercises on Code Generation.
Java Programming Introduction & Concepts. Introduction to Java Developed at Sun Microsystems by James Gosling in 1991 Object Oriented Free Compiled and.
Programming Languages –14 David Watt (Glasgow) Steven Wong (Singapore) Moodle : Computing Science → Level 3 → Programming Languages 3 © 2012 David.
CSC 338: Compiler design and implementation
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages.
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
Copyright © 2007 Addison-Wesley. All rights reserved.1-1 Reasons for Studying Concepts of Programming Languages Increased ability to express ideas Improved.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
1 Programming Languages Fundamentals Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM.
CPS 506 Comparative Programming Languages Syntax Specification.
Chapter 1 Introduction. Chapter 1 - Introduction 2 The Goal of Chapter 1 Introduce different forms of language translators Give a high level overview.
Chapter 1 Introduction Study Goals: Master: the phases of a compiler Understand: what is a compiler Know: interpreter,compiler structure.
. 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.
Compiler Design Introduction 1. 2 Course Outline Introduction to Compiling Lexical Analysis Syntax Analysis –Context Free Grammars –Top-Down Parsing –Bottom-Up.
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.
1 A Simple Syntax-Directed Translator CS308 Compiler Theory.
Introduction to Compilers Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY.
CSCE 314 Programming Languages
Programming Language Concepts (CIS 635) Elsa L Gunter 4303 GITC NJIT,
CSC 4181 Compiler Construction
Language Implementation Overview John Keyser Spring 2016.
Overview of Compilation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 2.
CSC 8505 Compiler Construction
Reading Exercise 0 Discussion. Imperative vs Declarative A.Prolog, SQL, Perl B.ML, Lisp, SQL C.C, Java,Smalltalk D.C#, Haskell, Spreadsheets E.C++, Eiffel,
COP4020 Programming Languages Introduction Prof. Robert van Engelen (modified by Prof. Em. Chris Lacher)
Programming Languages Salihu Ibrahim Dasuki (PhD) CSC102 INTRODUCTION TO COMPUTER SCIENCE.
Chapter 1 Introduction Samuel College of Computer Science & Technology Harbin Engineering University.
Chapter 1. Introduction.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Advanced Computer Systems
Component 1.6.
Introduction Chapter : Introduction.
Concepts of Programming Languages
PROGRAMMING LANGUAGES
Overview of Compilation The Compiler BACK End
Course supervisor: Lubna Siddiqui
CSE401 Introduction to Compiler Construction
Overview of Compilation The Compiler BACK End
Compilers B V Sai Aravind (11CS10008).
COP4020 Programming Languages
Compiler design.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
A Tour of Language Implementation
CSc 453 Interpreters & Interpretation
Presentation transcript:

Programming Languages CSCE 314 Programming Languages A Tour of Language Implementation Dr. Hyunyoung Lee

Programming Language Characteristics Different approaches to describe computations, to instruct computing devices E.g., Imperative, declarative, functional Different approaches to communicate ideas between humans E.g., Procedural, object-oriented, domain-specific languages Programming languages need to have a specification: meaning (semantics) of all sentences (programs) of the language should be unambiguously specified

Programming Language Expressiveness Different levels of abstraction More abstract Haskell, Prolog sum[1..100] Scheme, Java mynum.add(5) C i++; Assembly language iadd Machine language 10111001010110

Evolution of Languages 1940’s: connecting wires to represent 0’s and 1’s 1950’s: assemblers, FORTRAN, COBOL, LISP 1960’s: ALGOL, BCPL (→ B → C), SIMULA 1970’s: Prolog, FP, ML, Miranda 1980’s: Eiffel, C++ 1990’s: Haskell, Java, Python 2000’s: D, C#, Spec#, F#, X10, Fortress, Scala, Ruby, . . . 2010’s: Agda, Coq . . . Evolution has been and is toward higher level of abstraction

Defining a Programming Language Syntax: Defines the set of valid programs Usually defined with the help of grammars and other conditions if-statement ::= if cond-expr then stmt else stmt | if cond-expr then stmt cond-expr ::= . . . stmt ::= . . . Semantics: Defines the meaning of programs Defined, e.g., as the effect of individual language constructs to the values of program variables if cond then true-part else false-part If cond evaluates to true, the meaning is that of true-part; if cond evaluates to false, the meaning is that of false-part.

Implementing a Programming Language Task is to undo abstraction. From the source: int i; i = 2; i = i + 7; to assembly (this is actually Java bytecode): iconst_2 // Put integer 2 on stack istore_1 // Store the top stack value at location 1 iload_1 // Put the value at location 1 on stack bipush 7 // Put the value 7 on the stack iadd // Add two top stack values together istore_1 // The sum, on top of stack, stored at location 1 to machine language: 00101001010110 01001010100101

Implementing a Programming Language – How to Undo the Abstraction Source program Optimizer I/O Type checker Code generator Machine code Lexer Parser Machine Bytecode JIT Interpreter Virtual machine I/O I/O

Compiling and Interpreting (1) Typically compiled languages: C, C++, Eiffel, FORTRAN Java, C# (compiled to bytecode) Typically interpreted languages: Python, Perl, Prolog, LISP Both compiled and interpreted: Haskell, ML, Scheme

Compiling and Interpreting (2) Borderline between interpretation and compilation not clear (not that important either) Same goes with machine code vs. byte code. Examples of modern compiling/interpreting/executing scenarios: C and C++ can be compiled to LLVM bytecode Java compiled to bytecode, bytecode interpreted by JVM, unless it is first JITted to native code, which can then be run on a virtual machine such as VMWare

Lexical Analysis From a stream of characters if (a == b) return; to a stream of tokens keyword[‘if‘] symbol[‘(‘] identifier[‘a‘] symbol[‘==‘] identifier[‘b‘] symbol[‘)‘] keyword[‘return‘] symbol[‘;‘]

Syntactic Analysis (Parsing) From a stream of characters if (a == b) return; to a stream of tokens keyword[‘if‘] symbol[‘(‘] identifier[‘a‘] symbol[‘==‘] identifier[‘b‘] symbol[‘)‘] keyword[‘return‘] symbol[‘;‘] to a syntax tree (parse tree) if-statement expression statement equality operator return stmt identifier identifier a b

Type Checking if (a == b) return; Annotate syntax tree with types, check that types are used correctly if-statement : OK statement : OK identifier : int b a expression : bool equality operator : integer equality return stmt : void

Optimization int a = 10; int b = 20 – a; if (a == b) return; Constant propagation can deduce that always a==b, allowing the optimizer to transform the tree: if-statement : OK statement : OK identifier : int b a expression : bool equality operator : integer equality return stmt : void if-statement : OK statement : OK true constant : bool return stmt : void return stmt : void

Code Generation Code generation is essentially undoing abstractions, until code is executable by some target machine: Control structures become jumps and conditional jumps to labels (essentially goto statements) Variables become memory locations Variable names become addresses to memory locations Abstract data types etc. disappear. What is left is data types directly supported by the machine such as integers, bytes, floating point numbers, etc. Expressions become loads of memory locations to registers, register operations, and stores back to memory

Phases of Compilation/Execution Characterized by Errors Detected Lexical analysis: 5abc a === b Syntactic analysis: if + then; int f(int a]; Type checking: void f(); int a; a + f(); Execution time: int a[100]; a[101] = 5;