Lecture 1: Course Introduction, Schemes and Mind Maps of Programming Languages

CS164: Programming Languages and Compilers ... Please read Chapter 2 of the online Course Notes for the next lec- tures. • Discussion sections start next ...

Typology: Schemes and Mind Maps

2022/2023

Uploaded on 05/11/2023

sheetal_101
sheetal_101 🇺🇸

4.8

(17)

234 documents

1 / 21

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lecture 1: Course Introduction
CS164: Programming Languages and Compilers
P. N. Hilfinger, 787 Soda
Fall 2020
Acknowledgement. Portions taken from CS164 notes by G. Necula.
Last modified: Wed Aug 26 22:26:55 2020 CS164: Lecture #1 1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15

Partial preview of the text

Download Lecture 1: Course Introduction and more Schemes and Mind Maps Programming Languages in PDF only on Docsity!

Lecture 1: Course Introduction

CS164: Programming Languages and Compilers P. N. Hilfinger, 787 Soda Fall 2020

Acknowledgement. Portions taken from CS164 notes by G. Necula.

Administrivia

  • All course information, readings, and documentation is online from the course web page (constantly under construction).
  • Get a cs164-xxx class account electronically using Webacct with your CalId.
  • Please do not take this course P/NP.
  • Projects generally require partnerships of 3–4. Start looking now. We will assign you to a team if you do not find one.
  • DSP students: since projects are done in teams, I cannot accommo- date requests for individual extensions on projects for disability- related reasons.
  • Please read Chapter 2 of the online Course Notes for the next lec- tures.
  • Discussion sections start next week. At the moment, you are all in a single section. There will be a sign-up poll for actual rooms/times later this week or weekend.

Generic General Advice

DBC!

RTFM!

Plagiarism: Obligatory Warning

  • We have software to detect plagiarism, and we Know How to Use It!
  • If you must use others’ work (in moderation), cite it!
  • Remember that on projects, you necessarily involve your partner.
  • Most cheating cases result from time pressure. Keep up, and talk to us as early as possible about problems.

Implementing Programming Languages

  • Strategy 1: Interpreter: program that runs programs.
  • Strategy 2: Compiler: program that translates program into machine code (interpreted by machine).
  • Strategy 3: Modern trend is hybrid: - Compilers that produce virtual machine code for bytecode inter- preters. - “Just-In-Time” (JIT) compilers interpret parts of program, com- pile other parts during execution. - Variant of 2: Compiler that translates program into another pro- gramming language (such as C), or into an intermediate language (such as Java class format) for which there is a translator or compiler.

Languages

  • Initially, programs “hard-wired” or entered electro-mechanically - Analytical Engine, Jacquard Loom, ENIAC, punched-card-handling machines
  • Next, stored-program machines: programs encoded as numbers (ma- chine language) and stored as data: - Manchester Mark I, EDSAC.
  • 1953: IBM develops the 701; all programming done in assembly
  • Problem: Software costs > hardware costs!
  • John Backus: “Speedcoding” made a 701 appear to have floating point and index registers. Interpreter ran 10–20 times slower than native code.

After FORTRAN

  • Lisp, late 1950s: dynamic, symbolic data structures.
  • Algol 60: Europe’s answer to FORTRAN: modern syntax, block struc- ture, explicit declaration. - Dijkstra: “A marked improvement on its successors.” - Algol report Set standard for language description.
  • COBOL: late 1950’s (and still with us). Business-oriented. Intro- duces records (structs).

The Language Explosion

  • APL (arrays), SNOBOL (strings), FORMAC (formulae), and many more.
  • 1967-68: Simula 67, first "object-oriented" language.
  • Algol 68: Combines FORTRANish numerical constructs, COBOLish records, pointers, all described in rigorous formalism. Remnants remain in C, but Algol68 itself did not catch on.
  • 1968: "Software Crisis" announced. Trend towards simpler lan- guages: Algol W, Pascal, C

Into the Present

  • Complexity increases with C++.
  • Then decreases with Java.
  • Then increases again (C#, Java 1.5 et seq.).
  • Proliferation of little or specialized languages and scripting languages: HTML, PHP, Perl, Python, Ruby,....

Example: FORTRAN

C FORTRAN (OLD-STYLE) SORTING ROUTINE C SUBROUTINE SORT (A, N) DIMENSION A(N) IF (N - 1) 40, 40, 10 10 DO 30 I = 2, N L = I- X = A(I) DO 20 J = 1, L K = I - J IF (X - A(K)) 60, 50, 50 C FOUND INSERTION POINT: X >= A(K) 50 A(K+1) = X GO TO 30 C ELSE, MOVE ELEMENT UP 60 A(K+1) = A(K) 20 CONTINUE A(1) = X 30 CONTINUE 40 RETURN END

C ----------------------------------

C MAIN PROGRAM DIMENSION Q(500) 100 FORMAT(I5/(6F10.5)) 200 FORMAT(6F12.5)

READ(5, 100) N, (Q(J), J = 1, N) CALL SORT(Q, N) WRITE(6, 200) (Q(J), J = 1, N) STOP END

Example: APL

∩◦ An APL sorting program

∇ Z ← SORT A

Z ← A [△| A ]

Example: Python (2.5)

import sys, re

def format(x):

return "%10.5f" % x

vals = map(float, re.split(r’\s+’, sys.stdin.read().strip()))

vals.sort()

print ’\n’.join([ ’’.join(map(format, vals[i:i+6]))

for i in xrange(0,len(vals),6)])

Problems to Address

  • How to describe language clearly for programmers, precisely for implementors?
  • How to implement description, and know you’re right? - Answer: Automatic conversion of description to implementation
  • How to test?
  • How to save implementation effort? - With multiple languages to multiple targets: can we re-use effort?
  • How to make languages usable? - Handle errors reasonably - Detect questionable constructs - Compile quickly

Classical Compiler Structure (Front)

A

Lexical Analysis Parsing

/* Example */ salary = base + rate[years]; output(salary);

Optimized Tree

Intermediate, Virtual−Machine

Static Semantics Optimization^ Code Generation

Push_Addr # Push_Addr # Index Add

Push #

Source Program

Token Stream

Abstract

() ID#5 ID#

= ID#

;

ID#2 [] ID#3 ID#

<ID#1, ’=’, ID#2, ’+’, ID#3, ’[’, ID#4, ’]’, ’;’, ID#5, ’(’, ID#1, ’)’, ’;’, ...>

ID#2 [] ID#3 ID#

(double) (double) (int) (double[])

(double)

Optimization

Syntax Tree (AST)

AST

Attributed

(VM) Code