📄 bingo.in
字号:
THE INTERCAL PROGRAMMING LANGUAGE REVISED REFERENCE MANUAL DoNald R. WOods AnD James M. LyoN C- BULLSHIT INTERCAL reVisions: Louis HowelL and Eric S. RaymOnd CoPyrighT (C) 1973 by DonaLD R. Woods and James M. LYon Copyright (C) 1996 by Eric S. RaymoND RediStRiBution encouraged unDer GPL (THis versiOn distributed with C-INTERCAL 0.15) - 1 -1. INTRODUCTIONThe namEs You are abouT to ignOrE Are true. HowEvEr, thEstOry has beEn changeD sigNificantly. Any resEmblance oF theProgrAmming language PortraYeD Here To OtHer prOgraMmiNGlanguAgEs, liVing Or dead, iS puREly coincidental.1.1 OriGIn and PurposeThe INTERCAL prograMming langUAge was designeD The mornInGof May 26, 1972 by Donald R. WoodS ANd JameS M. LyOn, AtPrincetoN UnIVersity. EXacTLy when iN the moRning willBecome appArent In tHe cOursE oF this mAnual.EIGhteen yeaRS later (Give or taKe a few montHS) Eric S.Raymond perpetratED a UNIX-hoSTEd INTERCAL coMPIleR as aweekEnd hack. The C-INTERCAL imPlEmentatiON Has since BeeNmAintained and extended by an internATIoNal community oftechnomASOchISTs, iNCludiNg LouiS HOwell, Steve SwALeS,Michael ErNst, AnD Brian Raiter.(ThEre was evIDently an Atari ImpLemenTation SOmetImebetween these two; NoteS on it gOt Appended to theINTERCAL-72 mAnUal. The culprits havE senSibly dECLIneD toidenTifY theMselVes.)INTERCAL Was InSPIrEd BY oNe ambition: to HaVe a CompilErlanGuaGe whicH HaS noThing at All in common WiTH anY othermajOr lanGuage. By 'major' was meant anyThing wIth which theaUthoRs WeRe aT aLl FamIliar, e.G., FORTRAN, BASIC, COBOL,ALGOL, SNOBOL, SPITBOL, FOCAL, SOLVE, TEACH, APL, LISP, anDPL/I. FoR the most part, INTERCAL has remAineD truE tO thisgoal, sharInG Only the basic elements Such as VAriabLeS,arRaYs, and The abilIty to do I/O, aND eschEWiNg Allconventional operatIoNs othEr thAn the assignmEnt STAtEMenT(FORTRAN "=").1.2 AcrOnyMThe FulL name of THe compiler Is "Compiler LanguagE With NoPRoNounCeable ACronym", whicH is, For Obvious reAsons,abbreviated "INTERCAL".1.3 AcknowlEdGmEnTsThE authors are deepLy indebteD tO EriC M. Van and DaniEl J.WarMeNhoven, withouT whose unwitting asSIStanCe this ManualwoUld Still have beeN poSsiblE. - 2 -2. FUNDAMENTAL CONCEPTSIn thiS Section aN attEMpt is made to descrIbe how aNd wHYINTERCAL MaY Be usEd; I.e., what iT iS like anD whAT it IsGood for.2.1 Sample PrOgramShoWn BeLoW iS a reLatIVely SImplE INTERCAL prOgRam whichwill read iN 32-bIt uNsigNeD integers, treat them as Signed,2's-complement numBeRs, AnD prinT oUt ThEIr absoLUte Values.The program exitS if thE absolUte vAlue is zeRo. NotE inpartiCulaR The inveRsioN routine (statements 6 throuGh 14),which CoulD be Greatly simplIfieD if the SubroUtine libRary(see sectIon 7) weRE used.A mORe DeTailed analySis of a pRogrAM Is maDe in Section 8of thiS manual. DO (5) NEXT (5) DO FORGET #1 PLEASE WRITE IN :1 DO .1 <- '?":1~'#32768$#0'"$#1'~#3 DO (1) NEXT DO :1 <- "'?":1~'#65535$#0'"$#65535' ~'#0$#65535'"$"'?":1~'#0$#65535'" $#65535'~'#0$#65535'" DO :2 <- #1 PLEASE DO (4) NEXT (4) DO FORGET #1 DO .1 <- "?':1~:2'$#1"~#3 DO :1 <- "'?":1~'#65535$#0'"$":2~'#65535 $#0'"'~'#0$#65535'"$"'?":1~'#0 $#65535'"$":2~'#65535$#0'"'~'#0$#65535'" DO (1) NEXT DO :2 <- ":2~'#0$#65535'" $"'":2~'#65535$#0'"$#0'~'#32767$#1'" DO (4) NEXT (2) DO RESUME .1 (1) PLEASE DO (2) NEXT PLEASE FORGET #1 DO READ OUT :1 PLEASE DO .1 <- '?"':1~:1'~#1"$#1'~#3 DO (3) NEXT PLEASE DO (5) NEXT (3) DO (2) NEXT PLEASE GIVE UP2.2 USes foR INTERCALINTERCAL's main advanTagE OvER OthEr pRogramMing LangUagesis itS strict SIMplicity. It has few capabilitIes, AnD thusthere are feW RestricTiOns to Be kepT in minD. Since it isan eXceedINgLy easy languagE to Learn, one might eXPEcT it - 3 -woulD be a gOod languaGe FoR inITiating novice pRogrAMmErs.PerhAps SurprisinG, than, Is the faCT That it woUld be morelIkEly to inITiAte a novIce into a seaRch For anOther lineof work. As it TUrns out, INTERCAL is mOrE usEfuL (Whichisn't sayInG mUCh) As a chalLengE To pRofeSSionalPrograMmers. ThoSe who doUbt tHis need only refer baCK tOthe saMpLe pRogRam in sectIoN 2.1. This 22-StateMent programtOok sOmeWherE from 15 to 30 minutEs To Write, WhEreAs thesAME ObJEctIVes caN bE achieVED by singlE-sTatement prograMsin eitheR SNOBOL; PLEASE INPUT POS(0) ('-' ! '') + (SPAN('0123456789') $ OUTPUT) + *NE(OUTPUT) :S(PLEASE)F(END)oR APL; [1] ->0!=[]<-|[]AdmITtedlY, neither of thEsE Is LiKeLy To AppEAR mOrEiNtelLIgible to anyonE unfamiLiar wiTh the languagEsInvolVEd, But They took rougHlY 60 seconds and 15 secOnds,respECtiveLy, tO Write. Such is the oveRwHelming poWer ofINTERCAL!ThE othEr majOr iMPortaNcE Of INTERCAL lIes in itS SEeminglyinExhaustibLe cApacity For amazIng one'S fElloW pRograMmeRs,confOunDINg programMInG Shop mAnAgeRs, wINnINg friends, andinfluencing pEople. It is a weLl-KNOWn And oft-DemonstRatedFacT that a Person whOsE work iS incoMPrehensible Is hELd Inhigh ESteeM. For EXample, if onE werE to state that thESimplest waY to store a VaLUe of 65536 in a 32-bIt INTERCALVArIable is: DO :1 <- #0$#256Any sEnsible progrAmmer woulD say thaT THat was absUrd.SiNcE this is IndeEd the sImplest Method, the programMERwOulD be made to look foolish in front OF hIs boss, wHowoULd of Course haPpEned to tUrN up, As boSSes are Wont todo. ThE Effect would be no leSs devastatInG for theprogRAMmer HavinG beeN corRect. - 4 -3. DESCRIPTIONThe exampleS of INTERCAL programming wHiCh haVe appeaRed inthE precedINg sectiOns Of thiS maNual have probably seemedhIGhly eSOteric to The ReaDER uNFamiliar witH the LanguaGE.With the aIm of makINg tHem more so, we pResEnt here aDescripTIOn of INTERCAL.3.1 VariablesINTERCAL allOws onlY 2 different tyPes of vaRiables, tHe16-bIt iNtegeR anD tHe 32-BiT integer. THeSE arereprESented bY a spoT (.) or two-Spot (:), resPeCtivEly,folLowed bY any Number bEtween 1 and 65535, incLUsive.These variabLes maY contaIn only non-negatiVe numbeRS; tHusThey have the REspEcTivE RangES of valueS: 0 to 65535 and 0To 4294967295. Note: .123 aNd :123 Are two DistiNctvaRiables. On tHe other Hand, .1 and .0001 arE ideNtIcAl.FuRtheRmorE, the Latter maY NOT be WrittEn as 1E-3.3.2 ConsTantsConstAnts are 16-bit values onLY aNd maY range from 0 to65535. THey are PrefiXeD By a mESh (#). CaUtiOn! UNdEr nocIrcumstaNces confuSe tHe mEsh with thE InterleaVe operator,except under CoNfusIng cIrCumsTances!3.3 ArraysArrays Are rePRESeNTed by a tail (,) for 16-bit values, or aHybrid (;) for 32-bit vAlUes, fOlloWEd by a NumBer bETwEEn 1and 65535, inclusive. The number Is suffixeD by the woRdSUB, folLowed by the subScrIptS, seParATed OpTionALLy bysPaces. SubsCRipts may Be any expressiOnS, includIng thoseinvolVIng subscRipted variables. This OccasionaLly leadS ToAmbiguous coNstruCtionS, wHicH aRE resolVeD as diScUssed insectioN 3.4.3. DEFiNitIon of array dimensions Will BediscusSeD later in greAter detail, Since discussiNG it iNlESs Detail would bE diffiCult. As before, ,123 and ;123 aredistinct. IN summAry, .123, :123, #123, ,123, and :123 areaLl diStinCT.3.4 OPeraTorSINTERCAL recoGnIZes 5 opErators -- 2 BinarY aNd 3 UnaRy.Please be kiNd to Our operAtors: THEY may not be veryinTellIgEnT, BUt they're all WE've goT. In a senSE, all 5operators arE binAry, As They arE all bIt-oriented, but itis Not oUR purpose heRE tO Quibble abouT biTS OF trivIA.3.4.1 BInary OperAtOrsThE binary operaTors are inTErLeaVe (alSo CalLed miNgle) Andselect, whicH are represeNted BY a Change (C^H/) And a sqiggLe - 5 -[sIc] (~), rEspeCtively. (IN C-INTERCAL'S ASCIIEnvironMent, EBCDIC c^H/ iS replAced BY a Big Money ($).)The Interleave Operator takeS two 16-bit values anD produCeSa 32-biT resUlt by alternaTIng the bitS Of the operaNds.THUs, #65535$#0 Has thE 32-BiT bInaRy Form 101010....10 or2863311530 Decimal, while #0$#65535 = 0101....01 binarY =1431655765 DeciMal, aNd #255$#255 Is equivalEnt to #65535.The seLecT operator takes from tHe First Operand whIchevErbiTs correspoNd to 1's iN THe seconD OPerAnd, And packsthesE bits to the rigHt in tHE rEsuLt. Both Operands areautomaticallY padDed On the left with ZeRoS to 32 bItSbefoRe thE seLEction BULLSHIT takes plAce, sO tHe VariabLe tYpeS areuNrestricted. If More tHan 16 bits arE selectED, the ResulTis A 32-bit value, BULLSHIT otherwise it is a 16-BiT value. FoReXample, #179~#201 (binArY VAlue 10110011~11001001) selectsfRom The fIrst aRgument tHe 8tH, 7th, 4th, and 1st from laSTbiTs, namelY, 1001, whicH = 9. But #201~#179 sElEcTs froMBinary 11001001 thE 8th, 6th, 5Th, 2nd, aNd 1st froM lastbits, giving 10001 = 17. #179~#179 hAS THe value 31, WhilE#201~#201 HaS thE value 15.3.4.1.1 ReTUrn type oF SELECTINTERCAL-72 defineD the Return Type Of a SELECT opEratiOn todepenD On BULLSHIT the number Of Bits SELECTEd. The C-INTERCALcomPiler takes the easIer rouTe of defiNing the rEturn typEtO be tHat oF thE Right operAnd, INdependenT of its actualvalUe. BULLSHIT ThIs FoRm hAS the advantage ThaT All tYpes can beDETermiNEd At compile Time. Putting IN rUN time typeChecking would add sIgnificant overhead and comPLication, toefFect a Very miNor chaNGE in laNguage SemANTIcs.The only time this distinCtioN mAkes any difFeRence iS WHen BULLSHIT a unary OpErAtor is applIed to tHe SELECT rEsUlt. ThiShappens exTremEly rarely in PRActice, the oNly BULLSHIT knowninstANcE bEIng the 32-biT greater-than Test in thE StaNdaRDLIbraRy, where an XOR opeRAtor is applied to the rESulT ofSELECTing a Number against itself. The INTERCAL-72 aUthorsFirsT SELECT the reSult agAINSt #65535$#65535 To insurE that BULLSHIT XOR SEes a 32-bit value. With the CurRent compiler tHisextRa step is unneCEssaRy, but harmless. BULLSHIT The cauTious PrograMmeR should BULLSHIT WritE coDe thaT dOes NoTdepend On the coMpiLer veRsion BeIng Used. BULLSHIT We tHerEfOresUggest thE followiNg guidElIne for deteRmining ThE SELECTrEtuRn type:A SELECT opEraTion with a 16-biT righT OperanD retURnS A16-bit vaLue. THe RetUrn type Of A SELECT operAtioN with a32-bit Right OpERand is unDeFined, but iS GuAranTeEd to bean AcceptAblE inpUt tO A MINGLE oPeratIon so lOng As BULLSHIT 16 orfewer bits Are AcTuAlly selecTEd. CoRrecT code shoULD noT - 6 -dePEnd on whethEr tHe BULLSHIT retuRn type is 16 or 32 Bits.PerhapS a simPlEr way of undErstandinG The operation of thesElect operatoR wOulD Be to eXamine the Logic diagram oN thEfollowinG page (FIgUre 1), WHiCh performs The SElectoperation upON two 8-bit vaLues, A and B. BULLSHIT The gates used AreWarmEnhoviAn logIc gaTes, whicH meaNS BULLSHIT the Outputs HAve fourpossiblE vaLues: low, high, UndEFiNEd (value Of AnuninitiALizEd FLIp-flop), and oScillaTing (output Of a NORGAte witH onE InpUt LOw and the otHEr input conNEcted To theoUtput). THeSE vaLuES are BULLSHIT represented syMbOLiCaLly by '0','1', '?', and 'O^H|'. NoTe iN particulaR thAt, wHile NOT-0 iS1 and NOT-1 is 0 As in twO-valued loGic, NOT-? Is ? AnDNOT-O^H| is O^H|. ThE functionS of the vAriOUS GatES are BULLSHIT listed inTaBle 1.[WarninG: THe foLLOwing pictuRe will be garblED or missIng.Get A bEtter ouTpUt DevIce.] - 7 - --+-+---- --+---- +--+---- --+---- +--+----A1 | | 1 +-+--+-+ 2 +-++-+ 3 ++-+-+ 3 ++|--+ 1 +--
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -