CO538 Anonymous Questions and Answers Keyword Index |
This page provides a keyword index to questions and answers. Clicking on a keyword will take you to a page containing all questions and answers for that keyword, grouped by year.
To submit a question, use the anonymous questions page. You may find the keyword index and/or top-level index useful for locating past questions and answers.
Keyword reference for q5
2004 |
I have started Q5 and was wondering if you could give any tips on how to convert a character to upper case. And also what you mean on flushing and how to do this.
Just as a side-note, Q5 is not for assessment -- but doing it anyway yourself is useful! There are essentially two ways to convert between lower and upper case characters. The first is to do it arithmetically (since `BYTE's can be treated as regular values):
upper.char := (lower.char - 'a') + 'A'
Of course, you'd better check that `lower.char' really is in the range `a' to `z' first. The second method is more cunning, and relies on the way ASCII characters are assigned:
upper.char := lower.char /\ #DF
For flushing, see the answer to Question 91 (2000).
2003 |
I'm having trouble with the `overflow.buffer' process in q5. Here is what I have; there seems to be a problem with `count' such that it doesn't get incremented and nothing ever gets outputted. Thanks.
[adjusted code] PROC overflow.buffer (...) VAL INT BUFSIZE IS 10: [BUFSIZE] BYTE Buffer: INT head, tail, count: SEQ head:= 0 tail:= 0 INT count: count := 0 WHILE TRUE ... do things :
Inside the body of the WHILE loop, `count' is undefined [1]. The assignment `count := 0' is assigning to the `count' declared immediately above it. In occam, the scope of a variable is the process that follows it. Assignment is a process (simple), as are SEQ blocks, etc. (processes that contain sub-processes). Thus, the scope of the first `count' declaration is the entirity of the SEQ body (in effect, all the code in `overflow.buffer'). When `count' is declared again inside the SEQ, it descopes the earlier `count'. The scope of this is, as always, the process that follows it, which is just the single assignment `count := 0', which of course leaves the earlier `count' untouched.
Keywords: q5 , variable-scope
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. |