| | Analysis | Requirements & Principles |
architecture: Paradigms |
substance: Abstractions |
structure: Domains | building blocks: Features |
surface: Syntactics | Defining PLs |
Language List | |||||||
| foundational | safety |
flexibilized
| ||||||||||||||
Quick links to the syntactic definition of some languages (some PL grammars): Ada95, Java, Haskell, SML. Modula2.
TODO: Main directions of programm representation:
Concrete syntax:
| statements | expressions (+/- side-effects) | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| As a flow chart (1946/47)
Sorry for this crude character graphic |
true
.---> [a]---v
---> <p> +--->
`---> [b]---^
false
| ||||||||||||||
| In Lisp (1958) | (if (p) (a) (b))
| In Algol-60 (1960)
| if p then a else b
| In BCPL (end of 1960s) [ref]
| test p then a else b
| if p then a (in certain cases then may be omitted) p-> a, b
| In C (1971/2/3)
| if(p) a else b
| p? a : b
| In ML (1978)
|
| if p then a else b
| In Smalltalk80 (1980)
| (p) ifTrue: a; ifFalse: b
| |
Concrete syntax:
| notation | schema | examples | occurance | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Function style: | F(A1, ..., An) | pow(2,3) | mathematics, Algol-family | ||||||||||||||||||||||||||||
| Cambridge Polish [Scott] | F A1 ... An | (pow 2 3), (+ x y), (set! x y) | lambda-calculus, Lisp (always surrounded by parantheses), ML, Haskell | ||||||||||||||||||||||||||||
| f A1
| -x, ¬true, ++x
| mathematics, logic, Algol-family |
Postfix (unary post-A1) | A1 f
| x!, x^ (pointer dereferencing), x++
| mathematics, Pascal, C-family |
Infix (binary post-A1) | A1 f A2
| in Ada syntactic sugar for function-style "f"(A1,A2) in C++ syntactic sugar for operatorf(A1,A2) or for A1.operatorf(A2) x + y, x < y, x & y, x mod y, x->y, (x := y - "application" of "update-operator"?)
| mathematics, logic, Algol-family |
Selection style | A1.f(A2, ..., An)
| x.add(y)
| Simula-family (Eiffel, C++, Java, ...)
|
Mixfix styles: | preposition style | myBox displayOn: myScreen at: 100@50
| HouseholdFinances spend: 12+20 on: 'food' ages at: 'Brett' put: 3 Smalltalk's keyword messages
| conjunction style | if x then y else z
| Algol, ML, Haskell
| circumfix (unary) | |x| | mathematics
| A2-circumfix (binary) | x[y] | Algol-family
| A2-circumfix (ternary) | x ? y : z | C-family (C, C++, Java)
| |
Precedence levels (and associativity) regulate how to parse nested expressions cotaining infix, and/or pre- and postfix operators. Infix operators have associated predicende levels and associativity (left/right) to implicitly structure complex expressions. The design question is whether at all and how many different (classes of) operators there should be in the language.
| Fortran | C | Ada | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| arithmetic | ** | post++, --, | ** abs not | ||||||||||||
| pre++, --, unary+, -, &, * (ref/deref), !, ~ (logical/bitwise not) | |||||||||||||||
| *, / | *, /, % | *, /, mod, rem | |||||||||||||
| unary+, - | |||||||||||||||
| +, - | +, - | +, -, & (concatentation) | |||||||||||||
| <<, >> (shift) | |||||||||||||||
| relational | .eq., .ne., .lt., .le., .gt., .ge. | >, >=, <, <= | =, /=, <, <=, >, >= | ||||||||||||
| ==, != | |||||||||||||||
| bitwise | & | ||||||||||||||
| ^ | |||||||||||||||
| | | |||||||||||||||
| logical | .not. | && | and, or, xor [or has 'and' higher prec?]| .and. | .or. | || | .eqv., .neqv. | conditional | | ?: | | asssignment | (?) | =, +=, /=, <<=, &=, ... | (?)
| |
| Argument on the design of Pascal's levels |
| «In the interest of simplicity and efficient translatability, Pascal aimed at a reasonably small number of operator precedence levels. Algol 60's hierarchy of 9 levels seemed clearly too baroque. An additional incentive for change was the replacement of the equivalence operator for Boolean expressions ["=" with three line] by the equality operator [normal "="]. Since these two operators reside on different priority levels in Algol 60, some departure from the old rules were mandatory. In retrospect, however, the decision seems ill-advised, particularly with the growing significance of complicated Boolean expressions in connection with program verification.» [Niklaus Wirth: An Assessment of the P.L Pascal; SE 1(2) 1975] |
| Variation | Argument |
| "{...}" vs. keywords | "{...}" is easier to learn, whereas "if...endif", "do...od", "function f...end f;" etc allows better error detection [Anatomy, 59ff]. Also "{...}" is easier to spot on skimming than names (visual); bracketing check support by text-editors more likely than with keywords [IMHO]. |
| Assignments: | Meaning | Form |
| Definitions: | Meaning | Form |
| line terminated | bracketed | nesting | |||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| In Lisp (1958) and assembly | ; comment
| In Algol-60 (1960)
|
| comment comment ;
| ?
| In Basic (1965)
| rem comment
| In Prolog (1972)
| % comment
| /* comment */
| ?
| In BCPL (end of 1960s) [ref]
| // comment
| || comment \\ comment /* comment */
| |* comment *| \* comment *\ no nesting of equals (as in Pascal)
| In C (1971/2/3),
| line-comment since ISO-C, taken from C++ // comment
| /* comment */
| first closes all: | /* ... /* ... /* ... ... */ In Pascal (1972)
|
| (* comment *) | { comment } no nesting of equals: | (* ... { ... } ... *) { ... (* ... *) ... } In ML/SML (1978/83?)
| -- comment
| (* comment *)
| ?
| In Smalltalk80 (1980) (and earlier versions?)
|
| "comment"
| ?
| In Haskell
| -- comment
| {- comment -}
| ?
| |
| Variation | Argument |
| line terminated vs. bracketed | line terminated comments are less error-prone than bracketed comments [Anatomy, 62ff] |
Much more could be said here ...
Syntactic sugars are surface structure constructs which can be macro-expressed by other constructs of the language (they are not orthogonal to the rest of the language).
| Sugar | Description | Argument | ||||||
| a<b<=c and similar combinations | equivalent to a<b & b<=c
e.g. in BCPL or Icon | conciseness, common usage | ||||||
point free notation:
function f = g
in the context of, e.g., function g(x) = 2*x
| stands for
function f(x) = g(x)
conciseness
| different loop constructs in the same language
| ...
| the trend seem in PL design to reduce the variation in loop constructs
| message cascading | as in Smalltalk-80 Sends a cascade of messages to the same object:
| OrderedCollection new add:1; add:2; add:3
Instead of
|
| | Analysis | Requirements & Principles | Paradigms | Abstractions | Domains | Features | foundational | safety | flexible typing | Syntactics | Defining PLs | Language List |