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
Introduction Me 6 th year here at RU 1 st time teaching this course Have used lessons from this type of course to help with –Research –Teaching
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
Introduction How? Synchronous component Study at your leisure lectures Self study / experimentation Homework assignments –Intro –Major project Adaptability –Online forums/chat/twitter?
Introduction Informatio n Course website – Demo
Introduction Outline of course Languages 3-6 – Functional programming 7-10 – Logical programming – Procedural programming – OO / Review
Introduction Paradigms Radically different methods of accomplishing the same task Procedural Object oriented Functional Logical
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
Introduction Example 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 ); }
Introduction Paradigms Right tool right job OO is probably used for > 95% of software development Purpose –Performance –Reliability –Elegance –Expression
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?
Introduction Language s What is the purpose of a language? Why are there multiple languages? What are the major components of languages?
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
Introduction Implementatio n Compilation –Source, translation to binary, execution Interpretation –Source, intermediate program, execution Benefits / downsides
Introduction History Dr. Okie’s history notes – l4.html
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)
Introduction Symbol table Keystore method –Variables Type, value, scope, memory location –Functions –Classes Put info into table Pull it out when generating code
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 from x = 12 + y * 34?
Introduction Token handling Parse tree –What happens to each token Token 1: x Token 2: = Token 3: 12 Token 4: + Token 5: y Token 6: * Token 7: 34 Token 8: ; Tree x = 12+ y *34
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
Introduction Optimizatio n How to make your code better Extremely difficult field Reorganization of information –Unrolling loops Reduce redundant information
Introduction Not universal Not every implementation follows these steps Linking result against existing code Targeting interpreter versus assembler
Introduction Review Major paradigms / history of languages Parts of a computer language How a language becomes real
Introduction Next week Grammar Variable types / bindings / lifetime