1 / 17

Motivation for Language Specification

Motivation for Language Specification. Languages. Natural Languages. Artificial Languages. (descriptive). (prescriptive). Logic Languages. Programming Languages. Aspects. Syntax. Semantics. Pragmatics. Motivation for Specifying Natural Languages.

ita
Download Presentation

Motivation for Language Specification

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Motivation for Language Specification L2SpecIntro

  2. Languages Natural Languages Artificial Languages (descriptive) (prescriptive) Logic Languages Programming Languages Aspects Syntax Semantics Pragmatics L2SpecIntro

  3. Motivation for SpecifyingNatural Languages A lexicographer's business is solely to collect, arrange, and define the words that usage presents to his hands. He has no right to proscribe words; he is to present them as they are. -Noah Webster, lexicographer (1758-1843)  L2SpecIntro

  4. 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. L2SpecIntro

  5. Semantics seeks profound definitions rather than difficult theorems. • Software Design • Use Divide and Conquer. Team effort common. • 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 • Scheme – Guy Steele, Python – Guido von Rossum • Scala – Martin Oderksy, Clojure– Rich Hickey L2SpecIntro

  6. Problems with Informal Specifications Some Historically Significant Examples of Ambiguity/Incompleteness L2SpecIntro

  7. 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 fhas side-effect on variable xthen 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 L2SpecIntro

  8. 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} L2SpecIntro

  9. Semantic Equivalence Example Are the following statement templates equivalent? while <cond> do <statement> vs 25: if <cond> then begin <statement>; goto 25 end; L2SpecIntro

  10. #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--); } L2SpecIntro

  11. #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--); break; goto TAG; } } while (k2--); } L2SpecIntro

  12. Cause of ‘The 1990 AT&T Long Distance Network Collapse’ • The defect was a C program that featured a break statement located within an if-then-else statement, that was nested within a switch statement. • Instead of the control breaking out of the else clause, it also broke out of the surrounding switch. L2SpecIntro

  13. 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 L2SpecIntro

  14. 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. L2SpecIntro

  15. 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? L2SpecIntro

  16. 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. L2SpecIntro

  17. CS7100 Agenda Language Syntax(BNF) Semantics Pragmatics Data Control Abstract Data Types Denotational AxiomaticOperational (interpreter-based) Attribute Grammar Framework L2SpecIntro

More Related