ADA95 Tutorial Part 2

Size: px
Start display at page:

Download "ADA95 Tutorial Part 2"

Transcription

1 ADA95 Tutorial Part 2 produit à partir du matériel disponible à l'url

2 ADA 95 TUTORIAL This tutorial teaches the entire Ada 95 dialect of the Ada language. It is composed of 33 chapters which should be studied in order since topics are introduced in a logical order and build upon topics introduced in previous chapters. It is to the students benefit to download the source code for the example programs, then compile and execute each program as it is studied. The diligent student will modify the example program in some way, then recompile and execute it to see if he understands the material studied for that program. This will provide the student with valuable experience using his compiler. The recommended method of study is to print the text for one or two chapters, download the example programs, and study the material by loading the example programs in the compiler's editor for viewing. Following successful completion of each chapter, additional chapters can be downloaded as progress is made. Note that completion of the first part of this tutorial will give the student the ability to write very significant programs in Ada, but completion of the second part will give the student the ability to use all of the capabilities of Ada. Version February 1, 1998 The original for this page is located at and is the only fully authorized site for distribution of this tutorial. Many persons have downloaded one or more of our tutorials for redistribution without our consent, and occasionally do not include all of the components needed for the complete package. You can be assured that the tutorial will be complete and up to date only at the home site, since we have no control over the actions of other web site operators. This tutorial is distributed as shareware which means that you do not have to pay to use it. However, the author spent a good deal of time and financial resources to develop this tutorial and requests that you share in the financial burden in a very small way, but only if you felt the tutorial was valuable to you as an aid in learning to program in Ada. If you wish to remit a small payment to the author, full instructions for doing so will be given by clicking the link below. I hope you find programming in Ada to be rewarding and profitable. I personally think Ada is the best language to use for a large project with more than a single programmer because of the careful interface checking done by the compiler. How to Remit Payment For this Tutorial!

3 Part 2 - Advanced Ada 95 Tutorial Chapter 17 - Exceptions Chapter 18 - Advanced Subprogram Topics Chapter 19 - Advanced Array Topics Chapter 20 - Advanced Record Topics Chapter 21 - Advanced Packages & Private Types Chapter 22 - Object Oriented Programming Chapter 23 - More Object Oriented Programming Chapter 24 - Binary Input/Output Chapter 25 - Dynamic Allocation Chapter 26 - Tasking Chapter 27 - The Simple Rendezvous Chapter 28 - The Conditional Rendezvous Chapter 29 - Additional Tasking Topics Chapter 30 - Generic Subprograms Chapter 31- Generic Packages Chapter 32 - Control of Representation Chapter 33 - More Example Programs

4 Ada Tutorial - Chapter 17 EXCEPTIONS EXCEPTIONS ARE NOT NEW TO YOU Assuming you have completed part 1 of this tutorial, you have seen many references to exceptions, but we have said little about how you can use them. The purpose of this chapter is to instruct you on the use of exceptions, and by the time you complete it, you will have the ability to use exceptions to develop a program with its own error handling ability. WHY DO WE NEED EXCEPTIONS? The original charter for the development of Ada included the ability to operate in a real-time environment. You already understand, if you have much programming experience, that if it is possible for an error to surface, it will eventually surface. Many programming languages simply terminate operation if a "fatal error" is detected, but this could be a disaster if the program was controlling a real-time system upon which human lives or safety depended. A 747 in final approach to the airport, or a system used in a hospital operating room would be two examples of systems that simply could not be terminated abruptly because a bad data point was somehow accumulated. The careful application of Ada exceptions will allow the software to gracefully recover from such a situation rather than aborting operation completely. OUR FIRST EXCEPTION Example program > e_c17_p1.ada with Ada.Text_IO, Ada.Integer_Text_IO; use Ada.Text_IO, Ada.Integer_Text_IO; -- Chapter 17 - Program 1 procedure Except1 is procedure Divide_Loop is Divide_Result : INTEGER; for Index in 1..8 loop Put("Index is"); Put(Index, 3); Put(" and the answer is"); Divide_Result := 25 / (4 - Index); Put(Divide_Result, 3); exception when Constraint_Error => Put_Line(" Divide by zero error."); end Divide_Loop; Put_Line("Begin program here."); Divide_Loop; Put_Line("End of program."); end Except1; -- Result of Execution -- Begin program here. -- Index is 1 and the answer is 8 -- Index is 2 and the answer is 12

5 -- Index is 3 and the answer is Index is 4 and the answer is Divide by zero error. -- End of program. Examine the program named e_c17_p1.ada for our first example program with an exception handler. Ignore lines 18 and 19 for the moment and you will have a program that is not at all unusual, and should pose no problem for you to understand. The program does have a carefully introduced error however, because when we reach a value of 4 for Index in line 14, we will be attempting to divide by zero. Dividing by zero is not allowed in any programming language, because the answer is infinite and therefore undefined. The Ada runtime system will, by definition, cause the exception named Constraint_Error to be raised, which is the Ada way of saying that a divide by zero was attempted. This signals the system to do something about it. (Actually, there are many other ways to get the Constraint_Error exception raised but we will worry about them later.) The Ada system will search, in a very definite way, for any instructions we have given about this error, and if it finds none, will terminate operation of the program after issuing a message concerning the error. If we have given instructions about what to do with the error, it will execute the instructions and continue operation as we direct it to do. The method of giving the system these instructions is illustrated in lines 18 and 19. HOW ARE EXCEPTIONS HANDLED? When any exception is raised, the system immediately looks at the end of the current block or subprogram for the reserved word exception. If it is found, and if the specific exception that was raised is defined there, the instructions associated with that exception are executed, and the subprogram or block is exited. To define a handler for a specific exception, the reserved word when is used, followed by the name of the exception, and finally the sequence of statements to be executed following the => operator. The sequence of statements can be of arbitrary complexity, but should be kept simple due to the nature of exception handling. In this case, we output a message to the monitor and do nothing else. As many different exceptions as desired can be handled at the end of any block or subprogram by adding additional constructs of the form, when <exception-name> => instructions; following the single instance of the reserved word exception. We will study examples of multiple exception handlers later in this chapter. WHAT HAPPENS FOLLOWING EXCEPTION HANDLING? Following handling of the exception, the program executes an otherwise normal return to the calling program, and the normal sequence of instructions in the calling program is executed. Note that it is impossible to jump back into the subprogram or block in which the exception was raised from the exception handling routine at the end of that block. In this case, because of the logic used, the loop defined in line 10 is terminated early because we essentially jumped out of the loop and the program is ended. If an exception handler or a group of exception handlers is included, it must be the last thing in the block. If normal execution of the block reaches the end of the executable statements by coming to the reserved word exception, the block is terminated normally. You cannot drop into the exception handler at the end of a block. The only way to get to the exception handling code is through raising an exception. In spite of the additional questions you have at this point, compile and execute this program. Observe the results, and if you do not understand the output, reread the above text until you do, because these fundamental points are essential to understanding the entire topic of exceptions. LET'S USE SEVERAL EXCEPTIONS

6 Example program > e_c17_p2.ada with Ada.Text_IO, Ada.Integer_Text_IO; use Ada.Text_IO, Ada.Integer_Text_IO; -- Chapter 17 - Program 2 procedure Except2 is procedure Divide_Loop(Index : in INTEGER) is Divide_Result : INTEGER; Put("Index is"); Put(Index, 3); Put(" and the answer is"); Divide_Result := 25 / (4 - Index); Put(Divide_Result, 4); exception when Constraint_Error => Put(" Divide by zero error"); Put_Line(" in loop 1."); end Divide_Loop; procedure New_Divide_Loop(Index : in INTEGER) is My_Own_Exception : exception; Divide_Result : INTEGER; Put("Index is"); Put(Index, 3); Put(" and the answer is"); if Index = 4 then raise My_Own_Exception; end if; Divide_Result := 25 / (4 - Index); Put(Divide_Result, 4); exception when My_Own_Exception => Put(" Divide by zero error"); Put_Line(" in loop 3."); when Constraint_Error => Put_Line("This shouldn't happen."); Put_Line("But is included anyway."); when others => Put_Line("Some other exception found."); end New_Divide_Loop; Put_Line("Begin program here."); for Count in 1..6 loop -- loop number 1 Divide_Loop(Count); Put_Line("End of first loop."); for Count in 1..6 loop -- loop number 2 declare Divide_Result : INTEGER; Put("Count is"); Put(Count, 3); Put(" and the answer is"); Divide_Result := 25 / (4 - Count); Put(Divide_Result, 4); exception when Constraint_Error => Put(" Divide by zero error");

