Íà÷àëüíûé êóðñ ïðîãðàììèðîâàíèÿ íà ÿçûêå Ôîðò

         

ÓÑÎÂÅÐØÅÍÑÒÂÎÂÀÍÍÛÉ ÃÅÍÅÐÀÒÎÐ ÁÅÑÑÌÛÑËÅÍÍÛÕ ÑÎÎÁÙÅÍÈÉ


Ãåíåðàòîð áåññìûñëåííûõ ñîîáùåíèé, î êîòîðîì øëà ðå÷ü â ãë. 10, èìååò ñóùåñòâåííûé íåäîñòàòîê: íåîáõîäèìî îñóùåñòâëÿòü âîçâðàò êàðåòêè â îïðåäåëåíèè ñëîâà ÑÎÎÁÙÅÍÈÅ. Ýòî âåäåò ê ìîçàè÷íîìó âûâîäó ôðàç.

Äëÿ òîãî ÷òîáû ãåíåðèðîâàòü íåñêîëüêî ñîîáùåíèé, ìû äîëæíû ïîðó÷èòü ñàìîé ïðîãðàììå ôèêñèðîâàòü ìîìåíòû, êîãäà òðåáóåòñÿ âîçâðàò êàðåòêè. Ñëåäóþùèé íèæå ëèñòèíã ïðèâîäèòñÿ áåç âñÿêèõ

êîììåíòàðèåâ. Ïðèîáðåòàéòå íàâûêè ÷òåíèÿ ïðîãðàìì íà Ôîðòå. Ïîïðîáóéòå ñäåëàòü îïðåäåëåíèÿ áîëåå ÿñíûìè. Ðåçóëüòàò ðàáîòû íàøåé ïðîãðàììû âûãëÿäèò òàê:  ÄÀÍÍÎÌ ÑÎÎÁÙÅÍÈÈ ÌÛ ÐÀÑÑÊÀÆÅÌ ÂÀÌ Î ÒÎÌ, ×ÒÎ ÂÊËÀÄÛÂÀß ÈÌÅÞÙÈÅÑß Â ÍÀËÈ×ÈÈ ÑÐÅÄÑÒÂÀ  ÈÍÒÅÃÐÈÐÎÂÀÍÍÛÉ ÖÈÔÐÎÂÎÉ ÊÎÌÏËÅÊÑ ÏÐÈÌÅÍßß ÀÂÒÎÍÎÌÍÛÉ ÊÓËÜÒÓÐÍÛÉ ÏÐÎÄÓÊÒ ÏÐÅÄÑÒÀÂËßÅÒÑß ÂÎÇÌÎÆÍÛÌ ÄÀÆÅ ÍÅÑÌÎÒÐß ÍÀ ÊÂÀËÈÔÈÖÈÐÎÂÀÍÍÛÉ ÖÈÔÐÎÂÎÉ ÏÐÎÅÊÒ ÅÖÅ ÁÎËÜØÅ ÊÐÅÏÈÒÜ ÓÍÈÊÀËÜÍÛÉ ÏÐÎÃÐÀÌÌÍÛÉ ÎÁÚÅÌ.

Ñ ÎÄÍÎÉ ÑÒÎÐÎÍÛ, ÈÑÑËÅÄÎÂÀÍÈß ÏÎÊÀÇÀËÈ, ×ÒÎ ÑÒÐÓÊÒÓÐÈÐÎÂÀÍÍÎ ÏÐÈÌÅÍßß ÎÁÙÈÉ ÒÐÓÄÎÂÎÉ ÎÁÚÅÌ Ó×ÈÒÛÂÀß ÀÂÒÎÌÀÒÈÇÈÐÎÂÀÍÍÛÉ ÏÐÎÃÐÀÌÌÍÛÉ ÀÂÒÎÌÀÒ ÑÒÀÍÎÂÈÒÑß ÍÅÎÑÓÙÅÑÒÂÈÌÛÌ ÏÎÄÍÈÌÀß ÑËÓ×ÀÉÍÛÉ ÏÐÎÈÇÂÎÄÑÒÂÅÍÍÛÉ ÏÐÎÖÅÑÑ ÅÙÅ ÁÎËÜØÅ ÊÐÅÏÈÒÜ ÊÂÀËÈÔÈÖÈÐÎÂÀÍÍÛÉ ÌÍÎÃÎÎÒÐÀÑËÅÂÎÉ ÏÐÈÍÖÈÏ.

