home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!uknet!yorkohm!minster!dan
- From: dan@minster.york.ac.uk
- Newsgroups: comp.programming
- Subject: Re: A LITTLE BRAIN... in parallel
- Message-ID: <714154949.3534@minster.york.ac.uk>
- Date: 18 Aug 92 16:22:29 GMT
- Organization: Department of Computer Science, University of York, England
- Lines: 59
-
-
- Dear Netters,
-
- Here is my solution to the little problem someone posted a while ago.
- I am not too happy to see that more and more people are getting stuck
- into the arcane ways of C. comp.lang.c is a good place for that and I
- though that something a little different might be of interest.
- (... I am being a hypocrite; I spend my days hacking C as well)
-
- The following proglet (if I am allowed to call it so) reads lines and
- prints them in the reverse, while the words stay properly orientated;
- so FOO BAR BAZ becomes BAZ BAR FOO. As it stands the program works for a
- single line of text. It is written in Hoare's CSP language and my
- colleagues and I believe that it works. The version that worked for a
- single word only was tested in Ada and it worked properly.
-
- The following code DOESN'T use a stack or a list or env or anything like
- that. It uses a PROCESS per character. Each char is read by a single
- process and printed by that same process. BAZ BAR FOO would need 12
- separate processes.
-
- If CSP was executable, running META would do the trick.
-
- END = p? -> d! -> SKIP
- P = input?ch ->
- IF ch == <CR>
- (f:META//(f.nw? -> p! -> d? -> output!ch -> SKIP))
- ELSIF ch == <SPACE>
- p! -> d? -> output!ch -> nw! -> SKIP
- ELSE
- (n:P //(n.p? -> p! -> d? -> output!ch -> n.d! -> SKIP))
- META = END || P
-
- where <CR> is ASCII 0x0d and <SPACE> is ASCII 0x20
- (note [pd][!?] implies that a communication channel is engaged, but
- that we are NOT interested in the actual messages that will be passed.
- The channels are only used for synchronization.)
-
- Beware of the above code...
- I didn't even proved it correct, but I suppose I could if needed.
-
- p.s. as I said I am NOT sure that it works, but I give it a very high
- probability of correctness. :)
-
- p.p.s Just an afterthought if you want it to work for more then one line
- define another process, say TEXT as follows:
-
- TEXT = META -> TEXT
-
- p.p.p.s I will try to convince my colleague to translate all of the
- above into Ada. If he does, I'll post it.
-
-
-
- Daniel Kustrin
- Distributed Ada Debugging Group
- University of York
- York, England
- dan@minster.york.ac.uk
-