INTERCALA note about the sourcesHistoryPolitenessConstantsVariablesArraysOperatorsBinary operatorsUnary operatorsPrecedenceStatementsSlide 13Slide 14Slide 15Slide 16COME FROMCommentsHello World ExampleAnother ExampleThat last program in comparisonBeyond INTERCALINTERCALAaron BloomfieldCS 415Fall 20052A note about the sourcesThe main sources for this lecture set are:The INTERCAL page in Wikipediahttp://en.wikipedia.org/wiki/IntercalThe INTERCAL Programming Language Revised Reference ManualOn the INTERCAL resources page: http://www.catb.org/~esr/intercal/Both sources are available under “free” licensesWikipedia under the GNU Free Documentation LicenseThe Reference Manual under the GPLIn accordance with these licenses, this work is also released under those same licenses3HistoryOriginally designed in 1972Main goal: “to have a compiler language which has nothing at all in common with any other major language”Only similarities are “basic” things such as:Variables, arrays, I/O, assignmentNothing else!Including all the arithmetic operators you are familiar with…INTERCAL stands for “Programming language without a pronounceable acronym”4PolitenessINTERCAL makes sure the programmer is politeStatements may be prefixed by PLEASEIf not enough PLEASEes are there, the compiler complains:PROGRAMMER IS INSUFFICIENTLY POLITEIF too many are there, the compiler also complains:PROGRAMMER IS OVERLY POLITEBetween ¼ and 1/3 of the statements must have PLEASE5ConstantsConstants are prefixed by a mesh (#)Can not be negative, and range from 0 to 65535Examples on next line#0 #32 #655356VariablesTwo types of variables:16-bit integerRepresented by the spot (.) followed by a number between 0 and 65535Examples on next line.1 .32 .6553532-bit integerRepresented by the two-spot (:)Examples on next line:0 :32 :4294967295Note that you can’t have negative numbersYou have to keep track of the sign separatelyFurther notes.123 and :123 are distinct variablesBut .1 and .0001 are identicalBut .001 is not 1E-37ArraysArray (of numbers) are represented by a tail (,) or a hybrid (;) for 16-bit and 32-bit values, respectivelyArray elements are suffixed by the word SUB, followed by the subscriptsIn summary:.123 :123 ,123 ;123 and #123 are all distinct8OperatorsINTERCAL recognized 5 operators: 2 binary, 3 unary“Please be kind to our operators: they may not be very intelligent, but they’re all we’ve got”The design intent was to be different than any other operators that existedBinary operatorsInterleave (aka mingle): represented by a change (¢)In an ASCII environment, you can use big money ($) insteadTakes two 16-bit values and interleaves their bits, producing a 32-bit valueSo #65535$#0 has 32-bit form 101010…10 (or 2863311530 decimal)Select: represented by a sqiggle [sic] (~)9Binary operatorsInterleave (aka mingle): represented by a change (¢)In an ASCII environment, you can use big money ($) insteadTakes two 16-bit values and interleaves their bits, producing a 32-bit valueSo #65535$#0 has 32-bit form 101010…10 (or 2863311530 decimal)Select: represented by a sqiggle [sic] (~)Finds which bits are 1 in the second operandSelects those bits from the first operandConsider #179~#201 (binary 10110011~11001001)From the second operand, selects bits 1, 2, 5, and 8Those bits in the first operand are 1, 0, 0, and 1, resepectivelyThus, the result is value #9Consider #201~#179 (binary 11001001~10110011)From the second operand, selects bits 1, 3, 4, 7, 8Those bits in the first operand are 1, 0, 0, 0, 1Thus, the result is #1710Unary operatorsThree types:Logical AND (&)Logical OR (V)Logical XOR ()In ASCII, written as a what (?)These characters are inserted between the spot, two-spot, mesh, etc., and the number:Examples on the next line.&123 #?123Cannot use multiple unary operatorsThese operators perform their respective operations on pairs of adjacent bits, with the result going into the position of where the first bit (of the pair) was in the original numberThe result of the first and last bits goes into the first bit of the resultExamples (77 is binary 1001101):#&77 is 0000000000000100 = 4#V77 is 1000000001101111 = 32879#?77 is 1000000001101011 = 3287511PrecedenceAs INTERCAL was intended “to have no precedents”, the compiler does not define what the operator precedence is“The precedence (or lack thereof) may be overruled by grouping expressions between pairs of sparks (‘) or rabbit-ears (“)”.Thus, ‘#165$#203’~#358 (binary value ‘10100101$11001011’~101100110) has value 1512StatementsLine labels are enclosed in wax-wane pairs (())Labels are (unique) integers from 1 to 65535Labels between 1000 and 1999 are used by the INTERCAL System Library functionsAfter the line label (if present), one of the following must occur:DOPLEASEPLEASE DOFollowing that, “either, neither, or both” of the following occur:NOT or N’T, which causes INTERCAL to abstain from that lineA number from 0 to 100, preceded by a double-oh-seven (%)This causes the statement to have that percentage of being executedFollowing all of this are one of the 14 valid operations13Statements1. CalculateThe assignment: instead of =, INTERCAL uses a angle (<) followed by a worm (-)32-bit values can get 16-bit values, and vise-versa if the value is less than 655352. NEXTOf the form:DO (label) NEXTPLEASE DO (label) NEXTUsed for subroutine calls and unconditional transfersTransfers control to that label AND stores it in a stack3. FORGETFollowed by an expressionCauses that many entries to be removed from the stack14Statements4. RESUMELike a FORGETBut jumps to the line label that is the last to be poppedUsed with NEXT (and FORGET) to do “subroutines”5. STASHStores variables and arrays so that subroutines can use the same variable namesVariables and arrays to stash are separated by intersections (+)6. RETRIEVERestores the previously STASHed values of the variables and arrays15Statements7. IGNOREFollowed by a variable (or array)Causes the variable to be unable to
View Full Document