To set up and use the Rigal system as implemented at NMSU and to use Rigal to process an abstract syntax tree using pattern parameters.
1. Set up the Rigal system in your own workspace. The preferred way is to add these statements to your .cshrc. (I put them in a .rigal file that I can source when I need to use Rigal).
setenv rig /home/unsupported/solaris/rsys
alias rc /home/unsupported/solaris/rsys/rc
alias ic /home/unsupported/solaris/rsys/ic
alias printdoc /home/unsupported/solaris/rsys/printdoc
alias rc /home/unsupported/solaris/rsys/rc
alias rig_crf /home/unsupported/solaris/rsys/rig_crf
alias rig_lint /home/unsupported/solaris/rsys/rig_lint
set path = ($path $rig)
Then verify your system by running the following program:
#Go
PRINT #Sumfirst(10)
##
#Sumfirst
$N
/ IF $N = 1 -> RETURN 1
ELSIF T -> RETURN $N + #Sumfirst($N - 1)
FI /
##
2. Write a Rigal program to process an abstract syntax tree for the following grammar so that it prints a list containing all the occurrences of all the identifers used in the program.
P ::= C
C ::= C1 C2 | I := E | if E then C1 else C2 | while E do C
E ::= I | N | E1 + E2 | E1 – E2 | I = E | I > E | I < E
3. Modify the program to print a list containing only the unique names of the identifiers used (i.e. there will be no duplicates).
Use the following tree for final testing and presentation of results. Of course you will be testing your program on many such trees, but you need only turn in the results for this tree.
<. C1 : <. I : Y, E : <. N : 0 .> .>,
C2 : <. C1 : <. I : X, E : <. N : 1 .> .>,
C2 : <. I : Y, E : <. N : 2 .> .> .>
.>
(total 30 points)
September 13th. by 5:00pm.