Today's exercise involves using BNF to examine the syntax of the construct that provides selective execution in each of our four languages. More precisely, we will use BNF to study the if construct in each of our languages.
The problem we will study this week is this: given the name of an academic year (i.e., freshman, sophomore, junior, senior) what is the corresponding integer code (i.e., 1, 2, 3, or 4)?
Begin by going to your 214/labs/ directory, making a new directory for this lab exercise, and copying the code skeletons YearCodes.java, year_codes.adb, year_codes.clj, and year_codes.rb from the course directory (/home/cs/214/labs/03/) into your new directory. Each of these skeletons provides a "driver" program to test a function that solves this problem, using the following simple algorithm:
1. Get year (a string) from the user. 2. Display the code corresponding to year.To perform step 2 of this algorithm, each "driver" displays the integer returned by a function yearCode() that, given year, returns the corresponding integer. The algorithm that we will use for this function is as follows:
if year is "freshman", then
return 1;
else if year is "sophomore", then
return 2;
else if year is "junior", then
return 3;
else if year is "senior", then
return 4;
else
return 0;
We will thus be implementing this algorithm in each of our
four languages.
Like last week, we will lead you through the process using Java, after which you will apply the same techiques to solve the problem in the other three languages. You should begin with the Java Introduction; the order in which you do the other three does not matter.
Turn in. Each of the four parts requires you to create files containing source code and execution traces. When you have completed them, use cat to create a single file that contains all of your results:
cat script.java script.ada script.clojure script.ruby > lab03-resultsThen submit your work by copying that single file into your personal folder in /home/cs/214/current/:
cp lab03-results /home/cs/214/current/yourUserName
replacing yourUserName with your login name.
The grader will access and grade your results from there.