Ñ ÄÐÓÃÎÉ ÑÒÎÐÎÍÛ, ÒÅÌ ÍÅ ÌÅÍÅÅ, ÏÐÀÊÒÈ×ÅÑÊÈÉ ÎÏÛÒ ÏÎÊÀÇÛÂÀÅÒ, ×ÒÎ ÑÒÐÓÊÒÓÐÈÐÎÂÀÍÍÎ ÏÐÈÌÅÍßß ÖÈÔÐÎÂÎÉ ÕÈÌÈ×ÅÑÊÈÉ ÊÎÌÏËÅÊÑ Ó×ÈÒÛÂÀß ÍÅÎÁÛ×ÀÉÍÛÉ ÌÍÎÃÎÎÒÐÀÑËÅÂÎÉ ÀÂÒÎÌÀÒ ÍÅÎÁÕÎÄÈÌÎ ÐÀÑÑÌÀÒÐÈÂÀß ÍÅÎÁÛ×ÀÉÍÛÉ ÏÐÎÃÐÀÌÌÍÛÉ ÊÐÈÒÅÐÈÈ ÔÓÍÊÖÈÎÍÈÐÎÂÀÒÜ ÊÀÊ ÂÐÅÌÅÍÍÛÉ ÖÈÔÐÎÂÎÉ ÏÐÎÅÊÒ.

 ÐÅÇÓËÜÒÀÒÅ ÍÀØÅ ÏÐÅÄËÎÆÅÍÈÅ ÇÀÊËÞ×ÀÅÒÑß Â ÒÎÌ, ×ÒÎ ÑÒÐÓÊÒÓÐÍÎ ÏÐÈÌÅÍßß ÑËÓ×ÀÉÍÛÉ ÊÓËÜÒÓÐÍÛÉ ÈÍÒÅÐÅÑ Ó×ÈÒÛÂÀß ÑÈÑÒÅÌÀÒÈÇÈÐÎÂÀÍÍÛÉ ÖÈÔÐÎÂÎÉ ÓÐÎÂÅÍÜ ÍÅÎÁÕÎÄÈÌÎ ÐÀÑÑÌÀÒÐÈÂÀß ÖÈÔÐÎÂÎÉ ÒÐÓÄÎÂÎÉ ÏÐÎÅÊÒ ÅÙÅ ÁÎËÜØÅ ÊÐÅÏÈÒÜ ÑÈÍÕÐÎÍÈÇÈÐÎÂÀÍÍÛÉ ÊÎÐÎÒÊÎÂÎËÍÎÂÛÉ ÊÐÈÒÅÐÈÈ.

Block # 156 0 ( Ãåíåðàòîð áåññìûñëåííûõ âûðàæåíèé, âàðèàíò ñ ñàìîôîðìàòèðîâàíèåì ) 1 VARIABLE ÎÑÒÀÒÎÊ \ êîëè÷åñòâî îñòàâøèõñÿ ñèìâîëîâ, ïîäëåæàùèõ ñêàíèðîâàíèè 2 VARIABLE ÏÎ-ÃÎÐÈÇÎÍÒÀËÈ \ òåêóùåå ïîëîæåíèå êóðñîðà äëÿ âûâîäà ïî 3 \ ãîðèçîíòàëè 4 70 CONSTANT ÏÐÀÂÃÐÀÍ \ ïðàâàÿ ãðàíèöà 5 : ÑÊÀÍÅÐ ( äëèíà-ïîèñêà -- àäð-ïðîáåëà | êîíåö-ïîëÿ) 6 2DUP + ROT ROT OVER + SWAP ÂÎ 1 Ñ@ BL = 7 IF DROP I LEAVE THEN LOOP ; 8 : ÄÀÉÑËÎÂÎ ( a -- a ñëîâî-ñ÷åò÷èê) \ ïîëó÷.
î÷åðåäè, ñëîâà äëÿ ôîðìàòèðîâàíèÿ 9 DUP ÎÑÒÀÒÎÊ @ BUP 0> IF ÑÊÀÍÅÐ ELSE DROP THEN OVER - 10 DUP 1+ NEGATE ÎÑÒÀÒÎÊ +! ; 11 : ÑÞÄÀ? ( ñ÷åò÷èê -- 1=ïîäõîäèò äëÿ äàííîé ñòðîêè) 12 ÏÎ-ÃÎÐÈÝÎÍÒÀËÈ @ + ÏÐÀÂÃÐÀÍ < ; 13 : SPACE' ÏÎ-ÃÎÐÈÇÎÍÒÀËÈ @ IF SPACE 1 ÏÎ-ÃÎÐÈÝÎÍÒÀËÈ +! THEN ; 14 : CR' CR 0 ÏÎ-ÃÎÐÈÇÎÍÒÀËÈ ! ; 15 157 LOAD 158 LOAD

