Top Banner
ITEC 380 Organization of programming languages Dr. Andrew Ray
25

ITEC 380 Organization of programming languages Dr. Andrew Ray.

Jan 16, 2016

Download

Documents

Jasmine Carter
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: ITEC 380 Organization of programming languages Dr. Andrew Ray.

ITEC 380

Organization of programming languages

Dr. Andrew Ray

Page 2: ITEC 380 Organization of programming languages Dr. Andrew Ray.

Introduction

Objectives

• Introductions (Me + You)• Outline of course• Why study languages? • Paradigms• How languages are understood

Page 3: ITEC 380 Organization of programming languages Dr. Andrew Ray.

Introduction

Me

• 6th year here at RU• 1st time teaching this course• Have used lessons from this type of

course to help with– Research– Teaching

Page 4: ITEC 380 Organization of programming languages Dr. Andrew Ray.

Introduction

You

• What is one topic you’d really like to learn about concerning programming languages?

• What do you want to learn in this class?

• How interested are you in this class? (1-10)

• Share with class

Page 5: ITEC 380 Organization of programming languages Dr. Andrew Ray.

Introduction

How?

• Synchronous component• Study at your leisure lectures• Self study / experimentation• Homework assignments– Intro–Major project

• Adaptability– Online forums/chat/twitter?

Page 6: ITEC 380 Organization of programming languages Dr. Andrew Ray.

Introduction

Information

• Course website– www.radford.edu/aaray/ITEC_380

• Demo

Page 7: ITEC 380 Organization of programming languages Dr. Andrew Ray.

Introduction

Outline of course

• 1-2 - Languages• 3-6 – Functional programming• 7-10 – Logical programming• 11-12 – Procedural programming• 13-14 – OO / Review

Page 8: ITEC 380 Organization of programming languages Dr. Andrew Ray.

Introduction

Paradigms

• Radically different methods of accomplishing the same task

• Procedural• Object oriented• Functional• Logical

Page 9: ITEC 380 Organization of programming languages Dr. Andrew Ray.

Introduction

Example

• Quicksort in haskell

quicksort :: Ord a => [a] -> [a] quicksort [] = [] quicksort (p:xs) = (quicksort lesser) ++ [p] ++ (quicksort greater)

where lesser = filter (< p) xs greater = filter (>= p) xs

Page 10: ITEC 380 Organization of programming languages Dr. Andrew Ray.

Introduction

Examplevoid qsort(int a[], int lo, int hi) { int h, l, p, t; if (lo < hi) { l = lo; h = hi; p = a[hi]; do { while ((l < h) && (a[l] <= p)) l = l+1; while ((h > l) && (a[h] >= p)) h = h-1; if (l < h) { t = a[l]; a[l] = a[h]; a[h] = t; } } while (l < h); a[hi] = a[l]; a[l] = p; qsort( a, lo, l-1 ); qsort( a, l+1, hi ); }}

Page 11: ITEC 380 Organization of programming languages Dr. Andrew Ray.

Introduction

Paradigms

• Right tool right job• OO is probably used for > 95% of

software development• Purpose– Performance– Reliability– Elegance– Expression

Page 12: ITEC 380 Organization of programming languages Dr. Andrew Ray.

Introduction

Choose your language

• You are familiar with OO and procedural languages

• Goal: Not a rehash of Java / Ada• Desire: Choose a different OO &

procedural language to study for the course

• Thoughts?

Page 13: ITEC 380 Organization of programming languages Dr. Andrew Ray.

Introduction

Languages

• What is the purpose of a language?• Why are there multiple languages?• What are the major components of

languages?

Page 14: ITEC 380 Organization of programming languages Dr. Andrew Ray.

Introduction

Computers

• Syntax– Did you put the exact number of ;’s in

it?

• Semantics–What does it mean?

• Goal– Tell the computer what to do

Page 15: ITEC 380 Organization of programming languages Dr. Andrew Ray.

Introduction

Implementation

• Compilation– Source, translation to binary, execution

• Interpretation– Source, intermediate program,

execution

• Benefits / downsides

Page 16: ITEC 380 Organization of programming languages Dr. Andrew Ray.

Introduction

History

• Dr. Okie’s history notes– http://www.radford.edu/~nokie/classes/

380/w1l4.html

Page 17: ITEC 380 Organization of programming languages Dr. Andrew Ray.

Introduction

Compilers

• How a language is understood (ears / brain)

• Lexical analysis• Syntactic Analysis• Intermediate code generation• Optimization• Code Generation• All use a central DB to store info

(symbol table)

Page 18: ITEC 380 Organization of programming languages Dr. Andrew Ray.

Introduction

Symbol table

• Keystore method– Variables• Type, value, scope, memory location

– Functions– Classes

• Put info into table• Pull it out when generating code

Page 19: ITEC 380 Organization of programming languages Dr. Andrew Ray.

Introduction

Stage 1

• Read the information• Start at the top left and read a

character at a time• When you hit whitespace/eos,

generate token• Hand token off• Repeat

What tokens come fromx = 12 + y * 34?

Page 20: ITEC 380 Organization of programming languages Dr. Andrew Ray.

Introduction

Token handling

• Parse tree–What happens to each token

Token 1: xToken 2: =Token 3: 12Token 4: +Token 5: yToken 6: *Token 7: 34Token 8: ;

Tree

x =

12 +

y * 34

Page 21: ITEC 380 Organization of programming languages Dr. Andrew Ray.

Introduction

Code generation

• Use parse tree / symbol table• Step 1 – Lookup y’s value• Step 2 – Multiply, store temp• Step 3 – Add 12 to temp,

store in temp2

• Step 4 – Assign temp2 to x• Not difficult to generate assembly for

this

x =

12 +

y * 34

Page 22: ITEC 380 Organization of programming languages Dr. Andrew Ray.

Introduction

Optimization

• How to make your code better• Extremely difficult field• Reorganization of information– Unrolling loops

• Reduce redundant information

Page 23: ITEC 380 Organization of programming languages Dr. Andrew Ray.

Introduction

Not universal

• Not every implementation follows these steps

• Linking result against existing code• Targeting interpreter versus

assembler

Page 24: ITEC 380 Organization of programming languages Dr. Andrew Ray.

Introduction

Review

• Major paradigms / history of languages

• Parts of a computer language• How a language becomes real

Page 25: ITEC 380 Organization of programming languages Dr. Andrew Ray.

Introduction

Next week

• Grammar• Variable types / bindings / lifetime