7 Put_Line(" in loop 2."); end; Put_Line("End of second loop."); for Count in 1..6 loop -- loop number 3 New_Divide_Loop(Count); Put_Line("End of program."); end Except2; -- Result of Execution -- Begin program here. -- Index is 1 and the answer is 8 -- Index is 2 and the answer is Index is 3 and the answer is Index is 4 and the answer is Divide by zero error in loop Index is 5 and the answer is Index is 6 and the answer is End of first loop. -- Count is 1 and the answer is 8 -- Count is 2 and the answer is Count is 3 and the answer is Count is 4 and the answer is Divide by zero error in loop Count is 5 and the answer is Count is 6 and the answer is End of second loop. -- Index is 1 and the answer is 8 -- Index is 2 and the answer is Index is 3 and the answer is Index is 4 and the answer is Divide by zero error in loop Index is 5 and the answer is Index is 6 and the answer is End of program. Examine the program named e_c17_p2.ada for additional examples of exceptions. This program will answer many of your questions about exceptions. In the last program we terminated the loop when the exception was raised, but we may desire to continue execution of the program following the exception. The first procedure in this program is logically identical to the last example program except the loop is moved to the calling program. When the divide by zero is detected by the system, which raises the Constraint_Error exception, the exception is handled by the exception handler defined in lines 17 and 18, and the return to the calling program is effected. In this case however, when control returns to the calling program, we are still inside of the loop, and the loop completes normally. This should indicate to you that by careful selection of where you handle exceptions, you can control the overall result. We will see more about this as we continue our study of exceptions. The logic of the second group of instructions, found in lines 49 through 64, is identical to the logic of the first group as studied in the last paragraph. The only difference is that the procedure has been changed into a block and inserted into the code in an inline fashion. This has been done to illustrate the use of an exception in a block of code, and to illustrate that the exception handler for the block of code is put at the end of that block. After the exception is raised and handled, execution s at the first statement following the block. Because the block is contained within the loop, the

8 exception is handled within the loop and the loop runs to completion. MULTIPLE EXCEPTION HANDLERS Finally, we come to the section of code in lines 66 through 69, consisting of a simple loop calling the procedure New_Divide_Loop. The procedure itself, defined in lines 21 through 40, contains an example of a new operation, the ability to make up our own exception, raise it our self, and handle it with our own exception handler. Line 22 declares the identifier My_Own_Exception as being the name of an exception, and is defined in much the same way that we would declare a variable. We cannot assign a value to it, but we can raise it anywhere within its defined scope which is the same as the scope of a variable declared at the same place. The exception is automatically initialized to the "not raised" condition by the system. Beginning in line 34, we define three different exception handlers, which will cover any exceptions raised anywhere within this procedure. The first two are named exception handlers but the third handler uses the reserved word others to indicate that it will be used for any exceptions that are not handled by the two named exception handlers. The others clause is optional, but if it is included, it must be last. RAISING AN EXCEPTION If we reach line 28 with a value of 4, which we eventually will because of the logic of the calling program, we will detect the divide by zero that would be attempted upon reaching line 31. Instead of letting the system generate the exception named Constraint_Error, we generate our own exception named My_Own_Exception, using the reserved word raise followed by the name of the exception. As soon as we raise this exception, the system jumps to the end of the block, looks for the reserved word exception, which it finds, then looks for the exception handler with the name that was raised. Upon finding it, the statements are executed, resulting in a message being output to the display, and we return to the calling program. In this case, the system will not raise the exception Constraint_Error, because we are detecting the error before it actually happens. You could raise it yourself by inserting the statement "raise Constraint_Error;" somewhere in this procedure, possibly when the value of Index is equal to 3. It would be a good exercise for you to insert that in the code to see that you can raise one of the system exceptions as well as your own. Be sure to compile and execute this program to verify proper operation according to this description and to ascertain your understanding of the same. Note that if an exception occurs, formal parameters of mode out or in out are not updated since a normal return is not accomplished. Partial results will therefore not be returned to the calling program. This is not illustrated here, but is left for the student to investigate if desired. WHAT ARE THE PREDEFINED EXCEPTIONS? There are four predefined exceptions which can be raised by the system to indicate a very specific problem. A brief definition follows; 1. Constraint_Error - This will occur if something goes out of its assigned range. 2. Program_Error - This will occur if we attempt to violate an Ada control structure such as dropping through the bottom of a function without a return. 3. Storage_Error - This will occur if we run out of storage space through either recursive calls or storage allocation calls. 4. Tasking_Error - This will occur when attempting to use some form of tasking in violation of the rules. WHAT ABOUT AN UNHANDLED EXCEPTION?

9 Example program > e_c17_p3.ada with Ada.Text_IO, Ada.Integer_Text_IO; use Ada.Text_IO, Ada.Integer_Text_IO; -- Chapter 17 - Program 3 procedure Except3 is procedure Divide_By_Zero(Count : INTEGER) is Divide_Result : INTEGER; Put("Count is"); Put(Count, 3); Put(" and the answer is"); Divide_Result := 25 / (Count - 4); Put(Divide_Result, 4); exception when Constraint_Error => Put_Line(" Divide by zero occurred"); end Divide_By_Zero; procedure Raise_An_Error(Count : INTEGER) is My_Own_Error : exception; Another_Result : INTEGER; Put("Count is"); Put(Count, 3); Another_Result := 35 / (Count - 6); -- untested divide by zero if Count = 3 then raise My_Own_Error; end if; Put_Line(" and is a legal value"); exception when My_Own_Error => Put_Line(" My own error occurred"); end Raise_An_Error; Put_Line("Begin program here."); for Count in 1..7 loop Divide_By_Zero(Count); Raise_An_Error(Count); Put_Line("End of program."); exception when Constraint_Error => Put(" Constraint error detected at"); Put_Line(" the main program level."); Put_Line("Program terminated."); end Except3; -- Result of Execution -- Begin program here. -- Count is 1 and the answer is Count is 1 and is a legal value -- Count is 2 and the answer is Count is 2 and is a legal value -- Count is 3 and the answer is Count is 3 My own error occurred

10 -- Count is 4 and the answer is Divide by zero occurred -- Count is 4 and is a legal value -- Count is 5 and the answer is Count is 5 and is a legal value -- Count is 6 and the answer is Count is 6 Constraint error detected at the main program level. -- Program terminated. Examination of the program named e_c17_p3.ada will reveal what happens if an exception is raised that is not handled by the program. In a word, the program will be terminated, but we need to understand how termination occurs so we can intelligently prevent it. There is a loop in the main program which calls two procedures successively, Divide_By_Zero and Raise_An_Error. The first procedure is identical to that in the first two example programs and the only exception raised is Constraint_Error, which is handled properly. The second procedure has its own exception defined, named My_Own_Error which it raises and handles itself in the manner defined previously in this chapter. It also has a divide by zero problem in line 26 that will raise the exception Constraint_Error when Count is equal to 6. Of course, the logic is defined to make this happen and illustrate the error. PROPAGATION OF EXCEPTIONS When the exception Constraint_Error is raised at line 26, the system searches for the reserved word exception which it finds in line 31 at the end of the procedure. It then searches for a sequence of statements for Constraint_Error which it does not find. Since an exception handler is not found within the procedure, the exception is propagated to the calling program in such a way that the exception appears to have been raised by the calling statement. In this case it will appear to the logic as if the exception Constraint_Error was raised by the statement in line 39. Once again, the exception rules are applied, and the system searches for an exception section at the end of the block or subprogram, in this case being the main program. Finding the reserved word exception in line 43, the system looks for the desired exception handler, which it finds and executes, then drops out of the bottom of the main program and returns to the operating system. If there were no handler for the exception, the exception would be propagated to the operating system, and it would issue some sort of nasty message on the standard output device about an unhandled exception leading to program termination. It should be somewhat obvious to you that if you added another level of subprogram nesting, you could report the error yourself, and possibly recover operation of the program. It is all a matter of program definition. CAN YOU EXECUTE AN EXCEPTION WITHOUT RAISING IT? As mentioned before, the section of code at the end of a block or subprogram, following the reserved word exception, is never executed without raising an exception. It can never be executed by dropping into it. Be sure to compile and execute this program to observe the operation of the exceptions. EXCEPTIONS CAN OCCUR DURING DECLARATIONS Example program > e_c17_p4.ada with Ada.Text_IO; use Ada.Text_IO; procedure Except4 is -- Chapter 17 - Program 4

11 procedure Try_It is VALUE : constant := 8; subtype LIMIT_RANGE is INTEGER range ; Funny : LIMIT_RANGE := VALUE; Put_Line("We are in the Try_It procedure"); exception when Constraint_Error => Put_Line("Constraint error occurred"); Put_Line("Detected in procedure Try_It"); end Try_It; procedure Try_To_Fix_It is Put_Line("We are in the Try_To_Fix_It procedure."); Try_It; exception when Constraint_Error => Put_Line("Constraint error occurred"); Put_Line("Detected in procedure Try_To_Fix_It"); end Try_To_Fix_It; Put_Line("Begin program here."); for Count in 1..4 loop Put_Line("Ready to call Try_To_Fix_It."); Try_To_Fix_It; Put_Line("End of program."); exception when Constraint_Error => Put ("Range error detected at the"); Put_Line(" main program level."); Put_Line("Program terminated."); end Except4; -- Result of execution -- Begin program here. -- Ready to call Try_To_Fix_It. -- We are in the Try_To_Fix_It procedure. -- Constraint error occurred -- Detected in procedure Try_To-Fix_It Ready to call Try_To_Fix_It. -- We are in the Try_To_Fix_It procedure. -- Constraint error occurred -- Detected in procedure Try_To-Fix_It Ready to call Try_To_Fix_It. -- We are in the Try_To_Fix_It procedure. -- Constraint error occurred -- Detected in procedure Try_To-Fix_It Ready to call Try_To_Fix_It.

