PLLab, NTHU Cs2403 Programming Languages Implementation Issues Cs2403 Programming Language Spring 2005 Kun-Yuan Hsieh.

Slides:



Advertisements
Similar presentations
Copyright © 1998 by Addison Wesley Longman, Inc. 1 Chapter One Preliminaries, including –Why study PL concepts? –Programming domains –PL evaluation criteria.
Advertisements

CSI 3125, Preliminaries, page 1 Programming languages and the process of programming –Programming means more than coding. –Why study programming languages?
Chapter 1: Preliminaries
Reasons to study concepts of PL
ISBN Chapter 1 Preliminaries. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Chapter 1 Topics Motivation Programming Domains.
ISBN Chapter 1 Preliminaries. Copyright © 2007 Addison-Wesley. All rights reserved.1-2 Chapter 1 Topics Reasons for Studying Concepts of.
CS 354 Overview. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Course Topics What is a programming language? What features do programming.
Programming Languages Structure
ISBN Lecture 01 Preliminaries. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Lecture 01 Topics Motivation Programming.
ISBN Chapter 1 Topics Motivation Programming Domains Language Evaluation Criteria Influences on Language Design Language Categories Language.
Copyright © 1998 by Addison Wesley Longman, Inc. 1 Concepts of Programming Languages Chapter 1.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
Programming Language Concepts
Chapter 1 Preliminaries. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Chapter 1 Topics Reasons for Studying Concepts of Programming Languages.
Language Evaluation Criteria
ISBN Chapter 1 Preliminaries. Copyright © 2006 Addison-Wesley. All rights reserved. 1-2 Chapter 1 Topics Reasons for Studying Concepts of.
CS 355 – Programming Languages
(1.1) COEN 171 Programming Languages Winter 2000 Ron Danielson.
Chapter 1. Introduction.
CS 363 Comparative Programming Languages
CS 330 Programming Languages 09 / 04 / 2008 Instructor: Michael Eckmann.
Chapter 1 Preliminaries CS Concepts of Programming Languages.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages.
Copyright © 2007 Addison-Wesley. All rights reserved.1-1 Reasons for Studying Concepts of Programming Languages Increased ability to express ideas Improved.
ICS 313 Fundamentals of Programming Languages Instructor: Abdul Wahid Wali Lecturer, CSSE, UoH
1 Programming Languages Fundamentals Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM.
ISBN CS 354 Preliminaries. Copyright © 2006 Addison-Wesley. All rights reserved.1-2 Course Topics What is a programming language? What features.
ISBN Chapter 1 Preliminaries. Copyright © 2015 Pearson. All rights reserved.1-2 Chapter 1 Topics Reasons for Studying Concepts of Programming.
ISBN Chapter 1 Preliminaries. Copyright © 2009 Addison-Wesley. All rights reserved.1-2 Chapter 1 Topics Reasons for Studying Concepts of.
Programming Domains 1.Scientific Applications Typically, scientific applications have simple data structures but require large numbers of floating-point.
Language Translation A programming language processor is any system that manipulates programs expressed in a PL A source program in some source language.
Chapter 1: Preliminaries Lecture # 2. Chapter 1: Preliminaries Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation.
Concepts of Programming Languages
Chapter 1 Preliminaries.
Why study programming languages?
Chapter 1 Preliminaries.
Chapter 1 Preliminaries.
Chapter 1 Preliminaries.
PROGRAMMING LANGUAGES
Chapter 1 Reasons to study concepts of PLs Programming Domains
1.1 Reasons to study concepts of PLs
Chapter 1 Preliminaries.
Chapter 1 Preliminaries.
Chapter 1 Preliminaries.
CS 3304 Comparative Languages Fall 2011
Chapter 1 Introduction.
Chapter 1 Preliminaries.
Chapter 1 Preliminary. Chapter 1 Preliminary 1.1 Reasons for Studying Concepts of Programming Languages Increased capacity to express ideas Improved.
Chapter 1 Preliminaries.
CS 3304 Comparative Languages Fall 2011
Chapter 1 Preliminaries.
Chapter 1 Preliminaries.
Chapter 1 Preliminaries.
Chapter 1 Preliminaries.
Chapter 1 Preliminaries.
Chapter 1 Topics Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation Criteria Influences on Language Design.
Chapter 1 Preliminaries.
Chapter 1 Preliminaries.
Chapter 1 Preliminaries.
Chapter 1 Preliminaries.
Chapter 1 Preliminaries.
Programming Languages, Preliminaries, History & Evolution
Reasons To Study Programming Languages
Chapter 1 Preliminaries.
Chapter 1 Preliminaries.
Chapter 1 Preliminaries.
Presentation transcript:

PLLab, NTHU Cs2403 Programming Languages Implementation Issues Cs2403 Programming Language Spring 2005 Kun-Yuan Hsieh

PLLab, NTHU Cs2403 Programming Languages Why studying? Increased capacity to express ideas –Language feature limits the form of algorithm you construct –Simulating other language ’ s feature to break this limit Improved ability of choosing right PL –To give you the ability to make informed language choices Increase ability to learn new PL –Programming language is in a state of continuous evolution –Vocabulary and fundamental concepts helps you learn

PLLab, NTHU Cs2403 Programming Languages Why studying? (cont.) Better understanding of implementation –To use a language in the way it was designed to be used Overall advancement of computing –Most popular languages are the best available? –Better educated programmer leads to better language population?

PLLab, NTHU Cs2403 Programming Languages Evaluation criteria Readability –Important because maintenance is cost –Overall simplicity since we tend to learn subset of it Feature multiplicity: more than one way to accomplish one operation –Count = count +1 –Count += 1 –Count ++ operation overloading –Reducing # of operations Less readable if carried too far –Assembly language is simple but less readable Orthogonality

