Classwork and Homework for Section 2

Classwork

Section 2
1.  Write a program to test whether the input is in the given list. The list is a linked-list with header.  Write it in Rz.
2.  Write an Rz program to find the median of 5. The inputs are five scalar variables: a,b,c,d,e.  (using decision tree, if you can do it with 6 comparisons you are very good, with 7 you are good, more than that you are average.  Do it by yourself first because you can also look up the answer from internet but that will ruin all the fun!).
3.  What is the meaning of this regular expression?   Draw the state diagram and try to explain what it does. (Hint: you can look find it in the lecture slides).
     /* ([^*]*[^/]*)* */
4.  Write the grammar of this language P.  The following paragraph shows sample of sentences from that language:
       fun a
         a = a + a ;
         if a  then a = a ;
         a = f a ;
         ...
       end
       where  f is a built-in function.   The P language has nested if.
      Hint:  Here is how you write a grammar for a sentence like  a = a + a + a ;
asg -> a = binop ;
binop ->  a binop2
binop2 ->  + binop  | empty

Homework

Section 2
1.  Learn how to write in Rz by reading  Quick Start Rz.
2. Familiarize with the compiler tool.  Use rz33-1.zip  to compile and run your programs in the classwork1. 
     Here is what a session looks like:
     Go to rz33/test directory  (that you unzip the package to).  There are two executable files:   rz33.exe  and  somv2x.exe

    Try to compile "fac.txt".  It is shown here:

// factorial

fac(n){
  if( n == 0 ) return 1;
  else return n * fac(n-1);
}

main(){
  print(fac(6));
}
 
    Here is the command line and the output at the screen:

D:\prabhas\bag\rz\rz33\test>rz33 fac.txt
fac
main
(fun main (print (call fac 6 )))
(fun fac (else (== #1 0 )(return 1 )(return (* #1 (call fac (- #1 1 ))))))


:main
    fun.1
    lit.6
    call.fac
    sys.1
    ret.1
:fac
    fun.1
    get.1
    lit.0
                    . . .
     You will get the file "fac.obj" as an output file.  It is an object file that is executable under Som VM (a kind of virtual machine similar to JVM). You can "run" it under somv2x.

D:\prabhas\bag\rz\rz33\test>somv2x fac.obj
720

     That's it.  Enjoy!

2.  Download rz33-1  and try to compile the source.  Use the executable  rz33.exe and somv2x.exe to compile and run your program.  Then modify the scanner so that it can cope with ALL CAPS input.  (e.g.  if the source file changes to ALL CAPS, the compile reads it as if it is small caps.)  It is easy to do that  only one or two lines of code needed to be inserted into the scanner.  Your only problem is to locate where to insert it.  Hand is a few lines of explanation how you did it. 
3.  Write the grammar of P language.  Hand-in by Tuesday 14 Aug.
4.   Read how to compute  First and Follow set  (by Prof. Kamin at UIUC)

Project

section 2
Design a language for a specific purpose.  Write a report about it.  The report contains:
1)  The design of the language.  A description of the language.  The motivation of your design.
2)  Examples of use of the language, some programs.
3)  Write its grammar.
The goal of the language is (there are two projects, choose to do one):
a)  Mouse control language:  point, click, find the target...
b)  Draw diagram language:  to describe action to draw diagram (similar to Visio or Word drawing module)
The length of the report is about 4 pages.  I am interested in the "quality" of the report not the "quantity".  You should try to explain your idea in your own word. Define a language that is not trivial or is not too big.  Its grammar should be less than one page. Create interesting examples.  Write a good grammar.  This is not a language implementation issue.  We concentrate on "design".
The deadline for hand-in is 4pm, on 27 August 2012 at the box in front of my office.