Class Note for CS 403 at UA-Programming Languages (7)
Class Note for CS 403 at UA-Programming Languages (7)
Popular in Course
Popular in Department
This 7 page Class Notes was uploaded by an elite notetaker on Friday February 6, 2015. The Class Notes belongs to a course at University of Alabama - Tuscaloosa taught by a professor in Fall. Since its upload, it has received 27 views.
Reviews for Class Note for CS 403 at UA-Programming Languages (7)
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 02/06/15
CS 403 91902 Today Next writing assignment Chapter 3 ALGOL60 Reading Assignment Chapter 4 The Forum is available Other questions and answers are welcome Association of Computing Machinery The First Sumety lri Cumputlng m1 Meeting utthe VEav Thursday Septembevz zuuz Time and Place EE 119 am an n m Jum us unThuvsdaytuv FREE Pooh and anneuneemems er upeemme ACM events meiumne a pvuuvammmu cuntes1 Gues1 Speaker Shane Menm a UA cs marl eunemiy Dlrerlnr at Network and cumnuung Sunrm at Seebeck Fm mulE mimvisit us at aem ene ua edu Ntsz as w Chssmus Pun Mzmzcswzcmmus ha Career Fair Bryant Ctr Remember Programming Journal 9AM to 3PM Wednesday Sept 25 List of companies at WWWUaCCUaedU Please make an effort to visit there On another note A Interview Etiquettequot seminar on 924 Check the Engineering Career Center for details Assignment is on the web page Begin by writing your recollections about programming forthe uninitialized variablequot project Continue writing about any amp all programming experiences you have ECE 480 VHDL quali es BASH and other scripting languages do too I will askforthe rst installment on Sept 26 quot Ntsz as w Chssmus ha 2 Mzmzcswzcmmus hat Writing Assignment Due Dates Take 3 ofthe principles covered in chapters 1 3 Discuss how they apply to FORTRAN and 2 other languages Try to nd at least one application in FORTRAN that the text does not mention Write 12 typed pages Turn in Thursday 926 Same day as your journal So you have a short paper due on 926 And ou have our ro rammin 39ournal due on 9E6 y P Q Q and last night when posted today s notes I saw that I had scheduled Exam 1 on 926 That s not going to work surprised Complicatingfactors 103 is EDay no classes Paper 1a compilation of your rst 3 papers is due on 1010 I39ll have to move it back 12 weeks Exam 2 is 1030 I may have to move it back Ntsz as w Chssmus m Ntsz as m cm mu m Due Dates Choices as see them Move one or both papers back to Tuesday 101 Move the exam back to Tuesday 101 Move the exam back to Tuesday 108 Online vote on the forum deadline Saturday noon Result posted by Saturday night Ifyou have other options you think are worthy of consideration they must be posted no later than 5PM today so everyone can see them I ll give the nal list of options to vote on at 7PM Vote Give your worst choice and your best choice mzmz c 0330255 um ALGOL Original Report in 1958 proposed the new language A couple of years for comment Joint project of ACM and GAMM European group Produced in only 8 days Originally called International Algebraic Language IAL Various adaptations NELIAC Navy Electronic Lab International Algol Compiler JOVIAL Jules Schartz Own Version of IAL used by US Air Force m mm c m3 Class um BackusNaur Form BNF John Backus remember him One of the original group of the 58 report presented a formal description of the Algol grammar Peter Naur also a major early contributor didn t agree and realized that the problem was the imprecision ofthe 58 paper Created BackusNaur Form BNF to be a formal description ofa language grammar BNF is a very powerful tool You ll see it often mzmz c 0330255 um Algal 60 days in Paris in Jan 60 9 final report Very different from Algol58 Remarkable generality amp elegance Report was only 15 pages BNF helped keep it short BNF only describes grammar To describe the semantics clear precise unambiguous Englishlanguage descriptions Not as easy as it sounds Thirteen members of ACM amp GAMM met for 6 m mm c m3 Class um 32 Design Structural Organization Hierarchically structured Also called nesting Control structures can be nested Constructs are either declarative or imperative mzmz c 0330255 um Declarative Declarative constructs bind names to objects Variables Only types integer real amp Boolean Procedures all subprograms typed functions returning a value untyped don t return a value Switch declarations m mm c m3 Class um Imperatives Imperative statements do the work Computational Control Flow mzmzc lcbss utns p 13 Algol Assignment operator FORTRAN had used for assignments But this caused confusion between assignment and equality test Other languages had used 9 or gt etc no arrow symbol on most keyboards J 1 9 J Note the left to right movement This seems odd to us but left 9 right is very natural amp Englishlike mzuuzc m3 Class um p n Algol Assignment operator Algol started with as an approximation of an arrow J 1 J But changed the assignment operator to right to left following the FORTRAN usage J J 1 Notice J 1 is evaluated left to right Then the assignment operator acts right to left We re used to it but it s not as natural as it seems mzmzc lcbss utns p e15 Algol Control Structures Basic set goto if thenelse for loop procedure invocation mzuuzc m3 Class um p IE Compiletime vs Runtime Distinction was not too importantwith FORTRAN Since all the data was statically allocated little had to be done at runtime Algol allows dynamic use of memory and recursion This necessitated more flexibility at runtime 9 The Stack Stack is the central runtime data structure mm c 0330255 um p I 33 Design Name Structures Primitive declarations bind names to objects In FORTRAN that means the names were bound to memory locations In Algol a single name may be bound to many locations and they may change during runtime mzuuzc m3 Class um p I Data Constructor In FORTRAN it was the array In Algol the block is the main constructor Compound statement 9 a block begin end formed a block Any place you can put a statement you can put a block Blocks define nested scopes FORTRAN had global and local variables ln Algol every block may start with declarations So each block may have its own local variables As blocks are nested there may be several layers of variables local to one block but nonlocal to inner nested blocks Figure 33 amp 34 show examples ofthis Scoping lines in 33 help show the visibility of variables Remember pcGRASP Fall 2002 cs 403 Class Notes Pa e 19 Fall 2002 cs 403 Class Notes Pa e 20 Exercise 31 noun Lizw i 1 mass Manganqu x pm Many innIII x y 39 high a z Draw a contour diagram for a given piece of code Where are these variables visible A Q X a n i Fall 2002 cs 403 Class Notes Pa e 21 Mull roll In A1xl AH 2 139 m bani lulln mu amyi and ad pronaura am at x Mill IN2 n prondun Mam myquot a 1 mm Intnu x Ind Plnll Ind mm mm 1 k 9100 and Fall 2002 cs 403 Class Notes Pa e 22 Scoping Static vs Dynamic What s the context of the procedure Static the environment of the de nition Dynamic the environment of the caller Algol uses static scoping Most other imperative languages do too Dynamic scoping varies the context A nonlocal variable x may be one variable in one call and an entirely different variable in another call Fall 2002 cs 403 Class Notes pa Dynamic Scoping Consider this code a begin integer m procedure P m 1 b begin integer m P end P end For each call of P which m is used Figures 3839 amp 310 are helpful here Fall 2002 cs 403 Class Notes pa 4 Static amp Dynamic scoping Even though most ofthe languages you use will use static scoping you need to understand dynamic scoping It makes a great exam question Advice to the wise Work the exercises on scoping 34 310 mzmz c 0330255 um Block structuring 9 Stack Call stack makes efficient storage management of block structured languages You ve seen this before but review it carefully It usually helps to draw the scoping lines andor contour diagrams m mm c m3 Class um 34 Design Data Structures Primitives are mathematical scalars integer real amp Boolean Algol s decision make them machine independent Portability Principle Avoid features or facilities that are dependent on a particular computer or a small class of computers mzmz c 0330255 um ZeroOneln nity Principle The only reasonable numbers in a programming language design are zero one and infinity FORTRAN only allow 3 D arrays violates this principle Algol decided not to specify a limit on the dimensions of arrays Algol s arrays are also generalized in that array indexes don t have to start with 1 Write the addressing equation for a 1D array with generalized lower amp upper bounds Try 2D m mm c m3 Class um Dynamic Arrays Careful use of the call stack allows arrays to be dynamic Variables can be used in the array declarations integer array x a bb mzmz c 0330255 um Strong Typing Type abstractions are enforced You can t do integer addition on reals You can coerce integers to reals but not reals to integers Type domination Butthere is a conversion operatorthatwill truncate reals to integers Strong typing is a pain but it is a safety mechanism You override it at your perill Type violations cause machinedependent behavior 9 dangerous m mm c m3 Class um 35 Design Control Structures Nesting 9 Structured Programming Generalizations of FORTRAN s control structures If added then amp else For loops are much more general amp powerful Block structures amp nesting dramatically increases the flexibility ofthe control structures With wise use of nesting you don t need the goto statement Goto violates the Structure Principle The static structure of the program should correspond in a simple way to the dynamic structure of the corresponding computations mzmzc minimum p a mzuuzc m3 Class um p 2 Parameter Passing Pass by Name Pass by reference from FORTRAN Algol adds Pass by value Very inefficient for arrays and other large structures Algol also added Pass by name Just substitute the name of the actual parameter for the name of the formal parameter in the procedure procedure incr n integer n n n 1 Calls incrx incrAi mzmz c 0330255 um p a mzuuzc m3 Class um p u Pass by Name Pass by Name Implementation procedure S el k integer el k begin k 2 el 0 end Call 5 Alli i See Jensen s device for a good use of this feature mzmz c 0330255 um p How Can t actually compile using the Copy Rule Implement a small function that calculates the address of what the parameter refers to now Instantiate that function in the procedure everywhere the variable name appears Then implement as a call by reference This function is called a thunk Pass by name is inefficient mzuuzc m3 Class um p Pass by Name Dangerous procedure swap X y Calls integer X y SWaPal b quot OK begin integertemp temp X SWaPAl U x y swapi Ai y temp completely end different Curiosities of Algol mzmz c 0330255 um p m Feature interaction can create problems Wth n features you may have n2 interactions Keep n small For loop is so general it can be confusing See example page 138 Switch handles cases First declare all the cases single married Then goto one of the cases At the end of each case goto done label mzuuzc m3 Class um p 2 End of class Read all of chapters 0 1 2 amp 3 if you haven t already Read chapter 4 for Tuesday Check web page for Forum notices Remember your personal programming journal Check web page for details on next writing assignment mzmz c 0330255 um p e39
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'