Homework 5

Instructions: Work through the following problems and record your answers. On completion of your work, THEN access the BlackBoard system. Once you access the BlackBoard system you will NOT be able to back out to rework your answers.

  1. What do you think the output from the following section of FORTRAN code will be?
         isum = 0
         i = 1
     20  if (i .gt. 4) goto 30
           isum = isum + 1
           i = i + 1
           goto 20
     30  write(*,*) isum

  2. What to you think is the value of result after execution of the following COBOL code? Assume that initial has the value 100.
     move initial to index.
     add 1 to index.
     add initial to index.
     add initial to index giving result.

  3. Which procedural language might be most appropriate for a program to do each of the following applications?
    1. Compute trajectories for a satellite launcher.
    2. Monitor an input device feeding data from an experiment to the computer.
    3. Process the day's transactions at an ATM (automated teller machine).
    Briefly explain your answers.

  4. Consider the following Lisp expression:
      (car (cdr (cdr (list 16 19 21))))
    Give a trace of the evaluation of the expression. This simple trace does not have to be in tabular form; just show the resulting expression after each step of the execution.

  5. Describe in English what the following Lisp function does:
     (define (doit L)
       (list (car (cdr L)) (car L))

  6. Consider the following (Prolog) facts:
     parent-of(eli, bill)
     parent-of(mary, bill)
     parent-of(bill, joe)
     parent-of(bill, betty)
     parent-of(bill, sarah)
    where parent-of(bill,sarah) states that Bill is a parent of Sarah.

    1. Give a Prolog rule father-of(X,Y) which is true when X is the father of Y.

    2. Give a Prolog rule daughter-of(X,Y) which is true when X is a daughter of Y.

    3. Give a Prolog rule ancestor-of(X,Y) which is true when X is an ancestor of Y.

  7. Consider the following finite state machine:

    1. Complete the table below corresponding to this FSM diagram:

      Current State Current Char Next State
      =>A ( B
      B a C

    2. Which of the following strings will be accepted by the FSM shown above?
      1. (a)
      2. (aa)
      3. (aba)
      4. ((aba))
      5. (abba)

  8. Consider the following table of tokens and corresponding token-ids (taken from Fig. 9.3 in Schneider & Gersting):

    symbol 1
    number 2
    = 3
    + 4
    - 5
    ; 6
    == 7
    if 8
    else 9
    ( 10
    ) 11

    For the following language fragment,

    if (c == 50) ifx = 1; else y = ifx + 44;
    complete the lexeme/token-id table shown below:


  9. Consider the following BNF syntactic specification:
       <S> ::= x<S> | <A>
       <A> ::= (<B>)<C>
       <B> ::= y<B>y | yy 
       <C> ::= z<C> | z
    Which of the following strings can be produced from this specification?
    1. x(yy)z
    2. (yyyy)z
    3. x(y)zzz
    4. (yy)z
    5. xx(yy)zz

Last updated 2001/11/28