250 likes | 347 Views
ITEC 380. Organization of programming languages Dr. Andrew Ray. Objectives. Introductions (Me + You ) Outline of course Why study languages? Paradigms How languages are understood. Me. 6 th year here at RU 1 st time teaching this course
E N D
ITEC 380 Organization of programming languages Dr. Andrew Ray
Objectives • Introductions (Me + You) • Outline of course • Why study languages? • Paradigms • How languages are understood
Me • 6th year here at RU • 1st time teaching this course • Have used lessons from this type of course to help with • Research • Teaching
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
How? • Synchronous component • Study at your leisure lectures • Self study / experimentation • Homework assignments • Intro • Major project • Adaptability • Online forums/chat/twitter?
Information • Course website • www.radford.edu/aaray/ITEC_380 • Demo
Outline of course • 1-2 - Languages • 3-6 – Functional programming • 7-10 – Logical programming • 11-12 – Procedural programming • 13-14 – OO / Review
Paradigms • Radically different methods of accomplishing the same task • Procedural • Object oriented • Functional • Logical
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
void 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 ); } } Example
Paradigms • Right tool right job • OO is probably used for > 95% of software development • Purpose • Performance • Reliability • Elegance • Expression
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?
Languages • What is the purpose of a language? • Why are there multiple languages? • What are the major components of languages?
Computers • Syntax • Did you put the exact number of ;’s in it? • Semantics • What does it mean? • Goal • Tell the computer what to do
Implementation • Compilation • Source, translation to binary, execution • Interpretation • Source, intermediate program, execution • Benefits / downsides
History • Dr. Okie’s history notes • http://www.radford.edu/~nokie/classes/380/w1l4.html
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)
Symbol table • Keystore method • Variables • Type, value, scope, memory location • Functions • Classes • Put info into table • Pull it out when generating code
Stage 1 What tokens come from x = 12 + y * 34? • 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
Token handling • Parse tree • What happens to each token Tree Token 1: x Token 2: = Token 3: 12 Token 4: + Token 5: y Token 6: * Token 7: 34 Token 8: ; x = 12 + y * 34
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
Optimization • How to make your code better • Extremely difficult field • Reorganization of information • Unrolling loops • Reduce redundant information
Not universal • Not every implementation follows these steps • Linking result against existing code • Targeting interpreter versus assembler
Review • Major paradigms / history of languages • Parts of a computer language • How a language becomes real
Next week • Grammar • Variable types / bindings / lifetime