Upload
judah-mendez
View
28
Download
0
Embed Size (px)
DESCRIPTION
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 - PowerPoint PPT Presentation
Citation preview
Programming Language Descriptions
PL-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
cs784
PL-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
cs784
PL-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
cs784
PL-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
cs784
PL-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
cs784
PL-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.
cs784
PL-Descriptions 8
Scope of break statement
#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--);}
cs784
PL-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}
cs784
PL-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.
cs784
PL-Descriptions 11cs784 (Prasad) L2SpecIntro 11
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
PL-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 cs784
PL-Descriptions 13cs784 (Prasad) L2SpecIntro 13
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
PL-Descriptions 14
Language
Syntax(BNF) Semantics Pragmatics
Data Control
Abstract Data Types
Denotational Axiomatic Operational
(interpreter-based)
Attribute Grammar Framework
CS784 Agenda
cs784