12 -- We are in the Try_To_Fix_It procedure. -- Constraint error occurred -- Detected in procedure Try_To-Fix_It End of program. Examine the program named e_c17_p4.ada for an example of an exception that occurs during the declaration part of the program. When a procedure is called, its declarations are elaborated prior to the logic being executed, as we have stated before. If one of the declarations cannot be properly elaborated, then an error occurs and an exception is raised. Examining the procedure Try_It will reveal an error in lines 8 through 10, where he variable Funny is declared to be of type LIMIT_RANGE with limits of 14 through 33, then it is initialized to the value 8. Since this is out of the allowed range, the exception Constraint_Error will be raised. The executable part of the procedure is not yet ready for use, so the exception handler defined within it cannot be used, and the exception will be propagated to the calling program where it will be handled just as if it occurred in the calling statement, which is line 22 in this case. The exception will therefore be handled by lines 24 through 26 of the procedure Try_To_Fix_It. Note that we never executed the code in the procedure named Try_It. Be sure to compile and run this program, then study the results. ADDITIONAL PREDEFINED EXCEPTIONS You will find that there are actually additional exceptions predefined by your compiler, but these are all defined in additional packages supplied with your compiler. Packages such as Ada.Text_IO, Ada.Sequential_IO, or Ada.Calendar (to be discussed later with tasking), have some number of exceptions defined as a part of their interfaces, but there are only four exceptions predefined as a part of Ada. These were listed and discussed earlier. A FEW MORE TOPICS CONCERNING EXCEPTIONS Example program > e_c17_p5.ada -- Chapter 17 - Program 5 package Stuff is Funny_Add_Error : exception; procedure Add_One(Number : in out INTEGER); function Subtract_One(Number : INTEGER) return INTEGER; end Stuff; with Ada.Text_IO; use Ada.Text_IO; package body Stuff is procedure Add_One(Number : in out INTEGER) is Number := Number + 1; exception when Funny_Add_Error => Put_Line("Funny add error raised"); when Constraint_Error => Put_Line("Constraint error raised"); end Add_One; function Subtract_One(Number : INTEGER) return INTEGER is Funny_Subtract_Error : exception; raise Funny_Subtract_Error;

13 return Number - 1; exception when Funny_Add_Error => Put_Line("Funny add error raised"); raise; when Funny_Subtract_Error => Put_Line("Funny subtract error raised"); raise; end Subtract_One; null; exception -- Numeric_Error is obsolete in Ada 95. It is another name for -- the exception Constraint_Error. -- when Numeric_Error => -- Put_Line("Numeric error during elaboration"); when Constraint_Error => Put_Line("Constraint_Error during elaboration"); when Funny_Add_Error => Put_Line("Funny Add error during elaboration"); -- when Funny_Subtract_Error => -- Put_Line("Funny subtract error during elaboration"); end Stuff; with Ada.Text_IO, Stuff; use Ada.Text_IO, Stuff; procedure Except5 is Index : INTEGER := 5; Add_Error : exception renames Stuff.Funny_Add_Error; Add_One(Index); Index := Subtract_One(Index); exception when Numeric_Error Constraint_Error => Put_Line("Numeric error or constraint error raised."); when Add_Error => Put_Line("Addition error detected"); when others => Put_Line("An unknown exception raised"); raise; -- Raise it again for the operating system end Except5; -- Result of execution -- Funny subtract error raised -- An unknown exception raised -- Unhandled exception; funny_subtract_error -- (Note, The last line above will be different for each compiler, -- but will say something about an unhandled exception. It -- will probably output about 10 lines of text.) The example program named e_c17_p5.ada illustrates a few additional topics about exceptions and illustrates how they are used in a package. This is a very strange program with lots of exception

14 handling examples for your study. You will be left on your own to study the overall operation of this program, but the unique exception handling techniques will be pointed out to you. The package body contains a section of initialization code in lines 37 through 49 which is composed of nothing but a null statement and several exception handlers. These are only used during initialization of the package since they are not within the executable portion of either of the subprograms. You will notice that the exception named Funny_Add_Error is declared in the package specification so it is visible in the exception handler in line 46, but the exception named Funny_Subtract_Error is not visible there because it is declared within the function. We will see soon however, that even this exception can be propagated to the main program. When the program is executing, a call to the function Subtract_One raises the exception Funny_Subtract_Error which is handled by the exception handler at the end of the function in line 32. A message is displayed and the same exception is raised by the isolated raise statement in line 34. This statement simply raises the exception that caused the jump to the exception handler in the first place. The isolated raise statement can only be used within an exception handler. The exception is passed on to the calling program, even though it has already been handled here. Because the exception named Funny_Subtract_Error is not visible to the main program, it cannot handle it by name but even this exception can be handled by an others clause as is done in line 68. After printing a message, the same exception is once again raised in line 70 where it is passed on to the operating system. You will see when you execute this program that the exception is known by name to the operating system. It will give you a nasty message about the unhandled exception and terminate operation. THE others CLAUSE IN AN EXCEPTION HANDLER If the others clause is used, it must be the last in the exception handler list and it cannot be combined with any other exceptions such as illustrated in line 64. As in other Ada constructs, two or more exceptions can be "or"ed and use the same exception handler. Numeric_Error was available inn Ada 83, but is considered obsolete in Ada 95. The name Numeric_Error is a synonym for Constraint_Error in Ada 95 to permit legacy code to compile without error. Note line 59 where an exception is renamed to reduce the length of its name. Any exception can be renamed in a similar fashion. Be sure to compile and execute this program and spend the time necessary to understand the exception propagation illustrated here. WHAT IS AN EXCEPTION OCCURRENCE? Many times it is adequate to simply report that an exception occurred and the general nature of the exception is sufficient to permit a recovery from the exceptional condition. There are times however, that it is necessary to provide additional information about the exception and what caused it. The exception occurrence is available in a predefined Ada 95 package for this purpose. The exception occurrence gives a unique name to one instance of raising an exception and provides hooks to completely analyze where and when the exception occurred. As always in this tutorial, an example program provides the best illustration, so examine the example program named e_c17_p6.ada. Example program > e_c17_p6.ada -- Chapter 17 - Program 6 with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Exceptions; use Ada.Text_IO, Ada.Integer_Text_IO; procedure Occur is Except_ID : Ada.Exceptions.EXCEPTION_OCCURRENCE;

15 procedure Divide_Loop is Divide_Result : INTEGER; for Index in 1..8 loop Put("Index is"); Put(Index, 3); Put(" and the answer is"); Divide_Result := 25 / (4 - Index); Put(Divide_Result, 3); exception when Except_ID: Constraint_Error => Put_Line(" Divide by zero error."); Put_Line(" Exception name:"); Put_Line(Ada.Exceptions.Exception_Name(Except_ID)); Put_Line(" Exception information:"); Put_Line(Ada.Exceptions.Exception_Information(Except_ID)); when Except_ID: Storage_Error => Put_Line(" Storage error detected."); Put_Line(Ada.Exceptions.Exception_Information(Except_ID)); when Except_ID: others => Put_Line(" Unknown exception detected."); Put_Line(Ada.Exceptions.Exception_Information(Except_ID)); end Divide_Loop; Put_Line("Begin program here."); Divide_Loop; Put_Line("End of program."); end Occur; -- Result of Execution -- Begin program here. -- Index is 1 and the answer is 8 -- Index is 2 and the answer is Index is 3 and the answer is Index is 4 and the answer is Divide by zero error Exception name: -- Constraint_Error Exception message: -- Constraint_Error (divide by zero) End of program.

