// numbers.j prompts for two numbers and does a few calculations. If // division by 0 or end of file is encountered, an exception is raised. // It is written in the core join calculus and compiles under v0.4 of cjcc. // To compile and run: cjcc -o numbers.c numbers.j // gcc -o numbers numbers.c // numbers // Author: Peter Selinger, University of Pennsylvania // Copyright (C) 1996 Peter Selinger // This is free software under the terms of the GNU General Public License. def main<> --> def /* exceptions */ exc --> write<"Exception: ",k1,_> | s and k1<> | s --> write and k2<> --> write<"\n",main,_> and eofexc --> write<"\nEnd Of File.\n",_,_> in def /* output */ output --> ss | sd | sq | sp

| k0<> | st | ct and k0<> --> write<"The sum is: ",k1,_> and k1<> | ss --> write and k2<> --> write<"\nThe difference is: ",k3,_> and k3<> | sd --> write and k4<> --> write<"\nThe product is: ",k5,_> and k5<> | sp --> write and k6<> --> write<"\nThe quotient is: ",k7,_> and k7<> | sq --> write and st --> equal and eq --> if and then<> | k8<> --> write<"\nThe numbers are equal.\n",k9,_> and else<> | k8<> --> write<"\nThe numbers are not equal.\n",k9,_> and k9<> | ct --> cont<> in def /* calculations */ calc --> plus | minus | div | times | store and ksum | kdiff | kquot | kprod | store--> output in def /* inputnumbers */ start<> --> write<"Please type two numbers: ",k1,_> and k1<> --> readint and n1 --> s1 | readint and s1 | n2 --> calc and again<> --> start<> in start<> in main<>