#- # CMP 407/770 final exam: add (homogeneous) sets to the Lehman programming language # due: noon on Friday, 12/21/12 # # The program below illustrates the operations your compiler should support: # set literals, # the union of two sets (^+), # the intersection of two sets (^&), # the difference of two sets (^-), # membership in a set (^?), # non membership in a set (^!), # the size of a set, and # looping over the elements of a set. # # The sets in this example program are sets of CHARACTER. # Your compiler should also support SET NUMBER, SET SEQ CHARACTER, SET SET BOOLEAN, etc.. # Your compiler need not support SET ANY, SET INVALID, etc.. # # When you are finished submit an email stating clearly and succinctly what you have # accomplished and what you have not. Include a jar file containing your compiler in # a form that I can import as an Eclipse project. # -# {'a', 'e', 'i', 'o', 'u', 'y', 'y'} ~> SET CHARACTER A # SET literal, a set of six characters write @A write "\nThe size of A is " write |@A| write "\nEnter another set of characters B as a string constant: " read SEQ CHARACTER: y write y write "\n" { CHARACTER } ~> SET CHARACTER B # SET literal, an empty set of characters for c : y do @B ^+ {c} ~:> B # the union of two sets write @B write "\nA union B is " write @A ^+ @B # the union of two sets write "\nA intersect B is " write @A ^& @B # the intersection of two sets write "\nA minus B is " write @A ^- @B # the (asymmetric) difference of two sets (the elements of A that are not in B) write "\n" for c : @A do # loop over the elements of a set if 0 == |c|%%2 then if @B ^? c write c # membership in a set else if @B ^! c write c # non membership in a set write "\n"