16 In line 2 we with the package named Ada.Exceptions which provides us with the ability to name and use an exception occurrence, and we name one in line 8. The name Except_ID can be used to refer to any single exception at a time, but can be reused to refer to any other exception at a later time. This example program executes a loop with a contrived error in it, a divide by zero. In fact, you may recognize it as a modification of the first example program in this chapter. When we arrive at the divide by zero condition, the exception Constraint_Error is raised and the exception handler defined in line 23 is found and execution s. However, because of the occurrence name given immediately following the reserved word when, this particular occurrence of Constraint_Error is given the name Except_ID. Once we have the occurrence name, we can use it to retrieve a formatted message with the name of the exception, even if the exception name in no longer within scope. This is done via a call to Exception_Name which is a part of the Ada.Exceptions package. This is illustrated in line 28 where the returned line of text is simply copied to the monitor. We can also get a more detailed message including a complete call stack listing by calling the function named Exception_Message with the name of the exception occurrence as the only parameter. This result is also copied to the monitor for inspection. The actual format is implementation dependent, and your compiler may give a very verbose line of text or a very sparse line of text. The compiler used for this compilation emitted a very scarce text. If we were to correct the error and allow the program to continue, another divide by zero condition would cause the Constraint_Error and the Except_ID exception occurrence could be used to analyze that particular exception. It should be obvious that you could use this to log certain exceptions to a log file for post execution analysis of what caused some particular catastrophic failure. If properly planned, such a log file would have a complete history of system operation prior to failure. USING THE OCCURRENCE MORE THAN ONCE In line 34 of the example program, we use the same occurrence name to retrieve and display information about any occurrence of the Storage_Error exception. This indicates that the exception occurrence acts just like a variable and can be used to refer to any exception that occurs during execution of the program. Note that it is very unlikely that the Storage_Error exception will be raised in this program, but is given here only for illustration. The same name can be used with the others condition to cover any otherwise unhandled exceptions that occur. Be sure to compile and execute this program with your compiler to see the output format provided for you. There is no standard way to format this data, so your output could look very different from the example output provided in the result of execution. The same information will be provided for you in some meaningful manner. PROGRAMMING EXERCISES 1. Change line 31 of e_c17_p2.ada to cause a divide by zero when Index is equal to 2 and see that both exceptions will be handled correctly.(solution) -- Chapter 17 - Programming example 1 with Ada.Text_IO, Ada.Integer_Text_IO; use Ada.Text_IO, Ada.Integer_Text_IO; procedure CH17_1 is procedure Divide_Loop(Index : in Divide_Result : INTEGER; Put("Index is"); Put(Index, 3); Put(" and the answer is"); INTEGER) is

17 Divide_Result := 25 / (4 - Index); Put(Divide_Result); exception when Constraint_Error => Put(" Divide by zero error"); Put_Line(" in loop 1."); end Divide_Loop; procedure New_Divide_Loop(Index : in INTEGER) is My_Own_Exception : exception; Divide_Result : INTEGER; Put("Index is"); Put(Index, 3); Put(" and the answer is"); if Index = 4 then raise My_Own_Exception; end if; Divide_Result := 25 / (2 - Index); Put(Divide_Result); exception when My_Own_Exception => Put(" Divide by zero error"); Put_Line(" in loop 3."); when Constraint_Error => Put_Line("This shouldn't happen."); Put_Line("But is included anyway."); when others => Put_Line("Some other exception found."); end New_Divide_Loop; Put_Line("Begin program here."); for Count in 1..6 loop -- loop number 1 Divide_Loop(Count); Put_Line("End of first loop."); for Count in 1..6 loop -- loop number 2 declare Divide_Result : INTEGER; Put("Count is"); Put(Count, 3); Put(" and the answer is"); Divide_Result := 25 / (4 - Count); Put(Divide_Result); exception when Constraint_Error => Put(" Divide by zero error"); Put_Line(" in loop 2."); end; Put_Line("End of second loop."); for Count in 1..6 loop -- loop number 3 New_Divide_Loop(Count); Put_Line("End of program."); end CH17_1;

18 -- Result of Execution -- Begin program here. -- Index is 1 and the answer is 8 -- Index is 2 and the answer is Index is 3 and the answer is Index is 4 and the answer is Divide by zero error in loop Index is 5 and the answer is Index is 6 and the answer is End of first loop. -- Count is 1 and the answer is 8 -- Count is 2 and the answer is Count is 3 and the answer is Count is 4 and the answer is Divide by zero error in loop Count is 5 and the answer is Count is 6 and the answer is End of second loop. -- Index is 1 and the answer is Index is 2 and the answer isthis shouldn't happen. -- But is included anyway. -- Index is 3 and the answer is Index is 4 and the answer is Divide by zero error in loop Index is 5 and the answer is Index is 6 and the answer is End of program. 2. Also in e_c17_p2.ada, declare a new exception in line 22, and raise it in line 29 to see how the others clause handles it.(solution) -- Chapter 17 - Programming example 2 with Ada.Text_IO, Ada.Integer_Text_IO; use Ada.Text_IO, Ada.Integer_Text_IO; procedure CH17_2 is procedure Divide_Loop(Index : in INTEGER) is Divide_Result : INTEGER; Put("Index is"); Put(Index, 3); Put(" and the answer is"); Divide_Result := 25 / (4 - Index); Put(Divide_Result); exception when Constraint_Error => Put(" Divide by zero error"); Put_Line(" in loop 1."); end Divide_Loop; procedure New_Divide_Loop(Index : in INTEGER) is My_Own_Exception, Surprise : exception; Divide_Result : INTEGER; Put("Index is"); Put(Index, 3); Put(" and the answer is"); if Index = 4 then raise Surprise; end if;

19 Divide_Result := 25 / (4 - Index); Put(Divide_Result); exception when My_Own_Exception => Put(" Divide by zero error"); Put_Line(" in loop 3."); when Constraint_Error => Put_Line("This shouldn't happen."); Put_Line("But is included anyway."); when others => Put_Line(" Some other exception found."); end New_Divide_Loop; Put_Line("Begin program here."); for Count in 1..6 loop -- loop number 1 Divide_Loop(Count); Put_Line("End of first loop."); for Count in 1..6 loop -- loop number 2 declare Divide_Result : INTEGER; Put("Count is"); Put(Count, 3); Put(" and the answer is"); Divide_Result := 25 / (4 - Count); Put(Divide_Result); exception when Constraint_Error => Put(" Divide by zero error"); Put_Line(" in loop 2."); end; Put_Line("End of second loop."); for Count in 1..6 loop -- loop number 3 New_Divide_Loop(Count); Put_Line("End of program."); end CH17_2; -- Result of Execution -- Begin program here. -- Index is 1 and the answer is 8 -- Index is 2 and the answer is Index is 3 and the answer is Index is 4 and the answer is Divide by zero error in loop Index is 5 and the answer is Index is 6 and the answer is End of first loop. -- Count is 1 and the answer is 8 -- Count is 2 and the answer is Count is 3 and the answer is Count is 4 and the answer is Divide by zero error in loop Count is 5 and the answer is Count is 6 and the answer is End of second loop.

20 -- Index is 1 and the answer is 8 -- Index is 2 and the answer is Index is 3 and the answer is Index is 4 and the answer is Some other exception found. -- Index is 5 and the answer is Index is 6 and the answer is End of program.

