Download presentation
Presentation is loading. Please wait.
Published byJulie Carter Modified over 9 years ago
1
Programming Language Descriptions
2
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 cs7842PL-Descriptions
3
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 cs7843PL-Descriptions
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 cs7844PL-Descriptions
5
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 cs7845PL-Descriptions
6
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 cs7846PL-Descriptions
7
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. cs7847PL-Descriptions
8
Scope of break statement #include 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--); } cs7848PL-Descriptions
9
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} cs7849PL-Descriptions
10
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. cs78410PL-Descriptions
11
cs784 (Prasad)L2SpecIntro11 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... cs78411PL-Descriptions
12
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 cs78412PL-Descriptions
13
cs784 (Prasad)L2SpecIntro13 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. cs78413PL-Descriptions
14
Language Syntax(BNF) Semantics Pragmatics Data Control Abstract Data Types Denotational Axiomatic Operational (interpreter-based) Attribute Grammar Framework CS784 Agenda cs78414PL-Descriptions
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.