zben@umd5.UUCP (07/09/85)
I am trying to convert an existing Pascal program to run under Ultrix, on a VAX, but do not have access to the internal documents for this implementation. The program makes extensive use of an "otherwise" clause in its "case" statements. I have blindly tried all variations I have seen in other Pascal implementations, without success. Can anybody out there tell me whether there is, in fact, an extension for a "none of the above" case, or that such an extension does not exist? -- Ben Cranston ...{seismo!umcp-cs,ihnp4!rlgvax}!cvl!umd5!zben zben@umd2.ARPA
chris@umcp-cs.UUCP (Chris Torek) (07/10/85)
Berkeley Pascal does not have an otherwise clause, so Ultrix Berkeley Pascal probably doesn't either. They won't unless you can convince someone to put in the ~20 line source code change to do it. . . . (I put it in here for a while for TeX, but now we have Pastel, so who needs pc?) -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251) UUCP: seismo!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris@maryland
trickey@Shasta.ARPA (07/12/85)
> I am trying to convert an existing Pascal program to run under Ultrix, > on a VAX, but do not have access to the internal documents for this > implementation. The program makes extensive use of an "otherwise" clause > in its "case" statements. I have blindly tried all variations I have seen > in other Pascal implementations, without success. > > Can anybody out there tell me whether there is, in fact, an extension for > a "none of the above" case, or that such an extension does not exist? > > -- > Ben Cranston ...{seismo!umcp-cs,ihnp4!rlgvax}!cvl!umd5!zben zben@umd2.ARPA Berkeley added a -O option to pxp sometime during 4.2. If you do pxp -O prog.p > newprog.p then prog.p can have a case labelled "others:", and pxp -O will create a newprog.c where such case statements are changed to: if <case expr> in [<list of non-"others:" labels in case>] then case <case expr> of <non-"others:" cases> end else <statement for "others:" case> If the range of the <case expr> isn't too big, the code generated is a bit-vector membership test, which isn't too bad. However, I recently reduced the running time of a program by a factor of 8 by noticing that large set membership tests get translated into a push of all the members onto the stack, followed by a call to a procedure to check each. (The fix was to change that code manaully, with a more efficient range test for the "others:" cases.) So be warned. When I and others ported TeX to UNIX, the "others:" problem had to be solved. We looked at pc's source, and found it was quite easy to add an "others:" clause capability. The compiler already generates code to check for "none of the cases", since it has to produce a runtime error for that. We asked Berkeley if they would consider putting the fix into pc, and they said no, because they didn't want to add such a non-standard feature to the language (and also because more programs than just pc would have to change to support a new language feature). Instead, they came up with the pxp -O solution, which is the one used in TeX right now. I don't think the large range problem shows up there. Sorry, but I don't have the changes to pc to add "others:" anymore. Howard Trickey ...decwrl!Glacier!Shasta!trickey
rusty@sdcarl.UUCP (rusty c. wright) (07/14/85)
Although the Berkeley Pascal compilers don't support the "others" clause (or whatever it is called; run strings on pxp and see if something pops up) pxp has a hack in it that will do what you want. Just give pxp the -O flag and it will turn case statements that use "others" into the appropriate if foo in [...] then case foo of ... else ... Just do something like pxp -O myfile.p > mynewfile.p -- rusty c. wright {ucbvax,ihnp4,akgua,hplabs,sdcsvax}!sdcarl!rusty