Pascal - Lesson #1

Introduction

  I. Access Turbo Pascal
       A. Windows  -> Click on Turbo Pascal

  II.  Turbo Pascal Main Screen
       A. Format
           1.  Product version information
               Press any key to erase
           2.  Sections
               a. Main Menu
               b.  Edit window
               c.  Output window
               d.  Bottom line key indicators
       B. Example
   File   Edit    Run    Compile     Options   Debug    Break/watch   
/---------------------------------------------------------------------\ 
|                                       Edit                           |
|    Line 1 Col 1     Insert Indent         Unindent      C:NONAME.PAS |
|                                                                      |
|                                                                      |
|                                                                      |
|                                                                      |
|                                                                      |
|                                                                      |
|                                                                      |
|--------------------------------Watch---------------------------------|
|F1-Help F5-Zoom   F6-Switch   F7-Trace    F8-Step   F9-Make   F10-Menu|
\----------------------------------------------------------------------/
       C. Navigating basic

                1. Within any menu
                   a. Select command     -> Highlighted letter
                                         -> LEFT ARROW or RIGHT ARROW + ENTER
                   b. Leave menu         -> ESC
                   c. Pull-down menu     -> LEFT ARROW or RIGHT ARROW
                   d. Previous window    -> F6

               2.  Within Turbo Pascal
                   a. Invoke main menu   -> F10
                   b. Help               -> F1
                        (1)  Detailed help         -> ENTER
                        (2)  Particular item       -> Ctrl-F1
                        (3)  Previous help screen  -> Alt-F1
                        (4)  Exit                  -> ESC
                   c. Invoke command     -> Alt + letter
                   d. Move to keyword    -> LEFT, RIGHT, UP & DOWN ARROWS

              3. Within Edit window
                   a. zoom toggle        -> F5
                   b. Switch window      -> F6


     III.  Pull-down Menus

      File   Edit   Run     Compile        Options Debug     Break/watch
       |             |        |                 |   |          |
       |             |        |                 |   |          |
/------------------\ |  /---------------------\ |   | /-------------------------------\
| Load          F3 | | | compile       Alt-F9 | |   | | Add watch             Ctrl-F7 |
| Pick      Alt-F3 | | | Make              F9 | |   | | Delete watch                  |
| New              | | | Build                | |   | | Edit watch                    |
| Save          F2 | | | Destination   Memory | |   | | Remove all watches            |
| Write to         | | | Find error           | |   | | ----------------------------- |
| Directory        | | | Primary file:        | |   | | Toggle breakpoint     Ctrl-F8 |
| Change dir       | | | Get info             | |   | | Clear all breakpoints         |
| OS shell         | | \----------------------/ |   | | View next breakpoint          |
| Quit       Alt-X | |                          |   | \-------------------------------/
\------------------/ |                         /     \
                     |                        /       \
                     |                       /         \
