^CSE2304^

Pracs 1(A) and 1(B), CSE2304, CSSE, Monash, Semester 1, 2003

Candidate: You must prepare your solution to this programming exercise in advance. The designated platform, on which your solution must be demonstrated and on which it will be marked, is the `gcc' compiler running on `Linux'. If you develop a solution on another platform, it is your responsibility to ensure that it works correctly on the designated platform. Read the information under the [prac' guide], [on C and code modularity], [missed pracs] and [plagiarism] links on the home page. It is better to have a program that does only part of the prac' but that compiles and runs than to have a more complex program that crashes or, even worse, does not compile. So keep copies of old working partial solutions.

Unless otherwise noted, you must write all the code yourself, and may not use any external library routines, standard I/O (e.g. printf) and mathematical (e.g. log) routines excepted.

Prac's are marked on the performance of the program and on your understanding of it. I.e. Perfect program with zero understanding => zero marks! (``Forgetting'' is not an acceptable explanation.)

The on-line versions of the prac's may include [links], corrections and supplementary material and are to be taken as the reference documents.

Demonstrators: Are not obliged to mark programs that do not compile or that crash. Time allowing, they will try to help in tracking down errors, but they are not required to mark programs in such a state, particularly those that do not compile.

NB. Note that each week's prac' groups are set their own specific problems. Make sure that you do the correct problem for your week! You will get zero marks if you solve the wrong problem.

The exam, and the prac' work (1--5), are both hurdles (50%) for CSE2304. If you fail one, or the other, or both, the highest mark that you can get is 44%(N).

Both prac's are based around a parser for ``well-formed formulae'' (boolean expressions, e.g. p and q or not r) [~lloyd/tildeProgLang/C/Wff/] that you will need to copy, compile, run, and modify to do your prac'.
Objectives:
1. To experience modifying an existing program (which is much more common in industry than writing a new program).
2. To learn something about parsing.
3. To revise recursion and trees.

Prac 1(A), week 3, 17-21 March 2003

A R G B

[In graphics], colours are often represented by 32-bit integers, i.e. hexa-decimal ARGB16 where `A' or alpha, represents transparency, `R' red, `G' green, `B' blue. We will not consider `A' (alpha) which leaves us with 24-bit RGB16 values, e.g. black=#016, white=#FFFFFF16, red=#FF000016, green=#00FF0016, blue=#0000FF16, yellow=#FFFF0016, etc..

Task: Modify the parser so that it:
1. Accepts (a) hexa-decimal constants and (b) the names of at least 8 predefined colours (e.g. red, green, blue, etc. ...), as operands.
[3 marks]
2. Interprets the boolean operators (and, or, not) as bit-wise operators on colours. And accepts any valid colour exression and rejects any invalid colour exression (e.g. gren+red or #0FFFFF and unknowncolour).
[1 mark]
3. Evaluates a given colour expression and prints the answer as a hexa-decimal number. e.g. (red or green) and not #F00000,   answer = #0FFF0016
[2 marks]
Full marks can only be obtained if the program is elegant, commented, well tested (with evidence), efficient, and totally correct.
Colours: #FFFFFF, #FF0000, #00FF00, #0000FF, #FFFF00, #FF00FF, #00FFFF, #0FFF00.

Prac 1(B), week 4, 24-28 March 2003

The `shell', or command-line interpreter, of an operating system reads from the keyboard and parses the commands typed by the user. These may be atomic commands, e.g.
ls     -- list the current directory
cat filename     -- cat(enate), i.e. print a named file
or compound commands, e.g.
ls; cat filename     -- first ls, and then cat...
c1 | c2     -- pipe the result of command c1 into c2
and combinations of the above.
 
Task: Modify the parser so that it:
1. Accepts the operators `|' and `;' (instead of the current boolean operators). Which of `|' and `;' has the higher priority?
[2 marks]
2. Accepts a basic command (i.e. a sequence of alphanumeric names and/or numbers for our purposes) as an operand. And rejects any invalid command, e.g. cat f | (lpr.
[2 marks]
3. Prints a fully parenthesized representation of an input command line so that the association of operators, atomic commands and parameters is clear.
[2 marks]
NB. You do not have to implement the full set of shell operators, nor execute the commands!
Full marks can only be obtained if the program is elegant, commented, well tested (with evidence), efficient, and totally correct.
e.g. Unparameterized:
(a)   echo 1 ; echo 2 | echo 3
(b)   echo 1 | echo 2 ; echo 3
e.g. Fully parameterized:
(c)   ((echo 1) ; (echo 2)) | (echo 3)
(d)   (echo 1) ; ((echo 2) | (echo 3))
(e)   ((echo 1) | (echo 2)) ; (echo 3)
(f)   (echo 1) | ((echo 2) ; (echo 3))
Does (a) correspond to (c) or (d)? Why? Does (b) correspond to (e) or (f)? Why? Can one tell?
¿And....
cat z | echo 1 ; cat
( cat z | echo 1 ) ; cat
cat z | ( echo 1 ; cat )
NB. If you want to put the input on the command line you can 'quote' the input string, e.g.
myprogram 'ls somedir ; cat somefile | somecmd'
(e.g. try:   echo 'echo 1 ; echo 2 | echo 3'  )
which will stop the shell from trying to execute the input as a real command line, or you can put the input in a file and redirect (<) it to standard input, or you can make the program read its input from a file.


© L. Allison, School of Computer Science and Software Engineering, Monash University, Australia 3800.
Created with "vi (Linux & IRIX)",   charset=iso-8859-1