1 / 14

Programming Language Descriptions

Programming Language Descriptions. What drives PL Development?. Computers are “in charge” of extremely important issues Execute a program literally. Exercise no “judgment”. Program development “works” : not too hard “works correctly”: beyond the state of the art

Download Presentation

Programming Language Descriptions

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. Programming Language Descriptions

  2. PL-Descriptions What drives PL Development? • Computers are “in charge” of extremely important issues • Execute a program literally. • Exercise no “judgment”. • Program development • “works” : not too hard • “works correctly”: beyond the state of the art • Errors are due to inadequate command over the • programming domain • programming language • A PL design should • Make programs efficient • Make programmers more productive • Help catch typical errors • High level operations • PL easy to understand

  3. PL-Descriptions Division of PL Descriptions • Syntax • Context Free Grammars • Context Sensitive Details • Semantics • PL designer typically uses prose. • Others would have developed • Operational Semantics • Axiomatic Semantics • Denotational • Pragmatics • Various practical details • Prose

  4. Description of Syntax: BNF Backus-Naur-Form Context-Free only LHS ::= seq of Terminals/Non-Terminals ::= separates LHS from RHS Repetition/Kleene Star { … }* Many variations of BNF PL-Descriptions

  5. PL-Descriptions Description of Semantics • What does a program “mean”? • Mostly via carefully written prose. • Semantics of a language is (ought to be) independent of its machine implementation. • Subtleties abound

  6. PL-Descriptions Side Effects • If function f has side-effect on variable x then it is possible to have • x + f(x) =/= f(x) + x • f(x) + f(x) =/= 2 * f(x) • f(x) / f(x) =/= 1, even assuming f(x) != 0 • Loss of Referential Transparency

  7. PL-Descriptions Subtle variations in semantics • Are the following equivalent? • (Ignore PL specific syntactic details.) • while B do S • S stands for a statement sequence • 25: if B then begin S; goto 25 end • Equivalent in Pascal, Ada, etc., but not in C/C++/Java.

  8. PL-Descriptions Scope of break statement #include <stdio.h> main() { inti, 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--); }

  9. PL-Descriptions Type Equivalence • type T = array [1..10] of integer; • var A,B : array [1..10] of integer; • C: array [1..10] of integer; • D, E: T; • Structural Equivalence: {A,B,C,D,E} • Name Chain Equivalence: {A,B},{C},{D,E} • Name Equivalence: {A},{B},{C},{D,E}

  10. PL-Descriptions Interpreter vs Compiler • Interpreter evaluates the representation of a program. • Compiler transforms a program representation in one language into an “equivalent” program in another language.

  11. PL-Descriptions Why is formal semantics not widely used? • Real PLs are too complex. • 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). • But steady progress is being made ... cs784 (Prasad) L2SpecIntro 11

  12. PL-Descriptions 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

  13. PL-Descriptions 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. cs784 (Prasad) L2SpecIntro 13

  14. PL-Descriptions CS784 Agenda Language Syntax(BNF) Semantics Pragmatics Data Control Abstract Data Types Denotational AxiomaticOperational (interpreter-based) Attribute Grammar Framework

More Related