Motivation for Language Specification - PowerPoint PPT Presentation

About This Presentation
Title:

Motivation for Language Specification

Description:

In contrast, the PL notations are diverse and similar looking ... Java - James Gosling. C# - Anders Hejlsberg. cs884 (Prasad) spec0intro. 5. Formal Proofs ... – PowerPoint PPT presentation

Number of Views:57
Avg rating:3.0/5.0
Slides: 20
Provided by: TKPr6
Learn more at: http://cecs.wright.edu
Category:

less

Transcript and Presenter's Notes

Title: Motivation for Language Specification


1
Motivation for Language Specification
2
Languages
Natural Languages
Artificial Languages
(descriptive)
Logic Languages
Programming Languages
(prescriptive)
Aspects
Syntax
Semantics
Pragmatics
3
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.

4
  • 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

5
Formal Proofs
  • Proofs
  • Hand-waving
  • x x x x x
  • d/dx ( x x x) d/dx (x x)
  • x 2 x
  • 1 2


  • QED!

x times
6
(contd)
  • Rigorous
  • Informal
  • 1 3 (2i - 1) i i
  • Formal Using Mathematical Induction

1
5
3
...
5
5
5
5
7
(contd)
  • 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.

8
Problems with Informal Specifications
  • Some Historically Significant Examples of
    Ambiguity/Incompleteness

9
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

10
Non-portability gotcha.c
  • main()
  • int i 5
  • printf(d d d \n,
  • i, i/i, i)
  • Intuitively??
  • 5 0 6

11
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

12
Pascal Example
  • Type Equivalence
  • 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

13
Example
  • Are the following statements equivalent?
  • while ltcondgt do ltstatementgt
  • vs
  • 25 if ltcondgt then
  • begin ltstatementgt
  • goto 25
  • end

14
  • include ltstdio.hgt
  • main()
  • int i, j, k1 2, k2 2
  • do i 2
  • while ( i gt 0 )
  • printf("\t i d \n", i--)
  • while (k1--) printf("\n")
  • do j 2
  • TAG
  • if ( j gt 0 )
  • printf("\t j d \n", j--)
  • goto TAG
  • while (k2--)

15
  • include ltstdio.hgt
  • main()
  • int i, j, k1 2, k2 2
  • do i 2
  • while ( i gt 0 )
  • printf("\t i d \n", i--)
  • break
  • while (k1--) printf("\n")
  • do j 2
  • TAG
  • if ( j gt 0 )
  • printf("\t j d \n", j--)
  • break
  • goto TAG
  • while (k2--)

16
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 lt DS lt AS

17
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.

18
Why is formal semantics not widely used?
  • It is relatively complex and not yet cost
    effective for everyday (and everybodys) 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?

19
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.
Write a Comment
User Comments (0)
About PowerShow.com