Lecture 7 - September 18, 2007

 

ACM meeting tomorrow night at 7pm in ISAT/CS 243

 

 

Additional problems with First FORTRAN program.

-1

variable used before set

-1

leaving off  .exe extension

-2

labels defined but not used

-2

use of literals in sub program calls

-1

using do… end do

-1

wrap around

-1

inaccurate prompts

-3

truncated averages

-1 each

erroneous language comments

 

not using contiuue

-2

missing only 1 return statement

-1

sum = 0

-1

not using logical variable when should

-2

missing 1x in output format statement

-2

description of purpose doesn't describe task

-1 each

unnecessary declaration

-2

missing executable name

-1 each

too many places after decimal point

 

comments must be dark enough to read

 

 

 

Additional discussion points re: FORTRAN program 1

 

      FUNCTION AVG (A, N)

      DIMENSION A(N)

        SUM = 0.0

        DO 10 I= 1,10

           SUM = SUM + A(I)

10    CONTINUE

        AVG = SUM/N

        RETURN

        END

 

SUM should be initialized to 0.0  not 0  or it could be initialized to A(1) and have the loop go from 2,10

Although this version of FORTRAN permits it, try not to use the function name on the right hand side of the assignment operator

 

CORE handout activity

 

A grammar consists of 4 elements:  a set of terminals, a set of non-terminals, a set of productions, a start symbol

All non-terminals must be replaced by other non-terminals or terminals until there are no more non-terminals

The start symbol is the only non-terminal that appears only on the left hand side of the rules.

Below is a simple program in mini-language CORE

 

program

     A : integer;

begin

    A := 0;

end;

 

BNF does not specify implementation details

BNF does not indicate operating system to be used

BNF does not tell us how big an integer can be stored

BNF does not tell us how long an identifier can be

BNF can not tell us that variables beginning with I-N are by default integer variables in FORTRAN

The BNF does not tell us whether we can have blank lines in the program

The BNF does not tell us whether the program is written with multiple statements on a line or not