Block # 157 0 ( Ãåíåðàòîð áåññìûñëåííûõ âûðàæåíèé, âàðèàíò ñ ñàìîôîðìàòèðîâàíèåì ) 1 : .ÑËÎÂÎ ( à # -- ) \ âûâîä ñëîâà, åñëè íåîáõîäèìî, âûïîëíåíèå CR 2 DUP ÑÞÄÀ? IF SPACE' ELSE CR' THEN 3 DUP ÏÎ-ÃÎÐÈÇÎÍÒÀËÈ +! TYPE ; 4 : ÑËÅÄÓÞÙÅÅ ( a # -- ñëåä.àäð.) 5 + 1+ ; 6 : ÂÛÂÎÄ ( à #ñèìâîëîâ -- ) \ âûâîä ñôîðìàòèðîâàííîãî òåêñòà 7 ÎÑÒÀÒÎÊ ! 8 BEGIN ÄÀÉÑËÎÂÎ DUP WHILE 2DUP .ÑËÎÂÎ ÑËÅÄÓÞÙÅÅ REPEAT 9 2DROP ; 10 : ÀÁÐÅÄ ( -- à) 161 BLOCK ; \ ñëó÷àéíûå ñëîâà 11 : ÎÁÎÐÎÒÛ ( -- à) 160 BLOCK ; \ ñâÿçûâàþùèå îáîðîòû 12 : ÂÂÅÄÅÍÈß ( - a) 1S9 BLOCK ; \ íà÷àëà ôðàç 13 : ÁÐÅÄ ( #ñòðîêè #ñòîëáöà -- à) \ ïîëó÷åíèå àäðåñà ñëîâà 14 20 * SWAP 64 * + ÀÁÐÅÄ + ; 15

Block # 158 0 ( Ãåíåðàòîð áåññìûñëåííûõ âûðàæåíèé, âàðèàíò ñ ñàìîôîðìàòèðîâàíèåì ) 1 : .ÁÐÅÄ ( #ñòðîêè #ñòîëáöà -- ) ÂÐÅÄ 20 ÂÛÂÎÄ ; 2 : ×ÀÑÒÜ-ÐÅ×È ( #ñòðîêè -- ) CREATE , \ îïðåäåëåíèå ÷àñòåé ðå÷è 3 DOES> @ 10 CHOOSE SWAP .ÁÐÅÄ ; 4 0 ×ÀÑÒÜ-ÐÅ×È 1ÏÐÈËÀÃÀÒÅËÜÍÎÅ 5 1 ×ÀÑÒÜ-ÐÅ×È 2ÏÐÈËÄÃÀÒÅËÜÍÎÅ 6 2 ×ÀÑÒÜ-ÐÅ×È ÑÓÙÅÑÒÂÈÒÅËÜÍÎÅ 7 : ÔÐÀÇÀ 1ÏÐÈËÀÃÀÒÅËÜÍÎÅ 2ÏÐÈËÀÃÀÒÅËÜÍÎÅ ÑÓÙÅÑÒÂÈÒÅËÜÍÎÅ ; 8 : ÎÁÎÐÎÒ ( #ãðóïïû -- ) [ 4 64 * ] LITERAL * 9 3 CHOOSE 64 * + ÎÁÎÐÎÒÛ + 64 ÂÛÂÎÄ ; 10 : ÏÎÂÅÑÒÂÎÂÀÍÈÅ 4 0 DO I ÎÁÎÐÎÒ ÔÐÀÇÀ LOOP ." ." CR' ; 11 : ÂÂÅÄÅÍÈÅ ( #àáçàöà -- ) 12 CR' 64 * ÂÂÅÄÅÍÈß + 64 ÂÛÂÎÄ ; 13 : ÑÎÎÁÙÅÍÈÅ CR' CR' 4 0 DO I ÂÂÅÄÅÍÈÅ ÏÎÂÅÑÒÂÎÂÀÍÈÅ LOOP ; 14 15

Block # 159 0  ÄÀÍÍÎÌ ÑÎÎÁÙÅÍÈÈ ÌÛ ÐÀÑÑÊÀÆÅÌ ÂÀÌ Î ÒÎÌ, ×ÒÎ 1 Ñ ÎÄÍÎÉ ÑÒÎÐÎÍÛ, ÈÑÑËÅÄÎÂÀÍÈß ÏÎÊÀÇÀËÈ, ×ÒÎ 2 Ñ ÄÐÓÃÎÅ ÑÒÎÐÎÍÛ, ÒÅÌ ÍÅ ÌÅÍÅÅ, ÏÐÀÊÒÈ×ÅÑÊÈÉ ÎÏÛÒ ÏÎÊÀÇÛÂÀÅÒ, ×ÒÎ 3  ÐÅÇÓËÜÒÀÒÅ ÍÀØÅ ÏÐÅÄËÎÆÅÍÈÅ ÇÀÊËÞ×ÀÅÒÑß Â ÒÎÌ, ×ÒÎ 4 5 6 7 8 9 10 11 12 13 14 15

