Discussion of intro_all.adb





Introduction





Comments, Program Structure, Context Clauses, Use Clause





Comments



Problems with Block Comments

  1. Consider this:
        /* x = 3;           * /
        y = 4;         
        /* z = 5; */
        
  2. Did you catch the error above? Now consider this:
        /* Startup
        x = 3;     
        /* Reset count  */
        count = 2 * x;
        
  3. And this:
        /* x = 3;      
        y = 4;         
        /* Come back and think about z's value
         * z = 5; 
         */
        
  4. This C code ...
        int i = 98;
        int * p = & i;  /* pointer p points to i */
        i = i / *p;         
        i = /* say something about the expression here */
        -4;
        printf("%d\n", i); /* result is -4 */
        
  5. ... gives different results from this C code:
        int i = 98;
        int * p = & i; 
        i = i /*p;          -- Starts a comment!!!
        i = /* say something about the expression here */
        -4;
        printf("%d\n", i); /* result is 94 */
        
  6. Different results in C and C++ (from Stroustrup):
        int b = a//* divide by 4 */4;
        -a;
        
  7. Is nesting allowed?

  8. You don't need to know C to see that lots of problems can arise!
  9. Some examples from Van Tassel, 2004 web paper


Program Structure: Three sections

      -- 1. Context Clauses:
   with ...         

   procedure intro_all ...
      -- 2. Declaration Section
   begin
      -- 3. Executable section
   end intro_all;


Context Clauses: With Statements and Packages



With Statement: Motivation and Comparison



Fully Qualified Names and Use Statements



Main Program, Identifiers, Declarations





Procedure intro_all



Compare and Contrast with Java



Rules for Identifiers



Declarations: Variables, Constants, Named Numbers



Standard Types, Literals, IO Libraries





Standard Types



Range Constraints



Types Natural and Positive



Literals



New Literals: Enumerated Types



Ada.Text_IO: put_line and other I/O routines



Ada.Integer_Text_IO



Keyword Parameters



Default Parameters



Ada.Float_Text_IO



Operators, Precedence, Strong Typing, Conversions, Attributes





Operator Precedence and Associativity



Arithmetic Operators



Not Equal



Boolean Operators



Character and String Concatenation



Short Circuit Forms



In Operator



Unary Minus



Strong Type Checking



Implicit and Explicit Conversions



Caution: Conversions and Integer and Floating Point Conversion



Type Checking Rules



Type Checking and I/O



Type Attributes



Control Structures





For Loops



More on For Loops



Three Kinds of Loops



While Loops



General Loops



Loop and a Half



If Statements



Compound Parts of If Statements



Contrast elsif and else if



Case Statement