CS 430 – SEPTEMBER 14th NOTES, 2:00 CLASS

courtesy of Willis Vandevanter

 

We started the class by reviewing the homework. Specifically, someone asked about Question 11    on pg 171.

 

pg 171 Q11

 

Terminal Symbols

terminals {a,b}

non-terminals{<S>, <A>, <B>}

 

Language:

<S> -> <A> a <B> b

<A> -> <A> b | b

<B> -> a <B> | a

 

a) baab

  - To solve we can draw the Tree Diagram:

                         S

                     /   |   |     \

                 <A> a <B>   b         

                    |         |

                    b        a

 

 

 The tree can be drawn for this string, therefore, this string is within our language.

b) bbbab

                          S

                     /   |   |     \

                 <A> a <B>   b         

                /   |         |       

           <A>  b        b

         /    |    

     <A>  b     

        |

        b

 

The tree cannot be drawn for this string (there are required to be at least 2 b’s to finish the string), therefore, this string is not within our language.

 

Alternate  Language would add Epsilon which is an erasing rule and then the string bbbab could be generated.

<S> -> <A> a <B> b

<A> -> <A> b | b | Epsilon

<B> -> a <B> | a | Epsilon

 

 

10.

  Language:

   <S> -> <A> <B> <C>

   <A> -> a <A> | a

   <B> -> b <B> | b

   <C> -> c <C> | c

 

In English, we describe this as 1 or more a's, followed by 1 or more b's, followed by 1 or more c's.

 

Examples given by this language:

  abc, aabbcc, aabcccccc ...

 

 

Homework 1

Next, we discussed the output of our homework programming assignment with an input of less than 80 digits.

  3 Input statements students used were:

 

READ(5,101,ERR=115) (ONE(I), I=1,40)   =>OUTPUT=> Replaced the rest of the array with zeros

 

       READ(5,10) (NUMBER(M), M=1,40)

10   FORMAT(40I2)   =>OUTPUT=> caused the program to fail

 

10  FORMAT(40F2.1, 0X)

      READ (5,10,ERR=99) (A(I), I=1,40) =>OUTPUT=> caused the program to hang

 

The Force2.0 compiler zeros out arrays which is why the array ends in all zeros.

 

We can also put in END = in replace of ERR = .

 

Pseudo-Random Number Generation using Force2.0

The function for psuedo-random number generation is RAND().

eg/

   DO 10 I = I,10

       x = RAND ()

       WRITE (6, *) X

10 CONTINUE   

     STOP

     END

 

output:

   .01699992

   .01699992

   .01699992

   .01699992

..........

   .01699992

 

The problem with above is that it the random function is based on the system clock and the function generates numbers so quickly that the clock never has time to increment.

 

eg 2/

      x = RAND (37)

       WRITE (6, *) X

   DO 10 I = I,10

        X = RAND(IFIX(7*X))

10 CONTINUE   

     STOP

     END

 

NOTE: RAND chooses a number between 0 and 1

- We multiply our original random seed by a prime number, randomize that number, and that gives us a larger diversity of random numbers. This is not a completely random function as it creates some repeat numbers.

 

 

ON BATCH FILES AND PASCAL

Pascal.bat contains:

     path=%path%;C:\Dev-pas\bin;

 

Search for this:

  PascalPath.bat

 

Put this file in the desktop and run it from the command line.

 

Suggested cmd line input:

    c:\  path > oldpath.bat

 

HOMEWORK:

   - Review the link about pascal information. Get a copy of FreePascal.