Motivation for Language Specification

Slides:



Advertisements
Similar presentations
Agenda Definitions Evolution of Programming Languages and Personal Computers The C Language.
Advertisements

Semantics Static semantics Dynamic semantics attribute grammars
ICE1341 Programming Languages Spring 2005 Lecture #6 Lecture #6 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Control Structures Any mechanism that departs from straight-line execution: –Selection: if-statements –Multiway-selection: case statements –Unbounded iteration:
8. Introduction to Denotational Semantics. © O. Nierstrasz PS — Denotational Semantics 8.2 Roadmap Overview:  Syntax and Semantics  Semantics of Expressions.
Introduction to Programming Languages Nai-Wei Lin Department of Computer Science and Information Engineering National Chung Cheng University.
ISBN Chapter 3 Describing Syntax and Semantics.
Copyright © 2006 Addison-Wesley. All rights reserved. 3.5 Dynamic Semantics Meanings of expressions, statements, and program units Static semantics – type.
Fall Semantics Juan Carlos Guzmán CS 3123 Programming Languages Concepts Southern Polytechnic State University.
CS 330 Programming Languages 09 / 19 / 2006 Instructor: Michael Eckmann.
1 Semantic Description of Programming languages. 2 Static versus Dynamic Semantics n Static Semantics represents legal forms of programs that cannot be.
CS 355 – Programming Languages
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Ch.2: Syntax and Semantics Fall 2005.
Comp 205: Comparative Programming Languages Semantics of Imperative Programming Languages denotational semantics operational semantics logical semantics.
Language Specfication and Implementation - PART II: Semantics of Procedural Programming Languages Lee McCluskey Department of Computing and Mathematical.
CS 330 Programming Languages 09 / 18 / 2007 Instructor: Michael Eckmann.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Operational Semantics.
Programming Language Semantics Mooly SagivEran Yahav Schrirber 317Open space html://
PSUCS322 HM 1 Languages and Compiler Design II Formal Semantics Material provided by Prof. Jingke Li Stolen with pride and modified by Herb Mayer PSU Spring.
C SC 520 Principles of Programming Languages 1 C SC 520: Principles of Programming Languages Peter J. Downey Department of Computer Science Spring 2006.
CS 330 Programming Languages 09 / 16 / 2008 Instructor: Michael Eckmann.
Describing Syntax and Semantics
MCA –Software Engineering Kantipur City College. Topics include  Formal Methods Concept  Formal Specification Language Test plan creation Test-case.
Language Evaluation Criteria
PROGRAMMING LANGUAGES The Study of Programming Languages.
Overview of Formal Methods. Topics Introduction and terminology FM and Software Engineering Applications of FM Propositional and Predicate Logic Program.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages.
CS 331, Principles of Programming Languages Chapter 2.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
CS 363 Comparative Programming Languages Semantics.
3.2 Semantics. 2 Semantics Attribute Grammars The Meanings of Programs: Semantics Sebesta Chapter 3.
ISBN Chapter 3 Describing Semantics.
Chapter 3 Part II Describing Syntax and Semantics.
Programming Languages and Design Lecture 3 Semantic Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
Semantics In Text: Chapter 3.
Syntax and Semantics CIS 331 Syntax: the form or structure of the expressions, statements, and program units. Semantics: the meaning of the expressions,
Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.
CS 127 Introduction to Computer Science. What is a computer?  “A machine that stores and manipulates information under the control of a changeable program”
1 / 48 Formal a Language Theory and Describing Semantics Principles of Programming Languages 4.
CS 331, Principles of Programming Languages Chapter 2.
Semantics (1).
Cs7100 (Prasad)L2SpecIntro1 Motivation for Language Specification.
Programming Language Descriptions. What drives PL Development? Computers are “in charge” of extremely important issues Execute a program literally. Exercise.
1-1 1 Introduction  Programming linguistics: concepts and paradigms syntax, semantics, and pragmatics language processors.  Historical development of.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
C HAPTER 3 Describing Syntax and Semantics. D YNAMIC S EMANTICS Describing syntax is relatively simple There is no single widely acceptable notation or.
Chapter 1: Preliminaries Lecture # 2. Chapter 1: Preliminaries Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation.
Semantics(1). 2 Symantec(1)  To provide an authoritative definition of the meaning of all language constructs for: 1.Programmers 2.Compiler writers 3.Standards.
Functional Programming
Chapter 3 – Describing Syntax
Describing Syntax and Semantics
Introduction to Formal Methods
Why study programming languages?
PROGRAMMING LANGUAGES
CSCI-235 Micro-Computer Applications
GC211Data Structure Lecture2 Sara Alhajjam.
Computer System and Programming
Syntax Questions 6. Define a left recursive grammar rule.
Programming Languages 2nd edition Tucker and Noonan
Ada – 1983 History’s largest design effort
Chapter 1 Preliminary. Chapter 1 Preliminary 1.1 Reasons for Studying Concepts of Programming Languages Increased capacity to express ideas Improved.
Denotational Semantics (Denotational Semantics)
Generic Language Technology (2IS15) Dynamic Semantics
Semantics In Text: Chapter 3.
Introduction To software engineering
Conference on the History of Programming Languages III
Chapter 3 Describing Syntax and Semantics.
Describing Syntax and Semantics
Motivation for Language Specification
Lesson 3.3 Writing functions.
Presentation transcript:

Motivation for Language Specification cs884 (Prasad) spec0intro

