<<

an abstract entity with some specification, including: • formal specification of tokens, i.e., legal keywords & identifiers CSC324 — Putting the Pieces together • tool: Regular Grammars. ⇒ formal specification of acceptable sentences, or syntax Afsaneh Fazly • tool: Context Free Grammars. ⇒ (mainly informal) specification of meaning, or semantics. • Winter, 2013

1 2

Programming Language The Birth of Programming Languages (PLs)

not to be confused with an IDE/compiler, that are pieces of Prior to the 1950s • implementing the language (performing translation): programs had to be written in machine code, using absolute lexical analysis: identifying tokens. • • addressing. tool: Finite State Machines. ⇒ programs were hard to read and write, and the job didn’t syntactic analysis: combining tokens into larger untis (e.g., • • attract many people. statements, expressions). software started to cost way more than the hardware. tool: Parsing Algorithms. • ⇒ semantic analysis. • birth of assembly languages, optimization and code generation. ⇒ • with little impact on the design of high-level langauges.

3 4 The Birth of High-Level PLs History of Programming Languages

Mid 1950s, 1960s Late 1970s announcement of the IBM 704 machine, with indexing and shift from procedure-oriented PL designs to data-oriented • floating-point instructions in hardware • designs first language with limited support for data abstraction: birth of the first high-level PL: Fortran. • • 67, designed by Ole-Johan Dahl and language was actually implemented (compiler); (Norwegian Computing Centre, Oslo). variables, user-defined subprograms, limited control structures; no recursion, no dynamic data structures.

growing interest in Artificial Intelligence (AI), from linguistics, • psychology, and mathematics Ole-Johan Dahl (left) birth of the first functional PL: LISP. & Kristan Nygaard (right) • parent of Scheme, ML, Haskell.

5 6

History of Programming Languages Other Interesting/Influential PLs

Early 1980s Algol (ALGOrithmic Language): giving birth to object-oriented (OO) design designed as a universal language for scientific computing • • first language developing OO concepts: , designed by hasn’t been used much, but had a great impact on many • • Adele Goldberg, & colleagues (Learning Research modern languages Group, PARC). COBOL (COmmon Business Language): designed for business applications, with sophisticated data • Adele Goldberg structures has been used more than any other PL, but no impact on the • design of other PLs support for OO programming is now part of most imperative, • and even functional/logic PLs: C++/C# (imperative), F# (functional), Prolog++ (logic) •

7 8 Other Interesting/Influential PLs RDBMS and Logic Programming

SQL (Structured Query Language): Any connection between Relational Database Management designed for managing and querying Relational Databases, System, and logic programming? • that store data in the form of tables non-procedural (as in logic programming) • user describes what they want (not how to retrieve them from e.g., database as a series of predicates/facts in Prolog, • • the database) relations among entities expressed through rules, and the retrieval through the search process. Example: SELECT price, duration Pros & cons of using logic programming to implement RDBMS? FROM flights conventional RDBMS only look-up information, whereas logic • WHERE flights.origin = ’toronto’ programming can do inference AND flights.destination = ’paris’ logic programming (inference engine) is often slow AND price < 1000.00 • ORDER BY price;

9 10

Imperative Design Imperative Design Human Language & Mind Human Language & Mind

Assembly Languages [before the 1950s]

⇑ Machine Hardware and Instruction Set Machine Hardware and Instruction Set

11 12 Imperative Design Imperative Design Human Language & Mind Human Language & Mind

data-oriented / object-oriented PLs [1970s, 1980s]

⇑ High-level PL with limited functionality [1950s, 1960s] High-level PL with limited functionality [1950s, 1960s]

⇑ ⇑ Assembly Languages [before the 1950s] Assembly Languages [before the 1950s]

⇑ ⇑ Machine Hardware and Instruction Set Machine Hardware and Instruction Set

13 14

Influences on PL Design Imperative Design Human Language & Mind Imperative Paradigm: computer architecture (and instruction set). ⇓⇓ • functional PLs [1950s, 1960s] logic PLs [1970s] hardware and software costs. • application. • mainly bottom-up, ⇒ closer to the needs of the machine/application. data-oriented / object-oriented PLs [1970s, 1980s] ⇒ ⇑ Question: How about functional and logic paradigms? High-level PL with limited functionality [1950s, 1960s]

⇑ Assembly Languages [before the 1950s]

⇑ Machine Hardware and Instruction Set

15 16 Scheme Scheme clear and simple syntax • Data types: numbers, symbols, pairs, lists, ... clear and simple semantics (for the core): λ-calculus • uniform treatment of program and data Syntax: • implementations properly tail-recursive ::= • | (if ) functions are values: created dynamically, stored, passed as • | (cond {( )} [(else )]) parameters, returned as results, etc. | (lambda ({}) ) static scoping | ... • ::= (define ) dynamic typing ... • pass-by-value • Example: Anything in particular you liked/disliked about Scheme? > (define max (lambda (x y) (if (> x y) x y))) > (max 3 4)

17 18

ML ML

Datatypes: unit, bool, int, real, string, tuples, lists, ... functional: recursion, higher-order functions • type safe, static type checking, type inference Syntax, Example: • built-in types, type synonyms • fun mystery lst = user-defined (abstract) data types • let enumerated, variant, recursive, mutually recursive types fun mysteryHelper [] res = res • exception handling | mysteryHelper (x::xs) res = • mysteryHelper xs (x::res) static scoping (dynamic scoping for exception handling) • in garbage collection, immutable data types, updatable mysteryHelper lst [] • references end;

mystery : ’a list -> ’a list Anything you liked/disliked about ML in particular? What does mystery do?

19 20 Prolog Deficiencies of Prolog as a Pure Logic PL Syntax: Prolog matching is ordered: from top of the database, and ::= . • | :- { , } . from left end of a goal. ::= ( { , } ) Prolog allows explicit control of backtracking through the use • ::= ( { , } ) of Cut !. | | Pros and cons of using Cut? ::= ... • Closed-world assumption, and Negation by failure. ::= ... •

Example: Anything you liked/disliked about Prolog?

mylength([],0). mylength([_|T],N) :- mylength(T,NT), N is NT+1.

21 22

Comparison: Summing a List of Numbers Comparison: Summing a List of Numbers in a C-like language: • sum = 0; Question: Do we know which one is closer to “how for (i=0; i

23 24 Natural Programming Languages and Environments References

L.A. Miller (1974). Programming by Non-, There is evidence that: • International Journal of Man–Machine Studies 6(2): 237–260. there are regularities in how people express step-by-step • L.A. Miller (1981). Natural Language Programming: Styles, natural language procedures [Miller’74, 81; Biermann et al.’83] • Strategies, and Contrasts, IBM Systems Journal 20(2): 184–215. people improve the precision of their natural language • A.W. Biermann, B.W. Ballard, and A.H. Sigmon (1983). An expressions if they know the recipient has limited intelligence • Experimental Study of Natural Language Programming, suggesting that such regularities can be incorporated into PL International Journal of Man–Machine Studies 18(1): 71–87. designs. J.E. Pane and B.A. Myers (2006). More Natural Programming • Languages and Environments,HenryLiebermanetal.(eds),End Despite such findings, these studies have had little impact on the User Development: 31–50. design of new PLs. Why? R.W. Sebesta, Concepts of Programming Languages, • Addison-Wesley, 10th ed., 2012.

25 26

Thank you for listening!

Good luck with your future career.

27