UA CS 520 - Criteria for Language Design

Unformatted text preview:

C SC 520 Principles of Programming LanguagesPrinciples of ProgrammingLanguagesLecture 02Criteria for Language Design↓ cut ↓ ↓ cut ↓hhhhhhh hhhhhhh1/7/106AT&TFOIL 1| |+ +Criteria for Language Design1. Simplicity— mnemonic— clear easily mastered semantics— as few basic concepts as possible— feature/concepts limited enough to master entirelanguage (discourages "dialecting")— effects of feature combinations easily predictable— simple rules of combinationex:(1) PL/I: default coercion rules among fixed bin,fixed dec, float bin, float dec, whenmodified by scale attributes, become very complex.Each rule is reasonable by itself—the combinationyields strange results.+ +| |hhhhhhh hhhhhhh1/7/106AT&TFOIL 2| |+ +dcl M fixed dec(10,5), N fixed bin(5,4);N=0;M=N+.1;expr attr. repn. val..1 dec(1,1) 0.1 (dec) 1/10N+.1 bin(5,4) 0.0001|100110011 .. 1/16(binary conversion, then truncation)M dec(10,5) 00000.06250 (dec) 1/16(2) ALGOL 60:—own static—array dynamic size (known at block entry)ex: own boolean array B[M:N];—created on first entry to block— retained between entries to block (with values at block exit)— seemingly could vary in size— conflicts with stack implementation— meaning?+ +| |hhhhhhh hhhhhhh1/7/106AT&TFOIL 3| |+ +(3) PASCAL: fairly simple(4) ADA:Entia non sint multiplicanda praeter necessitatem—William of Ockham—procedure calls: keyword or positional foractual/formal correspondence— but positional parameters must occur first, and oncea keyword is used, rest of the call must usekeyword parmsREORDER_KEYS(NUM_OF_ITEMS,KEY_ARRAY :=: RESULT_TABLE);+ +| |hhhhhhh hhhhhhh1/7/106AT&TFOIL 4| |+ +2. Well-defined Syntactic/Semantic Descriptiongsyntax — not a problem to specify once designedgsemantics — big problem; still often informal— ALGOL 68 Report (1968)—Revised Report on ALGOL 68 (1975)— Informal Introduction to ALGOL 68, Lindsey &Van der Meulen (1977)gChapter 0: Very Informal Introduction to ALGOL68gTechniques—Interpretive (operational): PL/I (VDL, Wegner,1972)—Axiomatic: PASCAL (Hoare-Wirth, 1971)— Denotational: Scheme (Steele & Sussman, 1978)+ +| |hhhhhhh hhhhhhh1/7/106AT&TFOIL 5| |+ +ex:(1) ALGOL 60: Lack of complete syntax and semantics(especially I/O) harmed adoption(2) PASCAL: forward left out of grammar; demandsdefinition before use but makes exceptions forrecursive types(3) PASCAL: When are types equivalent? The Report isambiguoustypet = array[1..100] of real;var a, b:array[1..100] of real;c:array[1..2] of t;d:array[1..2] of array[1..100] of real;e:t;f:array[1..100] of real;g:t;— structural equivalence: equivalent if have sametype structureg{a, b, e, f , g} : array[1..100] of real;g{c, d} : array[1..2] of array[1..100] ofreal;+ +| |hhhhhhh hhhhhhh1/7/106AT&TFOIL 6| |+ +— declaration equivalence: variables type compatible⇔ have same type name (built-in or user-defined)or appear in the same declaration (ex: PASCAL)g{a, b} (same declaration)g{f } (distinct declaration)g{e, g} (both of type t)g{c}, {d} (distinct declaration)— name equivalence: variables type compatible ⇔have same type name (built-in or user-defined) (ex:ADA)gonly {e, g} (both of type t)gall others inequivalent(4) DO loops in early FORTRAN: is the index valueavailable after transfer out?+ +| |hhhhhhh hhhhhhh1/7/106AT&TFOIL 7| |+ +(5) ALGOL 60: Semantics of assignmentsFrom the Algol 60 Report:‘‘4.2.3. Semantics [of assignment statement]Assignment statements serve for assigning the value ofan expression to one or several variables ... Theprocess will in the general case be understood to takeplace in three steps as follows:4.2.3.1. Any subscript expressions occurring in the leftpart variables are evaluated in sequence from left toright.4.2.3.2. The expression of the statement is evaluated.4.2.3.3. The value of the expression is assigned to allthe left part variables, with any subscript expressionshaving values as evaluated in step 4.2.3.1.’’begin integer a;integer procedure f(x, y); value y,x; integer y,x;a:=f:=x+1;integer procedure g(x); integer x;x:=g:=a+2;a := 0; outreal(1, a + (f(a,g(a)) / g(a)) )endMany possible evaluations of: a + ( f(a,g(a)) /g(a) )+ +| |C SC 520 Principles of Programming Languagesa + ( f(a,g(a)) / g(a) )+a/fgagaaag(x) by name:x:=g:=a+2f(x,y) by value:a:=f:=x+1main:a:=0;print exprC SC 520 Principles of Programming Languages(a) Eval denom. 1st, then numer. L-R+a/fggaaag(x) by name:x:=g:=a+2f(x,y) by value:a:=f:=x+1main:a:=0;print exprg:=2a:=2a=2a=2g:=4a:=4f:=3a:=3a=3a012375648312234+=32fg=a=0C SC 520 Principles of Programming Languages(b) Eval standard topological sort (L-R)+a/fggaaag(x) by name:x:=g:=a+2f(x,y) by value:a:=f:=x+1main:a:=0;print exprg:=3a:=3a=0a=0g:=2a:=2f:=1a:=1a=0a56120473811330 +=13fg=a=1(c) Other possible results (11 total)3354 3 1 3 1 15223 5 3 5 2 233537C SC 520 Principles of Programming LanguagesAnother Example:• Bad:• Algol examples from D.E. Knuth, ``The Remaining Trouble Spots in ALGOL 60’’, CACM 1967.A[ a + B[f(a)] + g(a) ] := C[a] := 0;hhhhhhh hhhhhhh1/7/106AT&TFOIL 12| |+ +(6) C, C++: Semantics of expressions & assignmentsa = f(i); a += g(i);a = f(i) + g(i);NOT equivalent. Result of one is known; result of theother is unknown.(7) C++: There are 6 different kinds of scope:— block (local) scope: names declared in a block &formal parameters defined in any enclosedblock/function (except if redeclared)—function scope: labels defined throughout functionin which declared—function prototype scope: names in the parameterlist extend to the end of prototype definition—file (global) scope: name declared outside allblocks/classes is defined throughout the translationunit+ +| |hhhhhhh hhhhhhh1/7/106AT&TFOIL 13| |+ +— class scope: class member name n is local to itsclass C and can be used only(1) as n in another member function of class C(2) as c.n where c is an object of class C (or aderived class of C)(3) as pc->n where pc is a pointer to an object ofclass C (or a derived class of C)(4) as X::n (scope resolution operator) where X isC (or a derived class of C)— namespace scope: names defined only inside thenamespace (a named collection of classes) orofoutside using scope resolution operator ::(namespaces support multivendor libraries withpotential name conflicts)namespace std {#include <iostream.h>#include <math.h>}namespace SOFTinc {class stack ( ... };class queue { ... };}// here use std::<<using namespace std;// here use << for std::<<using namespace SOFTinc;// here use stack for


View Full Document

UA CS 520 - Criteria for Language Design

Download Criteria for Language Design
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Criteria for Language Design and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Criteria for Language Design 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?