Select this to skip to main content [CSUSB] >> [CNS] >> [Comp Sci Dept] >> [R J Botting] >> [CSci620] >> 08 [Source]
[Index] [Schedule] [Syllabi] [Text] [Labs] [Projects] [Resources] [Search] [Grading]
Mon Apr 26 10:07:05 PDT 2004

Contents


    CSCI620 Session 8

      Previous

      [ 07.html ]

      Preparation

      Chapter 5 pp99-116: In the Beginning there was FORTRAN... Prepare some notes and at least one question you need to ask on it.

      Topics

        Attributes of a good language

        Von Neumann Architecture

        FORTRAN

        [ FORTRAN in resources ]

      . . . . . . . . . ( end of section Topics) <<Contents | Index>>

      Questions

        Acknowledgment

        I'd like to thank Dr. Gomez [ http://www.csci.csusb.edu/egomez/ ] for his valuable contributions in this class.

        What is Control

        We use the term control as short hand for flow of control. It is how a program chooses the next thing to do.

        In FORTRAN the flow of control is done by jumping from one place to a label somewhere else in the program.

        In the whole family of languages descended from Algol 60 most of the flow of control is done be control structures that have easily recognized beginnings and endings. Pascal and nearly every other language uses this syntax and semantics.

        Why? using a structured approach shows you a while at the start of the loop. In FORTRAN you don't know its a loop until you get to the GOTO 10. These are easily missed by programmers.

        Explain FORMAT input on page 105

        Note: you don't need this for the final. But it is an interesting example of a strange idea. On the other hand, if you plan to write any FORTRAN you have to master FORMAT.

        It is based on the need to pack a lot of data on 80-column cards. The tradition was to divide the card into fields and give each on a fixed format:
        Field
        5 digit floating point number with 3 decimal places
        Skip two columns
        3 digit integer
        7 digits of floating point with 2 decimals
        These formats are imposed on the data. If there is no decimal point, and the format specifies one.... then it is put into the data on top of any digit typed their(surprise!).

        Another example: space become zeroes inside numeric formats.

        My rules: (1)Write your input to FORTRAN on a coding sheet marked with the fields and digits. (2) Always input data to FORTRAN with an explicit decimal place.

        Watch out for this in the lab!

        Explain Prefix, Infix, Postfix.

        FORTRAN introduced Infix notation into programming languages. Here the operator is fixed in between the operands. This notation goes back to algebra.
         		1+2*3
        It has become natural for most people. Nearly all programming language use it. It has ambiguities that are handled by laws of precedence and associativity.

        In a prefix notation the operator is put first

         		+ 1 * 2 3
        In functional prefix there are parentheses as well
         		+ (1, * (2, 3))
        A prefix notation is also called Polish after a famous Polish logician.

        In post fix, as in German, the operator comes last:

         		1 2 3 * +
        This was used in some HP calculators. It also called reverse Polish notation. It has the advantage that it is easy to evaluate expressions using a single stack: values are pushed on to the stack, each operator pops off two items and pushes the result. Several computers were designed with a stack in the ALU as a result.

        In most programming languages you must use infix notation.

        In LISP you must use a form of prefix notation (+ 1 2).

        In the Pop language you could use any of these notations as you wished.

        In Prolog you can use prefix functional notation or infix if you wish. +(1,2) = 1+2.

        In C++ you use infix notation, but there is a function associated with an operation is declared using functional prefix notation!

        Each notation has advantages and disadvantages. Infix is the dominant one.

        Is whitespace significant in FORTRAN?

        FORTRAN allocates the first 6 or 7 spaces on a line a special meaning: The first space is normally blank but a non-space non-digit indicates a comment! Then digits indicate statement labels. BUT the 6th (7th?) column indicates that the line is a continuation of the previous line.

        After this initial field white space is IGNORED except in strings

         		'+  HI  +'
        and so called Hollerith formats
         		8H+  HI  +
        where the the number indicates how many characters are in the string.

        Otherwise, white space is ignored...... UNTIL the last 6 or 7 columns of an 80 column card which are reserved for a sequence number!! This number was optional, but was a life saver when you dropped a pack of 1,000 cards on the floor and needed to get them back in order. 3 passes threw a punch-card tabulator-sorter and your program was re-assembled.

        Explain how IF(A-B)10,20,20 does A<B in Arithmetic ifs

        The numbers are labels not values. If A-B has a value less than zero then we jump to the statement labeled 10 otherwise if it is zero we go to the second label(20), and if greater than zero we go to the third label (20 again). For example instead of
         		if(A<B)cout << "A<B\n"; else if(A==B)cout <<"A=B\n"; else cout <<"A>B\n";
        we write
         		IF(A-B)10,20,30
         	10	WRITE(5,110)
         		GOTO 40
         	20	WRITE(5,120)
         		GOTO 40
         	30	WRITE(5,130)
         	40	CONTINUE
         	110	FORMAT(' A<B')
         	120	FORMAT(' A=B')
         	130	FORMAT(' A>B')

        Notice that FORTRAN IV is not easy to read. The formulas are OK. The control flow takes careful thought and analysis to understand. There is NO simple way to figure out if a test is A<B or A>=B. You have to find the labels and see what they are attached to.

        As time went on FORTRAN evolved to have all the control structures that we expect in modern languages.

        This a good example of poor locality of reference.

        Explain locality of reference.

        A program has good locality of reference if you can see the what is going one without hunting on other pages/screens.

        As an example on page 133 the meaning of the first 2 lines can not be figured out with out looking at the last 2 lines! This is poor locality of reference.

        A reference is local if it refers to something nearby.

        When the references are to lines a long way away then the program is harder to read.

        The computer, executing the program, has to jump about more as well. This slows down the execution of the program because of the way virtual memory works.

        Page 101 what does it mean about error messages being a good attribute of a language

        You may have spent many hours trying to figure out an error message like
         		Parse error somewhere before line 1234
        This kind of error is not exactly helpful. The compiler writers knew this. The problem is that in C++ it is very hard to diagnose what the programmer has done wrong. It takes experience and intelligence in C++. I recently wasted several minutes because I used 'delete' as a function name when it is a reserved word (DUH!) and the compiler's error message was not explicit.

        Other languages: COBOL and Pascal for example, are designed to make it easy to spot what has gone wrong. They use more reserved words for a start! They have a carefully designed grammar that is easier to parse. So compilers for these languages help you find syntax errors quickly. (However the typical list of 1000 error messages for COBOL is a bit sick).

        Pascal and Ada go further. They aim to stop you running any program that is likely to crash or misbehave. Many mistakes that in C++ crash the system are detected by an Ada compiler and no program is produced. As a result novice Ada programmers crash the computers less than novice C++ programmers, in my experience.

        The language C went in a different direction. It was designed for very good programmers (6 friends!) to write code and so it trust the programmer and produces code that is sometimes patently dangerous. The assumption is that the programmer was just being rather clever. An example, is that types are not checked in function calls. Some horrible errors have occurred as a result. Neither is any checking done on the amount of data being stored in a piece of memory. If it overrides the program this is assumed to be what the programmer wanted. These buffer overruns are the commonest way that viruses get into computers (other than naive or forgetful people clicking attachments).

        Conclusion: a language should be designed so that a compiler can protect the programmer from there own stupidity. We need good error messages. We need to be stopped from putting bugs in code. Good language design helps.

        Explain feature interaction and orthogonality

        Orthogonality means that any feature can appear in any context.

        We also would like the meaning or effect of the feature to be similar in all the different contexts.

        In good language we can grasp the meaning of a feature once and not have to figure out what it means each time it is used.

        Here is one bad interaction I wasted time on some years ago. I wanted to kill long running FTP jobs on our FTP server. I needed to compare times on a 24-hour clock. I was using a language called awk. I wrote

         		if( t1 < t2 ) ..... else ...
        and was surprised when it said that 10 was less than 9. Click here [ Puzzle Answer ] to see the explanation.

        Here is another bad feature interaction. In Pascal the priorities of the operators are such that

         		if 1 < 2 and 3 < 4 then...
        means
         		if 1 < (2 and 3) < 4 then...
        Sometimes the result compiles (false <true in Pascal) and runs and is buggy.

        Can you explain how to prove that all GOTOs can be removed from a program.

        No time. It is true. There were 100s of papers on this between 1969-1980. Why not find one and prepare a report and presentation on the how it is done.

        What do we replace GOTOs by?

        The classic structures are called the D or Dijkstra structures.
        Nameabstract syntax
        sequence...;...;...;...;
        selectionif then else fi
        iterationwhile do od

        What are Language levels?

        A low level language is one that is like machine code:
         		add	i	1	i
        A high level is closer to mathematics or English
         		i=i+1;

        What and Why is Coherence?

        Coherence indicates that a language is easier to understand. It indicates a single mental model.

        Incoherence means a mixture of models are needed: a machine code and recursion, for example.

        What is the FORTRAN CONTINUE?

        This is not the Java/C++/C continue which jumps you to the end of a loop.

        The FORTRAN CONTINUE does nothing.

        It's purpose is so you have a place to put a label. Typically you need it at the end of a loop. It has become a good practice to end all DO loops in FORTRAN with a matching CONTINUE.

        The CONTINUE can also be used as the end point where several GOTOs and IFs come together.

        In the FORTRAN WRITE is the first character always special?

        Yes. The hardware (of those days) looked at the first character in the line to figure out how many lines (zero, 1, a page) to skip before this output occurs.
        Fist CharResult
        SpaceAdvance one line
        1Advance one page
        This semantics has been maintained on printers and displays that don't work like the old printers.

        Explain back-wards compatible.

        If old programs still work with a new compiler or version of the language we say it is back-wards compatible.

        When features are removed or changed, this breaks down. It takes work to fix the consequences.

        Sometimes an old compiler will be kept running for decades so that old software can still be used.

        Also not the word deprecated!

        What is deprecated?

        A deprecated feature is something that will be removed in a future version of a language. It means that you should stop using it now!

      . . . . . . . . . ( end of section Questions) <<Contents | Index>>

      Exercises

        TBA

      . . . . . . . . . ( end of section Exercises) <<Contents | Index>>

      Laboratory

      [ lab08.html ]

      Next

      Chapter 5 pp117-125 Pascal and Data types [ 09.html ]

      Puzzle Answer

      In awk the comparison was of the strings t1 vs t2. "10" is before "9" in the alphabetical order! I had to write
       		if( t1+0 < t2 )....
      to force an arithmetic comparison.

    . . . . . . . . . ( end of section CSCI620 Session 8) <<Contents | Index>>

    Glossary

  1. BNF::="Backus-Naur Form", for syntax and grammar, developed by Backus and Naur.
  2. EBNF::="Extended " BNF.
  3. HTML::= "HyperText Markup Language", used on the WWW.
  4. HTML_page::syntax= "<HTML>" head body.
  5. Java::="An " OO " Language from Sun".
  6. LISP::= "LISt Processing Language".
  7. LRM::="Language Reference Manual".
  8. OO::="Object-Oriented".
  9. Prolog::="Programming in Logic".
  10. TBA::="To Be Announced".
  11. UML::="Unified Modeling Language".
  12. URL::=Universal_Resource_Locator,
  13. Universal_Resource_Locator::syntax= protocol ":" location, where
    Net
    1. protocol::= "http" | "ftp" | "mailto" | ... ,
    2. location::= O( "//" host) O(pathname).

    (End of Net)
  14. WWW::= See http://www.csci.csusb.edu/dick/cs620/, index to web site for this class.
  15. XBNF::="eXtreme" BNF, developed by the teacher from EBNF, designed to ASCII input of syntax, semantics, and other formal specifications.


Formulae and Definitions in Alphabetical Order