Block # 160 0 ÏÐÈÌÅÍßß 1 ÂÊËÀÄÛÂÀß ÈÌÅÞÙÈÅÑß Â ÍÀËÈ×ÈÈ ÑÐÅÄÑÒÂÀ  2 ÑÒÐÓÊÒÓÐÈÐÎÂÀÍÍÎ ÏÐÈÌÅÍßß 3 4 ÈÌÅß Â ÂÈÄÓ 5 ×ÒÎÁÛ ÊÎÌÏÅÍÑÈÐÎÂÀÒÜ 6 Ó×ÈÒÛÂÀß 7 8 ÏÐÅÄÑÒÀÂËßÅÒÑß ÂÎÇÌÎÆÍÛÌ ÄÀÆÅ ÍÅÑÌÎÒÐß ÍÀ 9 ÑÒÀÍÎÂÈÒÑß ÍÅÎÑÓÙÅÑÒÂÈÌÛÌ ÏÎÄÍÈÌÀß 10 ÍÅÎÁÕÎÄÈÌÎ ÐÀÑÑÌÀÒÐÈÂÀß 11 12 ÔÓÍÊÖÈÎÍÈÐÎÂÀÒÜ ÊÀÊ 13 ÑÎÇÄÀÒÜ 14 ÅÙÅ ÁÎËÜØÅ ÊÐÅÏÈÒÜ 15

Block # 161 0 ÂÛÑÎÊÈÉ ÊÓËÜÒÓÐÍÛÉ ÓÐÎÂÅÍÜ 1 ÎÁÙÈÉ ÏÐÎÈÇÂÎÄÑÒÂÅÍÍÛÉ ÈÍÒÅÐÅÑ 2 ÀÂÒÎÌÀÒÈÇÈÐÎÂÀÍÍÛÉ ÍÀÓÊÎÅÌÊÈÉ ÊÎÌÏËÅÊÑ 3 ÇÀÏËÀÍÈÐÎÂÀÍÍÛÉ ÂÀËÎÂÎÉ ÎÁÚÅÌ 4 ÈÍÒÅÃÐÈÐÎÂÀÍÍÛÉ ÖÈÔÐÎÂÎÉ ÊÎÝÔÔÈÖÈÅÍÒ 5 ÊÂÀËÈÔÈÖÈÐÎÂÀÍÍÛÉ ÌÍÎÃÎÎÒÐÀÑËÅÂÎÉ ÏÐÈÍÖÈÏ 6 ÏÐÅÄÑÒÀÂÈÒÅËÜÍÛÉ ÕÈÌÈ×ÅÑÊÈÉ ÃÅÍÅÐÀÒÎÐ 7 ÒÅÕÍÎËÎÃÈ×ÅÑÊÈÉ ÍÅÏÐÅÐÛÂÍÛÉ ÏÐÎÖÅÑÑ 8 ÀÂÒÎÍÎÌÍÛÉ ÀÏÏÀÐÀÒÍÛÉ ÈÍÒÅÐÔÅÉÑ 9 ÖÈÔÐÎÂÎÉ ÍÅÇÀÂÈÑÈÌÛÉ ÀÂÒÎÌÀÒ 10 ÑÈÍÕÐÎÍÈÇÈÐÎÂÀÍÍÛÉ ÔÓÍÊÖÈÎÍÀËÜÍÛÉ ÊÐÈÒÅÐÈÉ 11 ÑÈÑÒÅÌÀÒÈÇÈÐÎÂÀÍÍÛÉ ÊÎÐÎÒÊÎÂÎËÍÎÂÎÉ ÏÐÎÅÊÒ 12 ÑËÓ×ÀÉÍÛÉ ÎÒÐÈÖÀÒÅËÜÍÛÉ ÈÌÏÓËÜÑ 13 ÍÅÎÁÛ×ÀÉÍÛÉ ÒÐÓÄÎÂÎÉ ÏÎÄÚÅÌ 14 ÂÐÅÌÅÍÍÛÉ ÍÅÕÀÐÀÊÒÅÐÍÛÉ ÑÏÀÄ 15 ÓÍÈÊÀËÜÍÛÉ ÏÐÎÃÐÀÌÌÍÛÉ ÏÐÎÄÓÊÒ


Ñîäåðæàíèå ðàçäåëà