/--------------------------\  /------------------\   /------------------------\
| Run              Ctrl-F9 |  | Compiler         |   | Evaluate       Ctrl-F4 |
| Program reset    Ctrl-F2 |  | Linker           |   | Call stack     Ctrl-F3 |
| Go to cursor          F4 |  | Environment      |   | Find procedure         |
| Trace info            F7 |  | Directories      |   | Integer debug       On |
| Step over             F8 |  | Parameters       |   | Stand debug        Off |
| User screen       Alt-F5 |  | Save options     |   | Display swap     Smart |
\--------------------------/  | Retrieve options |   | Refresh display        |
                              \------------------/   \------------------------/
     IV.  Lesson #1 Sample Program #1 -AEACIRCLE

          A. Required statements

               1. PROGRAM ->   PROGRAM <identifier> (<list>);
                          ->   PROGRAM areacircle;

               2. BEGIN        BEGIN

               3. END          END.

          B.   Reserved statements

               1. Comments      ->  { ... }   or   (* ... *)
                                    { Calculate the area }

               2.  VAR
                   a. REAL      ->  identifier : REAL;
                                ->        area : REAL;
                   b. INTEGER   ->  identifier : INTEGER;
                                ->      radius : INTEGER;

               3.  Operators
                   a. :  -> do the following
                   b. := -> becomes

               4.  Output statements
                   a. WRITELN   ->  WRITELN (...); or WRITELN('...');
                                ->  WRITELN (LST,' ... ');
                                ->  WRITELN ('This is a message.');
                                ->  WRITELN (3 * 5);
                                ->  WRITELN ('The product 3 *  5 = ', 3 * 5);
                   b. WRITE     ->  WRITE (...); or WRITE ('...');
                                ->  WRITE ('...' :w :d);
                                ->  WRITE ('Hello ');
                                    WRITELN ('world');

               5. Input statements
                   a. READLN -> READLN ( );
                             -> READLN (radius);
                   b. READ   -> READ ( );

          C. Create the program

               1.  Invoke main menu      -> F10

               2.  Access Edit window    -> select Edit

               3.  Key the program
                   a. Status line        -> cursor on line I col 1
                   b. Press ENTER after each line
                   c. Indent for program readability
                   d. Program list

                    PROGRAM areacircle;
                    { Sample program #1              }
                    { Calculate the area of a circle }
                    { Written by name on mm/dd/yy    }
                    VAR
                       radius  : REAL;
                       area    : REAL;
                    BEGIN
                         WRITELN ('Calculate the area of a circle.');
                         WRITELN;
                         WRITE ('Please input a value for the radius: ');
                         READLN (radius);
                         area := 3.14 * radius * radius;
                         WRITELN ('Area = ', area :8 :2);
                    END.

               4.   Edit keys
                    (a)  Move to word        -> LEFT, RIGHT, UP, and DOWN arrows
                    (b)  Delete character    -> BACKSPACE or DELETE
                    (c)  Delete line         -> Ctrl-Y
                    (d)  Insert line         -> ENTER

          D. Compile the program

               1. Invoke main menu    -> F10
               2. Access compiler     -> select Compile
               3. Pull-down menu      -> select Compile
               4. compilation screen
                  
                  /--------------Compiling to Memory------------\
                  |                                             |            
                  |                                             |
                  |   Main file: NONAME.PAS                     |
                  |   Compiling: EDITOR - NONAME.PAS            |
                  |                                             |
                  |                             Total     File  |
                  |   Lines compiled:           14        14    |
                  |                                             |
                  |   Available memory:            233K         |
                  |                                             |
                  |   Success         :           Press any key |
                  \---------------------------------------------/

               5.   Compilation errors
                    a.  Compilation returns to Edit window
                    b.  Error # appears at the top of the screen
                    c.  Blinking cursor on the incorrect line
                    d.  Edit the error
                    e.  Compile again

         E. Execute the program

              1.  Resident program must appear in Edit window
              2.  Invoke main menu -> F10
              3.  Access Run       -> select Run
              4.  Pull-down menu   -> select Run
              5.  Execution returns to Edit window

         F.   Save the program
              1.  Invoke main menu -> Flo
              2.  Access the file  -> select File
              3.  Auto replace the previous file
                  Pull-down menu   -> select Save
              4.  New program
                  Pull-down menu   -> select Write to
                  /----New Name----\
                  | A:filename.PAS |
                  \----------------/

         G. Print the program

              1. Invoke main menu -> F10
              2. Select the file  -> select File
              3. Pull-down menu   -> select Load or Pick
              4. Select: LISTER.PAS

                  /------------------Verify---------------\
                  | A:LESSON1.PAS not saved.  Save? (Y/N) |
                  \---------------------------------------/

              5.  LISTER.PAS appears in Edit window
              6.  Invoke main menu -> F10
              7.  Execute the file -> select Run
              8.  Pull-down menu   -> select Run
              9.  Enter filename: Key  the filename
             10.  Invoke main menu -> F10

         H. Retrieve the program

             1. Invoke main menu   -> F10
             2. Select the file    -> select File
             3. Pull-down menu     -> select Pick


                  /--Recent-Files---\
                  | NONAME.PAS      |
                  | LESSON1.PAS     |
                  | -- Load file -- |
                  \-----------------/

                  /--Load File Name---\        /--Load File Name---\
                  | *.PAS             |        | A:*.PAS           |
                  \-------------------/        \-------------------/

             4. Pull-down menu      s. select Load

                  /--C:\TURBO\*.PAS---\        /------A:\*.PAS-----\
                  | LISTER.PAS  ..\   |        | LESSON1.PAS       |
                  \-------------------/        \-------------------/

             5. Use LEFT or RIGHT ARROW to highlight file
             6. Press ENTER

        I. Edit the program

             1. Reserved statements
                 a. USES     -> Uses
                             -> Uses CRT;
                 b. CONST    -> CONST
                             -> CONST
                                    identifier = value;
                                            pi = 3.14;
                 C. CHAR     -> identifier : CHAR;
                             ->       answer : CHAR;
                 d. CLRSCR   -> CLRSCR;
                 e. UPCASE   -> UPCASE(identifier);
                             -> UPCASE(answer);

             2. Repetitive statement
                REPEAT ... UNTIL -> REPEAT
                                      .
                                    UNTIL(identifier) = value
                                 -> REPEAT
                                      .
                                    UNTIL UPCASE(answer) = 'N'

             3. Edit the program - Lesson #1 Sample Program #2
                a.  Uses CRT;
                b.  CONST
                c.  pi = 3.14;
                d.  answer : CHAR;
                e.  CLRSCR;
                f.  REPEAT
                g.  WRITE ('Do you want another area (Y/N)?');
                h.  READLN(answer);
                i.  UNTIL(answer) = 'N'

         H. Compile the program

         I.  Execute the program

         J.  Save the program

         K.  Exit Turbo Pascal
             1. Invoke main menu -> Flo
             2. Select the file  -> select File
             3. Pull-down menu   -> select Quit