Section 3
1) Recursive programming. Write a program to find sum of all
elements in an array, without using loop (recursion only). You can
use the size of the array as a parameter or the "last" element as 0
(sentinel).
2) Write a grammar for a love letter. Define your own style of the
letter.
Section 3
1. Learn how to write in Rz by reading Quick
Start Rz.
2. Download and compiler the compiler used in this class (rz33-1.zip).
Use whatever compiler for C that you are familiar with and compile it. Try
it out to compile some simple program. For recommended free C
compiler, see Tools section below.
3. Modify the compiler to run only as scanner then modify the
scanner to accept a new word "chaiyo" in the source.
Here is the steps to modify the compiler to run only as "scanner".
3.1 Go "main()" in "compile.c" add the following
line to call "lex()" (a scanner function) repeatedly.
readinfile(source);
prolog();
testlex();
exit(0);
void testlex(void){
mylex();
while( tok != tkEOF ){
printf(" ");
prtoken(tok);
mylex();
}
}
// print token
void prtoken(int tk){
. . .
case tkIDEN: printf("%s",
tokstring); break;
case tkNUMBER: printf("%s",
tokstring); break;
case tkSTRING:
printf("%c%s%c",34,tokstring,34); break;
case tkEOF: printf("eof");
break;
}
}
}
C:\rz33-1\comp\lcc>rz33 fac.txt
( n ) { if ( n == 0 ) return 1 ; else return n * fac ( n - 1 ) ; }
main ( ) { p
rint ( fac ( 6 ) ) ; }