21 Ada Tutorial - Chapter 18 ADVANCED SUBPROGRAM TOPICS In part 1 of this tutorial we covered the topic of subprograms in some detail, but there are many other things to discuss about them, so we return to them for more advanced topics. DEFAULT PARAMETERS Example program > e_c18_p1.ada with Ada.Text_IO, Ada.Integer_Text_IO; use Ada.Text_IO, Ada.Integer_Text_IO; procedure Defaults is Index : INTEGER; Animal_Sum : INTEGER; procedure Animals(Total : in out INTEGER; Cows : in INTEGER := 0; Total := Cows + Pigs + Dogs; Put("Cows ="); Put(Cows, 3); Put(" Pigs ="); Put(Pigs, 3); Put(" Dogs ="); Put(Dogs, 3); Put(" Put(Total, 4); end Animals; -- Chapter 18 - Program 1 Pigs : in INTEGER := 0; Dogs : in INTEGER := 0) is and they total"); Index := 3; Animals(Animal_Sum, 2, 3, 4); Animals(Animal_Sum, 3, Index, 4); Animals(Dogs => 4, Total => Animal_Sum); Animals(Total => Animal_Sum, Pigs => 2 * Index + 1, Cows => 5); Animals(Dogs => Index + 4, Total => Animal_Sum); Animals(Animal_Sum, Dogs => 4, Pigs => Index, Cows => 2); Animals(Animal_Sum); end Defaults; -- Result of Execution -- Cows = 2 Pigs = 3 Dogs = 4 and they total 9 -- Cows = 3 Pigs = 3 Dogs = 4 and they total Cows = 0 Pigs = 0 Dogs = 4 and they total 4 -- Cows = 5 Pigs = 7 Dogs = 0 and they total Cows = 0 Pigs = 0 Dogs = 7 and they total 7 -- Cows = 2 Pigs = 3 Dogs = 4 and they total 9 -- Cows = 0 Pigs = 0 Dogs = 0 and they total 0

22 Examine the program named e_c18_p1.ada for some examples of default parameters used in the definition of a procedure. The procedure has four formal parameters, of which the first is of mode in out, and the other three are of the mode in. The three in parameters have default values of zero assigned to each of them. When we call this procedure, we are not required to supply a value for each variable, and those we do not supply a value for will be defaulted to zero upon execution. Of course the first variable in the list, named Total, must have a variable name supplied so it can return a value. Therefore, it cannot be defaulted. The procedure itself, and the first two calls to it, in lines 29 and 30, should pose no problem for you to understand. When we arrive at line 31, however, we have a few things to point out. NAMED NOTATION FOR ACTUAL PARAMETERS We are using the named aggregate notation for the actual parameters in line 31, so they can be listed in any order, but due to the defaults defined in the procedure header, we do not have to specify every parameter, allowing the default values to take effect upon a call to the procedure. You will see, when you compile and run this program, that Cows and Pigs will have the default values of zero. Lines 32 and 33 also use the named aggregate notation and should be clear as to their operation. Line 34 uses the mixed aggregate notation, and as we discussed before, the positional aggregate notation can be used initially, but after switching to the named notation, all remaining entries must be named, unless they are allowed to default. Line 35 illustrates the degenerate case where only the result is used, with all three input variables defaulting to zero. PARAMETERS WITH out MODE CANNOT BE DEFAULTED Since the parameters that are of either mode in out or mode out must be able to return a value, they must have a variable defined as their actual parameter, and cannot therefore be defaulted. Default parameters are not new to you, because you have actually used them in procedure calls before. When you call the procedure New_Line, you have an optional number following it as in New_Line(2). The number of lines to space up on the monitor is defaulted to one in the package Ada.Text_IO, which was supplied to you with your compiler, but you can override the default by inserting a value for the number of lines. It is defined in Annex A.10.1 of the Ada 95 Reference Manual (ARM), where the formal parameter named Spacing is defaulted to the value of 1. Refer to either your documentation or the ARM and see this in use. DYNAMIC DEFAULT PARAMETERS Example program > e_c18_p2.ada with Ada.Text_IO, Ada.Integer_Text_IO; use Ada.Text_IO, Ada.Integer_Text_IO; procedure Default2 is Index : INTEGER; Animal_Sum : INTEGER; function Cow_Constant return INTEGER is return 7; end Cow_Constant; function Pig_Constant return INTEGER is Animals : INTEGER := Cow_Constant - 3; return 2 * Animals + 5; end Pig_Constant; procedure Animals(Total : in out INTEGER; -- Chapter 18 - Program 2

23 Cows : in INTEGER := 2 * Cow_Constant; Pigs : in INTEGER := Cow_Constant + Pig_Constant; Dogs : in INTEGER := 0) is Total := Cows + Pigs + Dogs; Put("Cows ="); Put(Cows, 3); Put(" Pigs ="); Put(Pigs, 3); Put(" Dogs ="); Put(Dogs, 3); Put(" and they total"); Put(Total, 4); end Animals; Index := 3; Animals(Animal_Sum, 2, 3, 4); Animals(Animal_Sum, 2, Index, 4); Animals(Dogs => 4, Total => Animal_Sum); Animals(Total => Animal_Sum, Pigs => 2 * Index + 1, Cows => 5); Animals(Dogs => Index + 4, Total => Animal_Sum); Animals(Animal_Sum, Dogs => 4, Pigs => Index, Cows => 2); Animals(Animal_Sum); end Default2; -- Result of Execution -- Cows = 2 Pigs = 3 Dogs = 4 and they total 9 -- Cows = 2 Pigs = 3 Dogs = 4 and they total 9 -- Cows = 14 Pigs = 20 Dogs = 4 and they total Cows = 5 Pigs = 7 Dogs = 0 and they total Cows = 14 Pigs = 20 Dogs = 7 and they total Cows = 2 Pigs = 3 Dogs = 4 and they total 9 -- Cows = 14 Pigs = 20 Dogs = 0 and they total 34 The program named e_c18_p2.ada is identical to the last example program except for one detail. The definition of the default values of the formal parameters are declared differently here. You will notice that the default values are not only arithmetic combinations, but the values to combine are the results of function calls, where the values are dynamically evaluated each time the procedure Animals is called. The default values are constants for each call of the procedure, but they are evaluated for each call and could therefore be different each time the procedure is called and executed. As mentioned previously, this is called elaboration. If the return from Cow_Constant, in line 12, returned the value of a global variable for example, the main program could modify the value of the global variable and therefore modify the value of the default variables prior to each call to the procedure. It would therefore be possible to set up different default values in each of several different procedures based on the currently read time of day, the ambient temperature, or whatever other variable conditions could be read into the system. Be sure to compile and run this program and observe the results, comparing them with the results you expected the program to output. THE MYSTERY OF RECURSION

24 Example program > e_c18_p3.ada with Ada.Text_IO, Ada.Integer_Text_IO; use Ada.Text_IO, Ada.Integer_Text_IO; -- Chapter 18 - Program 3 procedure Recurson is Index : INTEGER; procedure Print_And_Decrement(Value : in New_Value : INTEGER; Put("The value of the index is now"); Put(Value, 3); New_Value := Value - 1; if New_Value > 0 then Print_And_Decrement(New_Value); end if; end Print_And_Decrement; INTEGER) is Index := 7; Print_And_Decrement(Index); end Recurson; -- Result of execution -- The value of the index is now 7 -- The value of the index is now 6 -- The value of the index is now 5 -- The value of the index is now 4 -- The value of the index is now 3 -- The value of the index is now 2 -- The value of the index is now 1 This topic will be no problem for the experienced Pascal programmer, but for the FORTRAN programmer, it may be an entirely new and somewhat perplexing topic. Stay with it, and you will see exactly what recursion is and how to use it effectively. Examine the example program named e_c18_p3.ada, which is the simplest recursive program possible, but which is excellent for describing what recursion is and how it works. Beginning at the main program, we assign the variable named Index the value of 7 then call the procedure named Print_And_Decrement, taking along the value of Index as an actual parameter. Arriving at the procedure itself, we use the name Value for the formal parameter, and we display the value on the monitor with an appropriate line of text. Continuing on to line 15, we decrement the value of the passed variable then compare the result to zero. If the value is greater than zero, we call the procedure named Print_And_Decrement taking along the newly decremented value called New_Value. Here is where the FORTRAN programmer notices something new. We are calling the procedure from within itself, and that is just what recursion is. Assume for a moment that we call another complete copy of the procedure, decrement the value once again, and if it is still not zero, call another copy of the procedure. Eventually, the value of the passed variable will be reduced to zero and the procedure calls will all be completed, each returning to the procedure that called it until we arrive once again at the main program.

25 You should compile and run this program to see that it really does what we say it does, then return for additional discussion of this program and what it is doing. This is a really dumb way to count from 7 down to 1, but it is a very simple way to illustrate the use of recursion. Later in this tutorial, we will have illustrations of excellent uses of recursion for your instruction. WHAT ACTUALLY HAPPENED? When we called the procedure Print_And_Decrement, it began by elaborating its formal variables and assigning them the values passed by the calling program. These are stored on the stack, an internal portion of memory set aside by the Ada system to store dynamic variables and constants, and are available for later use. The local variables are then generated and elaborated, although in this case there was only one, and stored on the stack also with means to refer to them. Finally, the program code itself is actually executed, and when it is completed, the local variables and formal variables are erased from the stack and no longer exist. In a recursive call, the stack grows with each new call, and when control returns to an earlier call of the code, the variables for that call are still on the stack and available for use. In this program, we actually have only one copy of the executable code stored, but we have many copies of the formal variable and the local variable stored on the stack. ALL ADA SUBPROGRAMS ARE RE-ENTRANT If you have experience in systems programming and understand what it means for a program to be re-entrant, you will understand how this means of variable storage allows all Ada subprograms to be re- entrant. The ARM requires that all Ada subprograms be re-entrant, but if you don't know what it means, don't worry about it. It would be a good exercise for you to insert some code to display the value of the formal parameter following the recursive call to see that the value of the formal variable is still available when we return from each recursive call. This code would be inserted immediately after line 18. You should spend the time necessary to completely understand this program before continuing on to the next example program. A RECURSIVE FUNCTION Example program > e_c18_p4.ada with Ada.Text_IO, Ada.Integer_Text_IO; use Ada.Text_IO, Ada.Integer_Text_IO; procedure FuncRecr is START : constant := -2; STOP : constant := 5; Result : INTEGER; Data_Value : INTEGER; -- Chapter 18 - Program 4 function Factorial_Possible(Number : INTEGER) return BOOLEAN; function Factorial(Number : INTEGER) return INTEGER is if not Factorial_Possible(Number) then Put("Factorial not possible for"); Put(Number, 4); return 0; end if; if Number = 0 then return 1; elsif Number = 1 then

Exception Handling: Control. Exception handling is the control of error conditions or other unusual events during the execution of a program.

Exception Handling: Control. Exception handling is the control of error conditions or other unusual events during the execution of a program. Exception Handling: Control Exception handling is the control of error conditions or other unusual events during the execution of a program. 1 In a language without exception handling: When an exception

More information

Introduction to Computers and Programming

Introduction to Computers and Programming Introduction to Computers and Programming Prof. I. K. Lundqvist Lecture 12 April 14 2004 The goal of an engineer is to retire without having caused any major catastrophe -Dilbert 2 Today Program robustness

More information

Chapter 14. Exception Handling and Event Handling 异常处理和事件处理. 孟小亮 Xiaoliang MENG, 答疑 ISBN

Chapter 14. Exception Handling and Event Handling 异常处理和事件处理. 孟小亮 Xiaoliang MENG, 答疑   ISBN Chapter 14 Exception Handling and Event Handling 异常处理和事件处理 孟小亮 Xiaoliang MENG, 答疑 EMAIL: 1920525866@QQ.COM ISBN 0-321-49362-1 Chapter 14 Topics Introduction to Exception Handling Exception Handling in

More information

Chapter 14. Exception Handling and Event Handling ISBN

Chapter 14. Exception Handling and Event Handling ISBN Chapter 14 Exception Handling and Event Handling ISBN 0-321-49362-1 Chapter 14 Topics Introduction to Exception Handling Exception Handling in Ada Exception Handling in C++ Exception Handling in Java Introduction

More information

1: Introduction to Object (1)

1: Introduction to Object (1) 1: Introduction to Object (1) 김동원 2003.01.20 Overview (1) The progress of abstraction Smalltalk Class & Object Interface The hidden implementation Reusing the implementation Inheritance: Reusing the interface

More information

5. Control Statements

5. Control Statements 5. Control Statements This section of the course will introduce you to the major control statements in C++. These control statements are used to specify the branching in an algorithm/recipe. Control statements

More information

Chapter 6: The C Preprocessor

Chapter 6: The C Preprocessor C: Chapter6 Page 1 of 5 C Tutorial.......... The C preprocessor Chapter 6: The C Preprocessor AIDS TO CLEAR PROGRAMMING The preprocessor is a program that is executed just prior to the execution of the

More information

Programming Languages Third Edition. Chapter 9 Control I Expressions and Statements

Programming Languages Third Edition. Chapter 9 Control I Expressions and Statements Programming Languages Third Edition Chapter 9 Control I Expressions and Statements Objectives Understand expressions Understand conditional statements and guards Understand loops and variation on WHILE

More information

Principle of Complier Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore

Principle of Complier Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore Principle of Complier Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore Lecture - 20 Intermediate code generation Part-4 Run-time environments

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Week 13 - Part 2 Thomas Wies New York University Review Last lecture Scala Outline Today: Exceptions Sources for today s lecture: PLP, ch. 8.5 Exceptions

More information

Ada LOOP statement allows for repetition of a sequence of statements Three forms of a LOOP statement FOR loop_specification LOOP...

Ada LOOP statement allows for repetition of a sequence of statements Three forms of a LOOP statement FOR loop_specification LOOP... ! "# $ % Ada statement allows for repetition of a sequence of statements Three forms of a statement FOR loop_specification WHILE condition FOR loop is used when executing a specific number of iterations

More information

Chapter 10: File Input / Output

Chapter 10: File Input / Output C: Chapter10 Page 1 of 6 C Tutorial.......... File input/output Chapter 10: File Input / Output OUTPUT TO A FILE Load and display the file named formout.c for your first example of writing data to a file.

More information

Chapter 7. - FORTRAN I control statements were based directly on IBM 704 hardware

Chapter 7. - FORTRAN I control statements were based directly on IBM 704 hardware Levels of Control Flow: 1. Within expressions 2. Among program units 3. Among program statements Evolution: - FORTRAN I control statements were based directly on IBM 704 hardware - Much research and argument

More information

The PCAT Programming Language Reference Manual

The PCAT Programming Language Reference Manual The PCAT Programming Language Reference Manual Andrew Tolmach and Jingke Li Dept. of Computer Science Portland State University September 27, 1995 (revised October 15, 2002) 1 Introduction The PCAT language

More information

Coding and Unit Testing! The Coding Phase! Coding vs. Code! Coding! Overall Coding Language Trends!

Coding and Unit Testing! The Coding Phase! Coding vs. Code! Coding! Overall Coding Language Trends! Requirements Spec. Design Coding and Unit Testing Characteristics of System to be built must match required characteristics (high level) Architecture consistent views Software Engineering Computer Science

More information

Chapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language

Chapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language Categories of languages that support OOP: 1. OOP support is added to an existing language - C++ (also supports procedural and dataoriented programming) - Ada 95 (also supports procedural and dataoriented

More information

CSE 142 Su 04 Computer Programming 1 - Java. Objects

CSE 142 Su 04 Computer Programming 1 - Java. Objects Objects Objects have state and behavior. State is maintained in instance variables which live as long as the object does. Behavior is implemented in methods, which can be called by other objects to request

More information

On 17 June 2006, the editor provided the following list via an to the convener:

On 17 June 2006, the editor provided the following list via an  to the convener: ISO/IEC JTC 1/SC 22/WG 9 N 471 List of AIs Approved per Resolution 50-8 James W. Moore, Convener 23 June 2006 Resolution 50-8 reads as follows: "Noting WG9's approval of the amendment to ISO/IEC 8652 and

More information

Catalan Numbers. Table 1: Balanced Parentheses

Catalan Numbers. Table 1: Balanced Parentheses Catalan Numbers Tom Davis tomrdavis@earthlink.net http://www.geometer.org/mathcircles November, 00 We begin with a set of problems that will be shown to be completely equivalent. The solution to each problem

More information

6.001 Notes: Section 15.1

6.001 Notes: Section 15.1 6.001 Notes: Section 15.1 Slide 15.1.1 Our goal over the next few lectures is to build an interpreter, which in a very basic sense is the ultimate in programming, since doing so will allow us to define

More information

Control Structures. Outline. In Text: Chapter 8. Control structures Selection. Iteration. Gotos Guarded statements. One-way Two-way Multi-way

Control Structures. Outline. In Text: Chapter 8. Control structures Selection. Iteration. Gotos Guarded statements. One-way Two-way Multi-way Control Structures In Text: Chapter 8 1 Control structures Selection One-way Two-way Multi-way Iteration Counter-controlled Logically-controlled Gotos Guarded statements Outline Chapter 8: Control Structures

More information

Ada 2005 An introduction for TTK4145

Ada 2005 An introduction for TTK4145 Ada 2005 An introduction for TTK4145 Kristoffer Nyborg Gregertsen Department of Engineering Cybernetics 21-10-2009 2 Contents Introduction Language basics Variables, scope and types Program flow Routines

More information

The Decaf Language. 1 Lexical considerations

The Decaf Language. 1 Lexical considerations The Decaf Language In this course, we will write a compiler for a simple object-oriented programming language called Decaf. Decaf is a strongly-typed, object-oriented language with support for inheritance

More information

QUIZ Friends class Y;

QUIZ Friends class Y; QUIZ Friends class Y; Is a forward declaration neeed here? QUIZ Friends QUIZ Friends - CONCLUSION Forward (a.k.a. incomplete) declarations are needed only when we declare member functions as friends. They

More information

Testing Techniques for Ada 95

Testing Techniques for Ada 95 SOFTWARE QUALITY ASSURANCE TOOLS & TECHNOLOGY PROFESSIONAL SERVICES ACADEMY P a g e 1 White Paper Testing Techniques for Ada 95 The Ada language is widely accepted as the language of choice for the implementation

More information

Computer Science 210 Data Structures Siena College Fall Topic Notes: Recursive Methods

Computer Science 210 Data Structures Siena College Fall Topic Notes: Recursive Methods Computer Science 210 Data Structures Siena College Fall 2017 Topic Notes: Recursive Methods You have seen in this course and in your previous work that iteration is a fundamental building block that we

More information

A Short Summary of Javali

A Short Summary of Javali A Short Summary of Javali October 15, 2015 1 Introduction Javali is a simple language based on ideas found in languages like C++ or Java. Its purpose is to serve as the source language for a simple compiler

More information

Chapter 2 Basic Elements of C++

Chapter 2 Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 2-1 Chapter 2 Basic Elements of C++ At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion

More information

(Refer Slide Time: 1:40)

(Refer Slide Time: 1:40) Computer Architecture Prof. Anshul Kumar Department of Computer Science and Engineering, Indian Institute of Technology, Delhi Lecture - 3 Instruction Set Architecture - 1 Today I will start discussion

More information

UNIT 3

UNIT 3 UNIT 3 Presentation Outline Sequence control with expressions Conditional Statements, Loops Exception Handling Subprogram definition and activation Simple and Recursive Subprogram Subprogram Environment

More information

C Language Tutorial C LANGUAGE TUTORIAL

C Language Tutorial C LANGUAGE TUTORIAL C Language Tutorial C LANGUAGE TUTORIAL This tutorial teaches the entire C programming language. It is composed of 13 chapters which should be studied in order since topics are introduced in a logical

More information

Implementing Exceptions in Open Multithreaded Transactions Based On Ada 95 Exceptions

Implementing Exceptions in Open Multithreaded Transactions Based On Ada 95 Exceptions Implementing Exceptions in Open Multithreaded Transactions Based On Ada 95 Exceptions Jörg Kienzle Software Engineering Laboratory Swiss Federal Institute of Technology Lausanne CH - 1015 Lausanne EPFL

More information

Control Structures. Control Structures 3-1

Control Structures. Control Structures 3-1 3 Control Structures One ship drives east and another drives west With the selfsame winds that blow. Tis the set of the sails and not the gales Which tells us the way to go. Ella Wheeler Wilcox This chapter

More information

1 Lexical Considerations

1 Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler

More information

Supplemental Handout: Exceptions CS 1070, Spring 2012 Thursday, 23 Feb 2012

Supplemental Handout: Exceptions CS 1070, Spring 2012 Thursday, 23 Feb 2012 Supplemental Handout: Exceptions CS 1070, Spring 2012 Thursday, 23 Feb 2012 1 Objective To understand why exceptions are useful and why Visual Basic has them To gain experience with exceptions and exception

More information

Software Design and Analysis for Engineers

Software Design and Analysis for Engineers Software Design and Analysis for Engineers by Dr. Lesley Shannon Email: lshannon@ensc.sfu.ca Course Website: http://www.ensc.sfu.ca/~lshannon/courses/ensc251 Simon Fraser University Slide Set: 9 Date:

More information

6.001 Notes: Section 1.1

6.001 Notes: Section 1.1 6.001 Notes: Section 1.1 Slide 1.1.1 This first thing we need to do is discuss the focus of 6.001. What is this course all about? This seems quite obvious -- this is a course about computer science. But

More information

CSC 533: Organization of Programming Languages. Spring 2005

CSC 533: Organization of Programming Languages. Spring 2005 CSC 533: Organization of Programming Languages Spring 2005 Language features and issues variables & bindings data types primitive complex/structured expressions & assignments control structures subprograms

More information

Room 3P16 Telephone: extension ~irjohnson/uqc146s1.html

Room 3P16 Telephone: extension ~irjohnson/uqc146s1.html UQC146S1 Introductory Image Processing in C Ian Johnson Room 3P16 Telephone: extension 3167 Email: Ian.Johnson@uwe.ac.uk http://www.csm.uwe.ac.uk/ ~irjohnson/uqc146s1.html Ian Johnson 1 UQC146S1 What is

More information

Chapter 3:: Names, Scopes, and Bindings (cont.)

Chapter 3:: Names, Scopes, and Bindings (cont.) Chapter 3:: Names, Scopes, and Bindings (cont.) Programming Language Pragmatics Michael L. Scott Review What is a regular expression? What is a context-free grammar? What is BNF? What is a derivation?

More information

Comp2310 & Comp6310 Systems, Networks and Concurrency

Comp2310 & Comp6310 Systems, Networks and Concurrency The Australian National University Mid Semester Examination August 2017 Comp2310 & Comp6310 Systems, Networks and Concurrency Study period: 15 minutes Time allowed: 1.5 hours (after study period) Total

More information

Chapter 3:: Names, Scopes, and Bindings (cont.)

Chapter 3:: Names, Scopes, and Bindings (cont.) Chapter 3:: Names, Scopes, and Bindings (cont.) Programming Language Pragmatics Michael L. Scott Review What is a regular expression? What is a context-free grammar? What is BNF? What is a derivation?

More information

Practical exception handling and resolution in concurrent programs

Practical exception handling and resolution in concurrent programs Practical exception handling and resolution in concurrent programs Alexander Romanovsky Applied Mathematics Department, State Technical University, 195251, St. Petersburg, Russia tel: +7 812 555 64 52,

More information

0. Overview of this standard Design entities and configurations... 5

0. Overview of this standard Design entities and configurations... 5 Contents 0. Overview of this standard... 1 0.1 Intent and scope of this standard... 1 0.2 Structure and terminology of this standard... 1 0.2.1 Syntactic description... 2 0.2.2 Semantic description...

More information

(Refer Slide Time: 4:00)

(Refer Slide Time: 4:00) Principles of Programming Languages Dr. S. Arun Kumar Department of Computer Science & Engineering Indian Institute of Technology, Delhi Lecture - 38 Meanings Let us look at abstracts namely functional

More information

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Weiss Chapter 1 terminology (parenthesized numbers are page numbers) Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2010 Handout Decaf Language Tuesday, Feb 2 The project for the course is to write a compiler

More information

10. Abstract Data Types

10. Abstract Data Types 10. Abstract Data Types 11.1 The Concept of Abstraction The concept of abstraction is fundamental in programming Nearly all programming languages support process abstraction with subprograms Nearly all

More information

COMMUNICATING TASKS. Week 6 Laboratory for Concurrent and Distributed Systems Uwe R. Zimmer based on material by Alistair Rendell

COMMUNICATING TASKS. Week 6 Laboratory for Concurrent and Distributed Systems Uwe R. Zimmer based on material by Alistair Rendell COMMUNICATING TASKS Week 6 Laboratory for Concurrent and Distributed Systems Uwe R. Zimmer based on material by Alistair Rendell Pre-Laboratory Checklist vvyou have read this text before you come to your

More information

Compiler Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore

Compiler Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore Compiler Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore Module No. # 10 Lecture No. # 16 Machine-Independent Optimizations Welcome to the

More information

CS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class

CS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class CS112 Lecture: Defining Classes Last revised 2/3/06 Objectives: 1. To describe the process of defining an instantiable class Materials: 1. BlueJ SavingsAccount example project 2. Handout of code for SavingsAccount

More information

Programming Languages Third Edition. Chapter 10 Control II Procedures and Environments

Programming Languages Third Edition. Chapter 10 Control II Procedures and Environments Programming Languages Third Edition Chapter 10 Control II Procedures and Environments Objectives Understand the nature of procedure definition and activation Understand procedure semantics Learn parameter-passing

More information

A simple example... Introduction to Ada95. Literals. Identifiers

A simple example... Introduction to Ada95. Literals. Identifiers Introduction to Ada95 Types and program flow control Compilation units, packages Tasks in Ada95 Protected objects in Ada95 Example from Exercise Compendium A simple example with Ada.Text_IO; use Ada.Text_IO;

More information

Fun facts about recursion

Fun facts about recursion Outline examples of recursion principles of recursion review: recursive linked list methods binary search more examples of recursion problem solving using recursion 1 Fun facts about recursion every loop

More information

CS 1044 Program 6 Summer I dimension ??????

CS 1044 Program 6 Summer I dimension ?????? Managing a simple array: Validating Array Indices Most interesting programs deal with considerable amounts of data, and must store much, or all, of that data on one time. The simplest effective means for

More information

CS 2505 Computer Organization I Test 1. Do not start the test until instructed to do so!

CS 2505 Computer Organization I Test 1. Do not start the test until instructed to do so! Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted one-page formula sheet. No calculators or other electronic devices

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a

More information

Variables are used to store data (numbers, letters, etc) in MATLAB. There are a few rules that must be followed when creating variables in MATLAB:

Variables are used to store data (numbers, letters, etc) in MATLAB. There are a few rules that must be followed when creating variables in MATLAB: Contents VARIABLES... 1 Storing Numerical Data... 2 Limits on Numerical Data... 6 Storing Character Strings... 8 Logical Variables... 9 MATLAB S BUILT-IN VARIABLES AND FUNCTIONS... 9 GETTING HELP IN MATLAB...

More information

CATCH Me if You Can Doug Hennig

CATCH Me if You Can Doug Hennig CATCH Me if You Can Doug Hennig VFP 8 has structured error handling, featuring the new TRY... CATCH... FINALLY... ENDTRY structure. This powerful new feature provides a third layer of error handling and

More information

Computer Science Lab Exercise 1

Computer Science Lab Exercise 1 1 of 10 Computer Science 127 - Lab Exercise 1 Introduction to Excel User-Defined Functions (pdf) During this lab you will experiment with creating Excel user-defined functions (UDFs). Background We use

More information

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #34. Function with pointer Argument

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #34. Function with pointer Argument Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #34 Function with pointer Argument (Refer Slide Time: 00:05) So, here is the stuff that we have seen about pointers.

More information

Statement level control structures

Statement level control structures 1 Statement level control structures CS 315 Programming Languages Pinar Duygulu Bilkent University Control Statements: Evolution 2 FORTRAN I control statements were based directly on IBM 704 hardware Much

More information

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */ Overview Language Basics This chapter describes the basic elements of Rexx. It discusses the simple components that make up the language. These include script structure, elements of the language, operators,

More information

Elaboration The execution of declarations

Elaboration The execution of declarations Elaboration The execution of declarations Examples Elaboration of a variable declaration sets up space for that variable. Elaboration of a task variable creates, initializes, and runs the task. Elaboration

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

Lecture Transcript While and Do While Statements in C++

Lecture Transcript While and Do While Statements in C++ Lecture Transcript While and Do While Statements in C++ Hello and welcome back. In this lecture we are going to look at the while and do...while iteration statements in C++. Here is a quick recap of some

More information

(Refer Slide Time: 06:01)

(Refer Slide Time: 06:01) Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 28 Applications of DFS Today we are going to be talking about

More information

142

142 Scope Rules Thus, storage duration does not affect the scope of an identifier. The only identifiers with function-prototype scope are those used in the parameter list of a function prototype. As mentioned

More information

Lecture C11: FOR, WHILE and General Loops

Lecture C11: FOR, WHILE and General Loops Lecture C11: FOR, WHILE and General Loops Response to 'Muddiest Part of the Lecture Cards' (45 respondents) 1) General comments on lecture / class. (2 students) Class is too early: Sorry not much I can

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

CSE 12 Abstract Syntax Trees

CSE 12 Abstract Syntax Trees CSE 12 Abstract Syntax Trees Compilers and Interpreters Parse Trees and Abstract Syntax Trees (AST's) Creating and Evaluating AST's The Table ADT and Symbol Tables 16 Using Algorithms and Data Structures

More information

Introduction to Computer Science and Business

Introduction to Computer Science and Business Introduction to Computer Science and Business The Database Programming with PL/SQL course introduces students to the procedural language used to extend SQL in a programatic manner. This course outline

More information

CS 2505 Computer Organization I

CS 2505 Computer Organization I Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted one-page formula sheet. No calculators or other computing devices may

More information

Topic IV. Parameters. Chapter 5 of Programming languages: Concepts & constructs by R. Sethi (2ND EDITION). Addison-Wesley, 1996.

Topic IV. Parameters. Chapter 5 of Programming languages: Concepts & constructs by R. Sethi (2ND EDITION). Addison-Wesley, 1996. References: Topic IV Block-structured procedural languages Algol and Pascal Chapters 5 and 7, of Concepts in programming languages by J. C. Mitchell. CUP, 2003. Chapter 5 of Programming languages: Concepts

More information

Comp2310 & Comp6310 Systems, Networks and Concurrency

Comp2310 & Comp6310 Systems, Networks and Concurrency The Australian National University Mid Semester Examination August 2018 Comp2310 & Comp6310 Systems, Networks and Concurrency Study period: 15 minutes Time allowed: 1.5 hours (after study period) Total

More information

arxiv: v1 [cs.se] 17 Aug 2016

arxiv: v1 [cs.se] 17 Aug 2016 Introduction to the Case Management Model and Notation (CMMN) arxiv:1608.05011v1 [cs.se] 17 Aug 2016 Mike A. Marin University of South Africa IBM Analytics Group mmarin@acm.org August 18, 2016 Abstract

More information

High Performance Computing Prof. Matthew Jacob Department of Computer Science and Automation Indian Institute of Science, Bangalore

High Performance Computing Prof. Matthew Jacob Department of Computer Science and Automation Indian Institute of Science, Bangalore High Performance Computing Prof. Matthew Jacob Department of Computer Science and Automation Indian Institute of Science, Bangalore Module No # 09 Lecture No # 40 This is lecture forty of the course on

More information

Designing Robust Classes

Designing Robust Classes Designing Robust Classes Learning Goals You must be able to:! specify a robust data abstraction! implement a robust class! design robust software! use Java exceptions Specifications and Implementations

More information

Intro. Scheme Basics. scm> 5 5. scm>

Intro. Scheme Basics. scm> 5 5. scm> Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

More information

Page 1. Stuff. Last Time. Today. Safety-Critical Systems MISRA-C. Terminology. Interrupts Inline assembly Intrinsics

Page 1. Stuff. Last Time. Today. Safety-Critical Systems MISRA-C. Terminology. Interrupts Inline assembly Intrinsics Stuff Last Time Homework due next week Lab due two weeks from today Questions? Interrupts Inline assembly Intrinsics Today Safety-Critical Systems MISRA-C Subset of C language for critical systems System

More information

Chapter 3:: Names, Scopes, and Bindings

Chapter 3:: Names, Scopes, and Bindings Chapter 3:: Names, Scopes, and Bindings Programming Language Pragmatics Michael L. Scott Some more things about NFAs/DFAs We said that a regular expression can be: A character (base case) A concatenation

More information

Chapter 8 :: Composite Types

Chapter 8 :: Composite Types Chapter 8 :: Composite Types Programming Language Pragmatics, Fourth Edition Michael L. Scott Copyright 2016 Elsevier 1 Chapter08_Composite_Types_4e - Tue November 21, 2017 Records (Structures) and Variants

More information

C-LANGUAGE CURRICULAM

C-LANGUAGE CURRICULAM C-LANGUAGE CURRICULAM Duration: 2 Months. 1. Introducing C 1.1 History of C Origin Standardization C-Based Languages 1.2 Strengths and Weaknesses Of C Strengths Weaknesses Effective Use of C 2. C Fundamentals

More information

Sequencers. Markus Roggenbach. 18. März 2004

Sequencers. Markus Roggenbach. 18. März 2004 Sequencers Markus Roggenbach 18. März 2004 Programming Languages today Programming Languages today 2 M.Broy, J.Siedersleben: Objektorientierte Programmierung und Softwareentwicklung, Informatik Spektrum,

More information

Programming Assignment IV Due Monday, November 8 (with an automatic extension until Friday, November 12, noon)

Programming Assignment IV Due Monday, November 8 (with an automatic extension until Friday, November 12, noon) Programming Assignment IV Due Monday, November 8 (with an automatic extension until Friday, November 12, noon) Thus spake the master programmer: A well-written program is its own heaven; a poorly written

More information

Principles of Programming Languages

Principles of Programming Languages Principles of Programming Languages Lecture 08 Control Semantics & Continuations Semantics of Control Flow Sequencers: commands that cause control transfers:! goto! return! exit! break! continue! resultis

More information

Topic IV. Block-structured procedural languages Algol and Pascal. References:

Topic IV. Block-structured procedural languages Algol and Pascal. References: References: Topic IV Block-structured procedural languages Algol and Pascal Chapters 5 and 7, of Concepts in programming languages by J. C. Mitchell. CUP, 2003. Chapters 10( 2) and 11( 1) of Programming

More information

Introduction. In this preliminary chapter, we introduce a couple of topics we ll be using DEVELOPING CLASSES

Introduction. In this preliminary chapter, we introduce a couple of topics we ll be using DEVELOPING CLASSES Introduction In this preliminary chapter, we introduce a couple of topics we ll be using throughout the book. First, we discuss how to use classes and object-oriented programming (OOP) to aid in the development

More information

Scope. Chapter Ten Modern Programming Languages 1

Scope. Chapter Ten Modern Programming Languages 1 Scope Chapter Ten Modern Programming Languages 1 Reusing Names Scope is trivial if you have a unique name for everything: fun square a = a * a; fun double b = b + b; But in modern languages, we often use

More information

Programming Languages

Programming Languages Programming Languages Tevfik Koşar Lecture - VIII February 9 th, 2006 1 Roadmap Allocation techniques Static Allocation Stack-based Allocation Heap-based Allocation Scope Rules Static Scopes Dynamic Scopes

More information

Chapter 14. Exception Handling and Event Handling

Chapter 14. Exception Handling and Event Handling Chapter 14 Exception Handling and Event Handling Chapter 14 Topics Introduction to Exception Handling Exception Handling in Ada Exception Handling in C++ Exception Handling in Java Introduction to Event

More information

CIS 890: Safety Critical Systems

CIS 890: Safety Critical Systems CIS 890: Safety Critical Systems Lecture: SPARK -- Analysis Tools Copyright 2007, John Hatcliff. The syllabus and all lectures for this course are copyrighted materials and may not be used in other course

More information

What Is a Function? Illustration of Program Flow

What Is a Function? Illustration of Program Flow What Is a Function? A function is, a subprogram that can act on data and return a value Each function has its own name, and when that name is encountered, the execution of the program branches to the body

More information

Chapter 6 Control Flow. June 9, 2015

Chapter 6 Control Flow. June 9, 2015 Chapter 6 Control Flow June 9, 2015 Expression evaluation It s common in programming languages to use the idea of an expression, which might be a simple object function invocation over some number of arguments

More information

Introduction to Linked Lists. Introduction to Recursion Search Algorithms CS 311 Data Structures and Algorithms

Introduction to Linked Lists. Introduction to Recursion Search Algorithms CS 311 Data Structures and Algorithms Introduction to Linked Lists Introduction to Recursion Search Algorithms CS 311 Data Structures and Algorithms Lecture Slides Friday, September 25, 2009 Glenn G. Chappell Department of Computer Science

More information

Type Checking and Type Equality

Type Checking and Type Equality Type Checking and Type Equality Type systems are the biggest point of variation across programming languages. Even languages that look similar are often greatly different when it comes to their type systems.

More information

(Refer Slide Time: 00:51)

(Refer Slide Time: 00:51) Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute Technology, Madras Module 10 E Lecture 24 Content Example: factorial

More information

Lecture Notes on Programming Languages

Lecture Notes on Programming Languages Lecture Notes on Programming Languages 85 Lecture 09: Support for Object-Oriented Programming This lecture discusses how programming languages support object-oriented programming. Topics to be covered

More information

CS125 : Introduction to Computer Science. Lecture Notes #38 and #39 Quicksort. c 2005, 2003, 2002, 2000 Jason Zych

CS125 : Introduction to Computer Science. Lecture Notes #38 and #39 Quicksort. c 2005, 2003, 2002, 2000 Jason Zych CS125 : Introduction to Computer Science Lecture Notes #38 and #39 Quicksort c 2005, 2003, 2002, 2000 Jason Zych 1 Lectures 38 and 39 : Quicksort Quicksort is the best sorting algorithm known which is

More information

Topics. Java arrays. Definition. Data Structures and Information Systems Part 1: Data Structures. Lecture 3: Arrays (1)

Topics. Java arrays. Definition. Data Structures and Information Systems Part 1: Data Structures. Lecture 3: Arrays (1) Topics Data Structures and Information Systems Part 1: Data Structures Michele Zito Lecture 3: Arrays (1) Data structure definition: arrays. Java arrays creation access Primitive types and reference types

More information