PLLab, NTHU Cs2403 Programming Languages Evaluation criteria Readability (cont.) –Control statement Read from top to bottom is easier to understand than jump to follow the execution order –Data type and structure makes your meaning clear timeOut = 1 v.s. timeOut = true!! –Syntax –Identifier forms: using connotative names –Special words: program appearance –Form and meaning: statement indicates the purpose

PLLab, NTHU Cs2403 Programming Languages Evaluation criteria Writability –What affects readability affect writability –Simplicity and orthogonality Simplicity avoid misusing but may leads to undetected error –Support for abstraction to define then use complicated structures in a simple way Subprogram Tree (using point or array!!) –Expressivity

PLLab, NTHU Cs2403 Programming Languages Evaluation criteria Reliability –Performs to its specification under all conditions –Type checking –Exception handling –Aliasing –Readability and writability

PLLab, NTHU Cs2403 Programming Languages Evaluation criteria Cost –Training programmers to use language –Writing programs –Compiling programs, optimization –Executing programs –Language implementation system Java interpreter is free –Reliability –Maintaining programs

PLLab, NTHU Cs2403 Programming Languages Influences on language design Computer architecture –Software executes on hardware Programming methodologies –1950s and early 1960s: machine efficiency –Late 1960s: programming efficiency, readability, better control structures –Late 1970s: data abstraction –Middle 1980s: object-oriented programming

PLLab, NTHU Cs2403 Programming Languages The von Neumann Arch (cont.) Control unit Arithmetic and logic unit Instructions and data Results of operations Memory (stores both instructions and data) Input and output devices

PLLab, NTHU Cs2403 Programming Languages A grid-computer arch (non-Von Neumann) CPU

PLLab, NTHU Cs2403 Programming Languages Categories & trade-off PL categories: –Imperative (C, Pascal, FORTRAN) –Functional (LISP, Scheme) –Logic (Prolog) –Object-Oriented (C++, C Sharp, Java) Design trade-off –Reliability v.s. cost of execution –Writability v.s. readability –Flexibility v.s. safety

PLLab, NTHU Cs2403 Programming Languages Implementation methods Compilation (Pascal, C, C++, FORTRAN) –Translate high-level program to machine code –Slow translation –Fast execution Interpretation (LISP, Scheme, scripts) –No translation, interpreted by interpreter –Slow execution (translated on execution) –Easy to debug, run-time error refers to source level units Hybrid method (Java, CSharp, Perl) –Translated to intermediate language (Java byte code, MSIL) –Medium execution speed

PLLab, NTHU Cs2403 Programming Languages Compiler examples

PLLab, NTHU Cs2403 Programming Languages Interpreter v.s. Compiler Input data Results Interpreter Source Program Compiler Executable (sample.exe) Source Program

PLLab, NTHU Cs2403 Programming Languages Hybrid method Java Byte Code Java Source Code Java Compiler Java Interpreter on Windows Java Interpreter on Unix ( Stored in the disk & Publicly available ) (private property)

PLLab, NTHU Cs2403 Programming Languages C#VB.NET Visual J#.NET MSIL Linux native code Windows native code Mac OS native code Compile into MSIL CLR do this Support now Will Support soon Hybrid method example-.Net

PLLab, NTHU Cs2403 Programming Languages Helloworld.il

PLLab, NTHU Cs2403 Programming Languages Virtual computer concept C++ compiler FORTRAN compiler C compiler Ada compiler … Assembler Operating System Command interpreter LISP interpreter Operating system Macroinstruction interpreter Bare machine Virtual C Computer Virtual C++ Computer

PLLab, NTHU Cs2403 Programming Languages Levels of Programming Languages High-level program class Triangle {... float surface() return b*h/2; } class Triangle {... float surface() return b*h/2; } Low-level program ldloc.i4 b ldloc.i4 h mul ldc.i4 2 div ret ldloc.i4 b ldloc.i4 h mul ldc.i4 2 div ret Executable Machine code

PLLab, NTHU Cs2403 Programming Languages Compiler phases Lexical analyzer Syntax analyzer Intermediate code generator Semantic analyser Code optimizer Code generator Symbol-table manager Error handler Source program Target program

PLLab, NTHU Cs2403 Programming Languages Lexical analysis Source program is read from left-to-right and group into tokens Tokens: sequences of characters have a meaning Ex: –a= b + c * 10 identifier a assignment symbol = identifier b plus sign + identifier c multiplication sign * number 10

PLLab, NTHU Cs2403 Programming Languages Syntax analysis Grouping the tokens into grammatical phrases (hierarchical) Usually presented as a parse tree Expressed by recursive rules –Any identifier is an expression –Any number is an expression –If exp1 and exp2 are expressions, then so are exp1 + exp2 exp1 * exp3 Assignment statement expression identifierexpression a identifier b c 10 number = + *

PLLab, NTHU Cs2403 Programming Languages Semantics Specification of semantics is concerned with specifying the “ meaning ” of well-formed programs. Terminology: –Expressions are evaluated and yield values (and may or may not perform side effects) –Commands are executed and perform side effects. –Declarations are elaborated to produce bindings Side effects: – change the values of variables – perform input/output

PLLab, NTHU Cs2403 Programming Languages Syntax Analysis Scanner Source Program Abstract Syntax Tree Error Reports Parser Stream of “Tokens” Stream of Characters Error Reports Dataflow chart

PLLab, NTHU Cs2403 Programming Languages Type Checking For most statically typed programming languages, a bottom up algorithm over the AST: Types of expression AST leaves are known immediately: –literals => obvious –variables => from the ID table –named constants => from the ID table Types of internal nodes are inferred from the type of the children and the type rule for that kind of expression