Languages Natural Languages Artificial Languages Logic Languages (descriptive) Logic Languages Programming Languages (prescriptive) Aspects Syntax Semantics Pragmatics cs884 (Prasad) spec0intro

Motivation for Specifying Semantics of Programming Languages The language of mathematics is precise, well-understood, and standard. In contrast, the PL notations are diverse and similar looking syntax have been given different meaning. So it is important to specify unambiguously what a system of notation stands for. cs884 (Prasad) spec0intro

Semantics seeks profound definitions rather than difficult theorems. Software Design Use Divide and Conquer; Team effort. Language Design Unify and study interactions among language features. Individual effort common. Pascal, Modula-2, Oberon - Niklaus Wirth C - Dennis Ritchie C++ - Bjarne Stroustrup Java - James Gosling C# - Anders Hejlsberg cs884 (Prasad) spec0intro

Formal Proofs Proofs QED! Hand-waving x + x + … + x = x * x d/dx ( x + x + … + x) = d/dx (x * x) x = 2 * x 1 = 2 QED! x times cs884 (Prasad) spec0intro

(cont’d) Rigorous Informal 1 + 3 + … + (2i - 1) = i * i Formal : Using Mathematical Induction 1 1 3 3 1 3 5 ... 5 5 5 5 cs884 (Prasad) spec0intro

(cont’d) Formal proofs are those formulated in the syntax of a particular logic using its axioms and rules of inference. E.g., Rigorous but informal proofs in Abstract Algebra can be converted into formal proofs in first-order logic. FORMAL Reduce to symbol manipulation. cs884 (Prasad) spec0intro

Problems with Informal Specifications Some Historically Significant Examples of Ambiguity/Incompleteness cs884 (Prasad) spec0intro

Algol Example Algol-60 report is ambiguous since it does not specify a fixed-order of evaluation for sub-expressions, or rule out the possibility of side-effects in programs. If function f has side-effect on variable x then it is possible to have x + f(x) =/= x + f(x) f(x) + f(x) =/= 2 * f(x) f(x) / f(x) =/= 1 Loss of Referential Transparency cs884 (Prasad) spec0intro

Non-portability : gotcha.c main() { int i = 5; printf(“%d %d %d \n”, i, i/++i, i); } Intuitively?? 5 0 6 cs480(Prasad) L4javaGoals

Possible Outcomes SPARC : cc/gcc gotcha.c -ldl; a.out 6 1 6 Alpha, MIPS : cc/gcc gotcha.c; a.out 5 1 6 SUN-3 : cc gotcha.c ; a.out 6 1 5 Intuitively : 5 0 6 cs480(Prasad) L4javaGoals

Pascal Example Type Equivalence Structural Equivalence: {A,B,C,D,E} type T = array [1..10] of integer; var A,B : array [1..10] of integer; C: array [1..10] of integer; D: T ; E : T; Structural Equivalence: {A,B,C,D,E} Name Chain Equivalence: {A,B},{C},{D,E} Name Equivalence: {A},{B},{C},{D,E} cs884 (Prasad) spec0intro

Example Are the following statements equivalent? while <cond> do <statement> vs 25: if <cond> then begin <statement>; goto 25 end; These statements are equivalent in Pascal, Ada, etc. but not in C/C++/Java. cs884 (Prasad) spec0intro

printf("\t i = %d \n", i--); } #include <stdio.h> main() { int i, j, k1 = 2, k2 = 2; do { i = 2; while ( i > 0 ) { printf("\t i = %d \n", i--); } } while (k1--); printf("\n"); do { j = 2; TAG: if ( j > 0 ) { printf("\t j = %d \n", j--); goto TAG; } while (k2--); /* tcsh> gcc -ldl eq1.c tcsh> a.out i = 2 i = 1 j = 2 j = 1 */ cs884 (Prasad) spec0intro

printf("\t i = %d \n", i--); break; } #include <stdio.h> main() { int i, j, k1 = 2, k2 = 2; do { i = 2; while ( i > 0 ) { printf("\t i = %d \n", i--); break; } } while (k1--); printf("\n"); do { j = 2; TAG: if ( j > 0 ) { printf("\t j = %d \n", j--); goto TAG; } while (k2--); /* tcsh> gcc -ldl eq1.c tcsh> a.out i = 2 j = 2 */ cs884 (Prasad) spec0intro

Approaches to Formal Semantics Operational : How a program executes? Specifies abstract interpreter to carry-out the meaning of the programs. Denotational : What a program computes? Maps a program to a mathematical function from its inputs to its outputs. Axiomatic : For reasoning about programs Specifies properties of language constructs through pre-post conditions. Abstraction level: OS < DS < AS cs884 (Prasad) spec0intro

Interpreter vs Compiler Interpreter evaluates the meaning of a program. Compiler transforms a program in one language into an equivalent program in another language. That is, it preserves meaning. Semantics of a language is independent of its machine implementation. cs884 (Prasad) spec0intro

Why is formal semantics not widely used? It is relatively complex and not yet cost effective for everyday (and everybody’s) use. Semantics is general. In particular, it must consider all possible situations (including the boundary cases). However, most programmers want to know: What is the output for the particular inputs? cs884 (Prasad) spec0intro

Who needs semantics? Those who write (meta-)programs that must work for all programs. Designers of program transformation tools. compilers and interpreters. program analyzers. software engineering tools. critical software. cs884 (Prasad) spec0intro