Ãëàâíàÿ » Êàòàëîã    
ðåôåðàòû Ðàçäåëû ðåôåðàòû
ðåôåðàòû
ðåôåðàòûÃëàâíàÿ

ðåôåðàòûÁèîëîãèÿ

ðåôåðàòûÁóõãàëòåðñêèé ó÷åò è àóäèò

ðåôåðàòûÂîåííàÿ êàôåäðà

ðåôåðàòûÃåîãðàôèÿ

ðåôåðàòûÃåîëîãèÿ

ðåôåðàòûÃðàôîëîãèÿ

ðåôåðàòûÄåíüãè è êðåäèò

ðåôåðàòûÅñòåñòâîçíàíèå

ðåôåðàòûÇîîëîãèÿ

ðåôåðàòûÈíâåñòèöèè

ðåôåðàòûÈíîñòðàííûå ÿçûêè

ðåôåðàòûÈñêóññòâî

ðåôåðàòûÈñòîðèÿ

ðåôåðàòûÊàðòîãðàôèÿ

ðåôåðàòûÊîìïüþòåðíûå ñåòè

ðåôåðàòûÊîìïüþòåðû ÝÂÌ

ðåôåðàòûÊîñìåòîëîãèÿ

ðåôåðàòûÊóëüòóðîëîãèÿ

ðåôåðàòûËèòåðàòóðà

ðåôåðàòûÌàðêåòèíã

ðåôåðàòûÌàòåìàòèêà

ðåôåðàòûÌàøèíîñòðîåíèå

ðåôåðàòûÌåäèöèíà

ðåôåðàòûÌåíåäæìåíò

ðåôåðàòûÌóçûêà

ðåôåðàòûÍàóêà è òåõíèêà

ðåôåðàòûÏåäàãîãèêà

ðåôåðàòûÏðàâî

ðåôåðàòûÏðîìûøëåííîñòü ïðîèçâîäñòâî

ðåôåðàòûÐàäèîýëåêòðîíèêà

ðåôåðàòûÐåêëàìà

ðåôåðàòûÐåôåðàòû ïî ãåîëîãèè

ðåôåðàòûÌåäèöèíñêèå íàóêàì

ðåôåðàòûÓïðàâëåíèå

ðåôåðàòûÔèçèêà

ðåôåðàòûÔèëîñîôèÿ

ðåôåðàòûÔèíàíñû

ðåôåðàòûÔîòîãðàôèÿ

ðåôåðàòûÕèìèÿ

ðåôåðàòûÝêîíîìèêà

ðåôåðàòû
ðåôåðàòû Èíôîðìàöèÿ ðåôåðàòû
ðåôåðàòû
ðåôåðàòû

Ðàçðàáîòêà ñèíòàêñè÷åñêîãî ðàñïîçíàâàòåëÿ âû÷èñëÿåìîãî îïåðàòîðà ïåðåõîäà ÿçûêà


Ìèíèñòåðñòâî íàóêè, âûñøåé øêîëû è òåõíè÷åñêîé ïîëèòèêè Ðîññèéñêîé
Ôåäåðà­öèè.
Íîâîñèáèðñêèé Ãîñóäàðñòâåííûé
Òåõíè÷å­ñêèé Óíèâåðñèòåò.
Êóðñîâàÿ ðàáîòà ïî ñèñòåìíîìó
ïðîãðàììèðîâàíèþ.
Ðàçðàáîòêà
ñèíòàêñè÷åñêîãî ðàñïîçíàâàòåëÿ âû÷èñëÿåìîãî îïåðàòîðà ïåðåõîäà ÿçûêà FORTRAN.
Ôàêóëüòåò: ÀÂÒ.
Êàôåäðà: ÀÑÓ.
Ãðóïïà: À-513.
Ñòóäåíò: Áîðçîâ
Àíäðåé Íèêîëàåâè÷.
Ïðåïîäàâàòåëü:
Øîðíèêîâ Þðèé Âëàäèìèðîâè÷.
Àññèñòåíò: Ïàíîâà
Âåðà Áîðèñîâíà.
Äàòà: 19 ìàÿ
1997 ãîäà.
Îòìåòêà î
çàùèòå: _______________________________
Íîâîñèáèðñê
1997.
ßçûê
îïåðàòîðà.
ßçûê âû÷èñëÿåìîãî
îïåðàòîðà ïåðåõîäà ÿçûêà FORTRAN.
GOTO ÌÅÒÊÀ½ÊÎÍÑÒÀÍÒÀ½ÀÐÈÔÌÅÒÈ×ÅÑÊÎÅ
ÂÛÐÀÆÅÍÈÅ
ÌÅÒÊÀ           – Èäåíòèôèêàòîð
ÊÎÍÑÒÀÍÒÀ – ÖÅËÎÅ ÁÅÇ
ÇÍÀÊÀ
ÀÐÈÔÌÅÒÈ×ÅÑÊÎÅ
ÂÛÐÀÆÅÍÈÅ – ÂÛÐÀÆÅÍÈÅ, ÑÎÄÅÐÆÀÙÅÅ Â ÑÅÁÅ ÎÏÅÐÀÖÈÈ *, /, -, +, **, À ÒÀÊÆÅ ( ).
** – ÂÎÇÂÅÄÅÍÈÅ Â
ÑÒÅÏÅÍÜ.
Ãðàììàòèêà
ÿçûêà.
G[<ÎÏÅÐÀÒÎÐ>]:
1.<ÎÏÅÐÀÒÎÐ> ®
GOTO <ÂÛÐÀÆÅÍÈÅ>
2.<ÂÛÐÀÆÅÍÈÅ> ® Ò ç<ÂÛÐÀÆÅÍÈÅ>+Ò ç <ÂÛÐÀÆÅÍÈÅ>-Ò
3.Ò ® Î çÒ*Î ç Ò/Î êÒ**Î
4.Î ®(<ÂÛÐÀÆÅÍÈÅ>) ç<ÈÄÅÍÒÈÔÈÊÀÒÎÐ> ç<ÄÁÇ>
5.<ÈÄÅÍÒÈÔÈÊÀÒÎÐ> ® Á{Á çÖ}[L]
6.<ÄÁÇ> ® Ö{Ö}[.Ö{Ö}][L] Ò – ÒÅÐÌ Î – ÎÏÅÐÀÍÄ Á – ÁÓÊÂÀ Ö – ÖÈÔÐÀ ÄÁÇ – ÄÐÎÁÍÎÅ ÁÅÇ ÇÍÀÊÀ L – ÊÎÍÅÖ ÑÒÐÎÊÈ (ïóñòî) ** – ÂÎÇÂÅÄÅÍÈÅ Â ÑÒÅÏÅÍÜ
Êëàññèôèêàöèÿ
ãðàììàòèêè.
Äàííàÿ ãðàììàòèêà G[<ÎÏÅÐÀÒÎÐ>],
ñîãëàñíî êëàññèôèêàöèè Õîìñêîãî, ÿâëÿåòñÿ êîíòåêñòíî-ñâîáîäíîé, òàê êàê ïðàâàÿ
÷àñòü êàæäîé ðåäóêöèè íà÷èíàåòñÿ ëèáî ñ òåðìèíàëüíîãî ñèìâîëà, ëèáî ñ
íåòåðìèíàëüíîãî, ïðèíàäëåæàùåãî îáúåäèí¸ííîìó ñëîâàðþ.
A ® a, AÎVn, aÎV*.
Ãðàììàòèêà G[<ÎÏÅÐÀÒÎÐ>] íå ÿâëÿåòñÿ àâòîìàòíîé, òàê
êàê íå âñå å¸ ðåäóêöèè íà÷èíàþòñÿ ñ òåðìèíàëüíîãî ñèìâîëà. Ïî ýòîé æå ïðè÷èíå
äàííàÿ ãðàììàòèêà íå ÿâëÿåòñÿ S - ãðàììàòèêîé.
Ìåòîä
àíàëèçà.
Äëÿ äàííîé ãðàììàòèêè
ðåàëèçîâàí ðàçáîð ìåòîäîì ðåêóðñèâíîãî ñïóñêà, ïîñêîëüêó îíà îòíîñèòñÿ ê êëàññó
êîíòåêñòíî-ñâîáîäíûõ.
        Èäåÿ
ìåòîäà ñîñòîèò â òîì, ÷òî êàæäîìó íåòåðìèíàëüíîìó ñèìâîëó ñòàâèòñÿ â
ñîîòâåòñòâèå îïðåäåë¸ííàÿ ïðîãðàììíàÿ åäèíèöà (ôóíêöèÿ), êîòîðàÿ ðàñïîçíà¸ò
öåïî÷êó, ïîðîæäàåìóþ ýòèì íåòåðìèíàëîì.
        Ýòè
ïðîöåäóðû è ôóíêöèè âûçûâàþòñÿ â ñîîòâåòñòâèè ñ ïðàâèëàìè ãðàììàòèêè è èíîãäà
âûçûâàþò ñàìè ñåáÿ.
        Äàííûé
ìåòîä ðåàëèçîâàí íà ÿçûêå C++, ïîñêîëüêó îí îáëàäàåò
ðåêóðñèâíûìè âîçìîæíîñòÿìè.
Äèàãíîñòèêà
è íåéòðàëèçàöèÿ îøèáîê.
Äëÿ äàííîé ãðàììàòèêè
ïðîèçâîäèòñÿ òîëüêî äèàãíîñòèêà è íåéòðàëèçàöèÿ îøèáîê. Èñïðàâëåíèå îøèáîê íå
ïðîèçâîäèòñÿ.
Íåéòðàëèçàöèÿ îøèáîê
îñóùåñòâëÿåòñÿ ïî ìåòîäó Àéðîíñà, òî åñòü, ñïóñêàÿñü ïî ñèíòàêñè÷åñêîìó äåðåâó
áåç âîçâðàòà ïî êîíòåêñòó, ïðè îáíàðóæåíèè òóïèêîâîé ñèòóàöèè îòáðàñûâàþòñÿ òå
ëèòåðû (ñèìâîëû), êîòîðûå ïðèâåëè â òóïèêîâóþ ñèòóàöèþ è ðàçáîð ïðîäîëæàåòñÿ.
Òåñòèðîâàíèå.
¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
Ïðîòîêîë ðàáîòû
ñèíòàêñè÷åñêîãî ðàñïîçíàâàòåëÿ âû÷èñëÿåìîãî îïåðàòîðà ïåðåõîäà ÿçûêà FORTRAN.
¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
GOTO A+B-DD**(CC/(23+34**R))+Y*((C))
¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
AB    - Ïðîâåðêà íà
Àðèôìåòè÷åñêîå Âûðàæåíèå.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë 'A' ñ êîäîì 65.
T     - Ïðîâåðêà íà
Òåðì.
O     - Ïðîâåðêà íà
Îïåðàíä.
IDENT - Ïðîâåðêà íà Èäåíòèôèêàòîð ñ ñèìâîëà A.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë '+' ñ êîäîì 43.
AB    - Ïðîâåðêà íà
Àðèôìåòè÷åñêîå Âûðàæåíèå.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë 'B' ñ êîäîì 66.
T     - Ïðîâåðêà íà
Òåðì.
O     - Ïðîâåðêà íà
Îïåðàíä.
IDENT - Ïðîâåðêà íà Èäåíòèôèêàòîð ñ ñèìâîëà B.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë '-' ñ êîäîì 45.
AB    - Ïðîâåðêà íà
Àðèôìåòè÷åñêîå Âûðàæåíèå.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë 'D' ñ êîäîì 68.
T     - Ïðîâåðêà íà
Òåðì.
O     - Ïðîâåðêà íà
Îïåðàíä.
IDENT - Ïðîâåðêà íà Èäåíòèôèêàòîð ñ ñèìâîëà D.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë 'D' ñ êîäîì 68.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë '*' ñ êîäîì 42.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë '*' ñ êîäîì 42.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë '(' ñ êîäîì 40.
T     - Ïðîâåðêà íà
Òåðì.
O     - Ïðîâåðêà íà
Îïåðàíä.
AB    - Ïðîâåðêà íà
Àðèôìåòè÷åñêîå Âûðàæåíèå.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë 'C' ñ êîäîì 67.
T     - Ïðîâåðêà íà
Òåðì.
O     - Ïðîâåðêà íà
Îïåðàíä.
IDENT - Ïðîâåðêà íà Èäåíòèôèêàòîð ñ ñèìâîëà C.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë 'C' ñ êîäîì 67.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë '/' ñ êîäîì 47.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë '(' ñ êîäîì 40.
T     - Ïðîâåðêà íà
Òåðì.
O     - Ïðîâåðêà íà
Îïåðàíä.
AB    - Ïðîâåðêà íà
Àðèôìåòè÷åñêîå Âûðàæåíèå.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë '2' ñ êîäîì 50.
T     - Ïðîâåðêà íà
Òåðì.
O     - Ïðîâåðêà íà
Îïåðàíä.
IDENT - Ïðîâåðêà íà Èäåíòèôèêàòîð ñ ñèìâîëà 2.
FLOAT   - Ïðîâåðêà íà
Äðîáíîå Áåç Çíàêà ñ öèôðû 2.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë '3' ñ êîäîì 51.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë '+' ñ êîäîì 43.
AB    - Ïðîâåðêà íà
Àðèôìåòè÷åñêîå Âûðàæåíèå.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë '3' ñ êîäîì 51.
T     - Ïðîâåðêà íà
Òåðì.
O     - Ïðîâåðêà íà
Îïåðàíä.
IDENT - Ïðîâåðêà íà Èäåíòèôèêàòîð ñ ñèìâîëà 3.
FLOAT   - Ïðîâåðêà íà
Äðîáíîå Áåç Çíàêà ñ öèôðû 3.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë '4' ñ êîäîì 52.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë '*' ñ êîäîì 42.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë '*' ñ êîäîì 42.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë 'R' ñ êîäîì 82.
T     - Ïðîâåðêà íà
Òåðì.
O     - Ïðîâåðêà íà
Îïåðàíä.
IDENT - Ïðîâåðêà íà Èäåíòèôèêàòîð ñ ñèìâîëà R.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë ')' ñ êîäîì 41.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë ')' ñ êîäîì 41.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë '+' ñ êîäîì 43.
AB    - Ïðîâåðêà íà
Àðèôìåòè÷åñêîå Âûðàæåíèå.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë 'Y' ñ êîäîì 89.
T     - Ïðîâåðêà íà
Òåðì.
O     - Ïðîâåðêà íà
Îïåðàíä.
IDENT - Ïðîâåðêà íà Èäåíòèôèêàòîð ñ ñèìâîëà Y.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë '*' ñ êîäîì 42.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë '(' ñ êîäîì 40.
T     - Ïðîâåðêà íà
Òåðì.
O     - Ïðîâåðêà íà
Îïåðàíä.
AB    - Ïðîâåðêà íà
Àðèôìåòè÷åñêîå Âûðàæåíèå.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë '(' ñ êîäîì 40.
T     - Ïðîâåðêà íà
Òåðì.
O     - Ïðîâåðêà íà
Îïåðàíä.
AB    - Ïðîâåðêà íà
Àðèôìåòè÷åñêîå Âûðàæåíèå.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë 'C' ñ êîäîì 67.
T     - Ïðîâåðêà íà
Òåðì.
O     - Ïðîâåðêà íà
Îïåðàíä.
IDENT - Ïðîâåðêà íà Èäåíòèôèêàòîð ñ ñèìâîëà C.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë ')' ñ êîäîì 41.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë ')' ñ êîäîì 41.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë NULL ñ êîäîì 0.
¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
GOTO A
¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
AB    - Ïðîâåðêà íà
Àðèôìåòè÷åñêîå Âûðàæåíèå.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë 'A' ñ êîäîì 65.
T     - Ïðîâåðêà íà
Òåðì.
O     - Ïðîâåðêà íà
Îïåðàíä.
IDENT - Ïðîâåðêà íà Èäåíòèôèêàòîð ñ ñèìâîëà A.
SCAN  - Ñêàíèðîâàíèå.
Òåêóùèé ñèìâîë NULL ñ êîäîì 0.
¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
Ëèñòèíã
ïðîãðàììû.
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
//          FILE "KURSOVIK.CPP".
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
//          ÂÀÐÈÀHÒ ¹ 3.
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
//          Îïåðàòîð ïåðåõîäà âû÷èñëÿåìûé ÿçûêà
FORTRAN.
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
//             Êàôåäðà: ÀÑÓ.
//             Ãðóïïà: À-513.
//             Ñòóäåíò: Áîðçîâ Àíäðåé Hèêîëàåâè÷.
//             Ïðåïîäàâàòåëè:   êàíäèäàò
òåõíè÷åñêèõ íàóê, äîöåíò Øîðíèêîâ Þðèé Âëàäèìèðîâè÷,
//                                             àññèñòåíò Ïàíîâà Âåðà
Áîðèñîâíà.
//             Äàòà: 29 àïðåëÿ 1997ã.
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
//             Ïîäêëþ÷àåìûå ôàéëû.
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
#include<string.h>
#include<conio.h>
#include<stdio.h>
#include<dos.h>
#include<stdlib.h>
#include<ctype.h>
#include<time.h>
#include"keyboard.h"
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
//             Ìàêðîîïðåäåëåíèÿ.
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
#define   ERROR                                   0                              // Êîä îøèáêè.
#define   COL_STR                              20                            // Ìàêñèìàëüíîå
êîëè÷åñòâî ñòðîê.
#define   STR_LEN                              35                            // Äëèíà ñòðîêè.
#define   MAX_STR_LEN                  255                          // Ìàêñèìàëüíàÿ äëèíà ñòðîêè.
#define   FILENAME                           "TEST.TXT"         // Èìÿ ôàéëà, îòêðûâàåìîãî ïî
óìîë÷àíèþ.
#define   YES                                         1
#define   NO                                          2
#define   OK                                          3
//#define TEST                                     //
Îïðåäåëåíî, åñëè âêëþ÷åí îòëàäî÷íûé ðåæèì.
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
//             Ïðîòîòèïû ôóíêöèé.
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
int           I_ReadKey(void);                                                //
Îïðîñ êëàâèàòóðû.
void        Welcome(void);                                                   //
Ýêðàí ïðè ñòàðòå ïðîãðàììû.
void        Menu(void);                                                         //
Ìåíþ.
void        Help(void);                                                            //
Ïîìîùü.
void        MyExit(int=0);                                                      //
Êîððåêòíûé âûõîä èç ïðîãðàììû.
void        Beep(int=500,int=100);                                        //
Çâóêîâîé ñèãíàë.
void        Usage(void);                                                         //
Èñïîëüçîâàíèå ïðîãðàììû.
int           OpenFile(void);                                                    //
Îòêðûòèå ôàéëà.
void        DrawBox(int,int,int,int,char*);                           // Ðèñóåò ðàìêó ñ çàãîëîâêîì.
void        PrintText(void);                                                    //
Ïå÷àòàåò îñíîâíîé òåêñò.
void        Screen(void);                                                        //
Ïåðåðèñîâêà ýêðàíà.
void        Compile(void);                                                      //
Êîìïèëÿöèÿ.
void        Message(int);                                                       //
Âûâîä ñîîáùåíèé îá îøèáêàõ.
void        MyPuts(char*,int);                                              //
Àíàëîã puts(char*);.
void        Language(void);                                                  //
ßçûê îïåðàòîðà.
void        Grammar(void);                                                     //
Ãðàììàòèêà ÿçûêà.
void        GetFilename(void);                                              //
Çàïðîñ èìåíè ôàéëà äëÿ îòêðûòèÿ.
int           ScanStr(char*);                                                    //
Ïîèñê GOTO.
int           Scaner(char*);                                                      //
Îáðàáîòêà ñòðîêè.
void        Scan(void);                                                           //
Ñêàíèðîâàíèå ñëåäóþùåãî ñèìâîëà.
void        Delspace(char*);                                                  // Óäàëåíèå íåíóæíûõ ïðîáåëîâ â
ñòðîêå.
int           AB(void);                                                              //
Ðåàëèçàöèÿ íåòåðìèíàëà <ÀÂ>.
int           T(void);                                                                 //
Ðåàëèçàöèÿ íåòåðìèíàëà <Ò>.
int           O(void);                                                                 //
Ðåàëèçàöèÿ íåòåðìèíàëà <Î>.
int           IDENT(void);                                                        //
Ðåàëèçàöèÿ íåòåðìèíàëà <IDENT>.
int           FLOAT(void);                                                      //
Ðåàëèçàöèÿ íåòåðìèíàëà <FLOAT>.
void        Error(int=0,char* ="");                                        // Îáðàáîòêà îøèáêè.
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
//             Ãëîáàëüíûå ïåðåìåííûå.
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
char        filename[MAX_STR_LEN];                               //
Èìÿ ôàéëà.
char        *text[COL_STR+1];                                             //
Ìàññèâ óêàçàòåëåé íà ñòðîêè òåêñòà.
char        screen[4096];                                                        //
Áóôåð ïîä êîïèþ ýêðàíà.
char        mes[21][20][80];                                                    // Ìàññèâ ïîä ñîîáùåíèÿ îá
îøèáêàõ.
char        nx;                                                                           //
Òåêóùèé ñèìâîë.
int           pos;                                                                        //
Òåêóùàÿ ïîçèöèÿ â ñòðîêå.
char        STR[80];                                                                //
Ñêàíèðóåìàÿ ñòðîêà.
int           ERR1;                                                                     //
Ñ÷åò÷èê ñòðàíèö â ìàññèâå îøèáîê.
int           ERR2;                                                                     //
Ñ÷åò÷èê ñòðîê â ìàññèâå îøèáîê.
FILE        *errors;                                                                  //
Äåñêðèïòîð ôàéëà.
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
//             Ôóíêöèÿ MAIN.
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
void main(int argc,char*
argv[])
                {
                textcolor(LIGHTGRAY);
                textbackground(BLACK);
                _setcursortype(_NOCURSOR);
                clrscr();
                if(argc>2)
                                {
                                Usage();
                                MyExit();
                                }
                if(argc==2)
                                strcpy(filename,argv[1]);
                else
                                {
                                Welcome();
                                gettext(20,7,60,17,screen);
                                GetFilename();
                                }
                while(OpenFile())
                                {
                                puttext(20,7,60,17,screen);
                                GetFilename();
                                }
                Menu();
                }
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
//             Âûâîä ñîîáùåíèé îá îøèáêàõ.
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
void Message(int j)
                {
                window(42,3,79,23);
                textcolor(BLUE);
                textbackground(CYAN);
                clrscr();
                for(int i=0;i<COL_STR &&
mes[j][i][0]!=NULL;i++)
                                cprintf("%-30s\r\n",mes[j][i]);
                }
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
//             Ãpàììàòèêà ÿçûêà.
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
void Grammar(void)
                {
                window(1,25,80,25);
                textattr(112);
                MyPuts(" ~F1~ Help  ~F2~ Grammar  ~F3~
Language  ~F9~ Compile  ~F10~ Quit 
~Alt-X~
Quit  ~Esc~
Quit",DARKGRAY);
                window(10,5,70,20);
                textcolor(WHITE);
                textbackground(MAGENTA);
                clrscr();
                DrawBox(2,1,60,16,"Ãpàììàòèêà ÿçûêà");
                window(12,6,78,19);
                textcolor(YELLOW);
                cputs("\r\n");
                cputs(" 1. <Îïåpàòîp> -> GOTO
<Âûpàæåíèå>\r\n");
                cputs(" 2. <Âûpàæåíèå> -> T |
<Âûpàæåíèå>+T | <Âûpàæåíèå>-T\r\n");
                cputs(" 3. T -> O | T*O | T/O |
T**O\r\n");
                cputs(" 4. O -> (<Âûpàæåíèå>) |
<Èäåíòèôèêàòîp> | <ÄÁÇ>\r\n");
                cputs(" 5. <Èäåíòèôèêàòîp> -> ÁÖ[L]\r\n");
                cputs(" 6. <ÄÁÇ> -> Ö{Ö}[.Ö{Ö}][L]\r\n\n");
                cputs(" T    
- Òåpì;\r\n");
                cputs(" O    
- Îïåpàíä;\r\n");
                cputs(" Á    
- Áóêâà;\r\n");
                cputs(" Ö    
- Öèôpà;\r\n");
                cputs(" ÄÁÇ  
- Äðîáíîå Áåç Çíàêà;\r\n");
                cputs(" **   
- âîçâåäåíèå â ñòåïåíü.");
                I_ReadKey();
                }
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
//             ßçûê îïåðàòîðà.
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
void Language(void)
                VAR
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
//             Êîìïèëÿöèÿ.
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
void Compile(void)
                {
                static int compile=0;
                window(1,25,80,25);
                textattr(112);
                MyPuts(" ~F1~ Help  ~F2~ Grammar  ~F3~
Language  ~F9~ Compile  ~F10~ Quit 
~Alt-X~
Quit  ~Esc~
Quit",DARKGRAY);
                window(20,8,60,18);
                textcolor(WHITE);
                textbackground(RED);
                clrscr();
                DrawBox(2,1,40,11,"Êîìïèëÿöèÿ");
                window(22,9,58,17);
                textcolor(YELLOW);
                cputs("\r\n");
                if(compile>0)
                                {
                                cputs(" Òåêñò ÓÆÅ
îòêîìïèëèðîâàí!!!");
                                Beep(900,1000);
                                return;
                                }
                errors=fopen("PROTOCOL.TXT","wt");
                cputs(" Èäåò êîìïèëÿöèÿ.\r\n\n Ïîæàëóéñòà,
ïîäîæäèòå...");
#ifdef TEST
window(1,1,80,25);
textattr(78);
clrscr();
#endif
                fprintf(errors,"/*******************************************************\n");
                fprintf(errors,"––––––––––––––––––––––––––––––––––––––––––––––––––––––––\n");
                fprintf(errors,"ç   Ïðîòîêîë
ðàáîòû ñèíòàêñè÷åñêîãî ðàñïîçíàâàòåëÿ âû÷èñëÿåìîãî ç\n");
                fprintf(errors,"ç                         îïåðàòîðà ïåðåõîäà ÿçûêà FORTRAN.                       ç\n");
                fprintf(errors,"––––––––––––––––––––––––––––––––––––––––––––––––––––––––\n");
                for(int i=0;text[i] != NULL;i++)
                                Scaner(text[i]);
                fprintf(errors,"––––––––––––––––––––––––––––––––––––––––––––––––––––––––\n");
                fprintf(errors,"ç                
                      ÊÎÍÅÖ.                                                        ç\n");
                fprintf(errors,"––––––––––––––––––––––––––––––––––––––––––––––––––––––––\n");
                fprintf(errors,"*******************************************************/\n");
                Beep(900,100);
                compile++;
                }
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
//             Îáðàáîòêà ñòðîêè.
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
int Scaner(char* string)
                {
                char tmpstr[STR_LEN];
                strcpy(tmpstr,string);
                Delspace(tmpstr);
                ScanStr(tmpstr);
                return 0;
                }
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
//             Ïîèñê â ñòðîêå îïåðàòîðà GOTO.
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
int ScanStr(char* string)
                {
                int j;
                int i=0;
                int k=0;
                static int a=0;
                char tmp[80];
                char label=NO;
                strcpy(STR,string);
                fprintf(errors,"––––––––––––––––––––––––––––––––––––––––––––––––––––––––\n");
                fprintf(errors,"%s\n",string);
                fprintf(errors,"––––––––––––––––––––––––––––––––––––––––––––––––––––––––\n");
                do
                                {
                                tmp[0]=NULL;
                                j=0;
                                while(!isspace(string[k++])
&& string[k-1]!=NULL)
                                                {
                                                tmp[j++]=string[k-1];
                                                }
                                tmp[j]=NULL;
                                if((strcmp(tmp,"GOTO") !=
0) && !isdigit(tmp[0]))
                                                {
#ifdef TEST
cprintf("Íå îïðåäåëåí
èäåíòèôèêàòîð %s.\r\n",tmp);
#endif
                                                ERR1=a;
                                                ERR2=i;
                                                i++;
                                                Error(5,tmp);
                                                }
                                else if(!isdigit(tmp[0]))
                                                {
                                                label=YES;
                                                ERR1=a;
                                                ERR2=i;
                                                pos=k;
                                                while(AB()!=OK);
                                                break;
                                                }
                                }
                while(string[k] != NULL);
                if(label==NO)
                                {
#ifdef TEST
cprintf("Íå íàéäåí
îïåðàòîð GOTO.\r\nÑòðîêà ðàçáîðó íå ïîäëåæèò.\r\n");
#endif
                                Error(6);
                                }
                a++;
                return(OK);
                }
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
//             Óäàëåíèå â ñòðîêå ïðîáåëîâ.
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
void Delspace(char* string)
                {
                char str[STR_LEN];
                int j=0;
                int i=0;
                while(isspace(string[i]) && string[i] !=
NULL)
                                i++;
                for(;string[i] != NULL;i++)
                                {
                                if(islower(string[i]))
                                                string[i]=toupper(string[i]);
                                str[j++]=string[i];
                                }
                str[j]=NULL;
                sprintf(string,"%s",str);
                string[j-1]=NULL;
#ifdef TEST
textattr(30);
clreol();
cputs(string);
textattr(78);
cputs("\r\n");
#endif
                }
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
//             Ðåàëèçàöèÿ íåòåðìèíàëà <Àðèôìåòè÷åñêîå Âûðàæåíèå>.
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
int AB(void)
                {
#ifdef TEST
cprintf("AB    - Ïðîâåðêà íà Àðèôìåòè÷åñêîå
Âûðàæåíèå.\r\n");
#endif
                fprintf(errors,"AB    - Ïðîâåðêà íà Àðèôìåòè÷åñêîå Âûðàæåíèå.\n");
                Scan();
                T();
                if(nx=='+')
                                {
                                AB();
                                }
                else if(nx=='-')
                                {
                                AB();
                                }
                if(nx==NULL)
                                return(OK);
                else if(nx!='*' && nx!='/' &&
nx!=')')
                                Error(1);
                return(YES);
                }
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
//             Ðåàëèçàöèÿ íåòåðìèíàëà <Òåðì>.
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
int T(void)
                {
#ifdef TEST
cprintf("T     - Ïðîâåðêà íà Òåðì.\r\n");
#endif
                fprintf(errors,"T     - Ïðîâåðêà íà Òåðì.\n");
                O();
                if(nx=='/')
                                {
                                Scan();
                                T();
                                }
                else if(nx=='*')
                                {
                                Scan();
                                if(nx=='*')
                                                {
                                                Scan();
                                                T();
                                                }
                                else T();
                                }
                if(nx==NULL)
                                return(OK);
                else if(nx!='+' && nx!='-' &&
nx!=')')
                                Error(2);
                return(OK);
                }
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
//             Ðåàëèçàöèÿ íåòåðìèíàëà <Îïåðàíä>.
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
int O(void)
                {
#ifdef TEST
cprintf("O     - Ïðîâåðêà íà Îïåðàíä.\r\n");
#endif
                fprintf(errors,"O     - Ïðîâåðêà íà Îïåðàíä.\n");
                if(nx=='(')
                                {
                                AB();
                                if(nx!=')')
                                                Error(3);
                                else
                                                {
                                                Scan();
                                                return(OK);
                                                }
                                }
                else        
if(IDENT() == NO)
                                                {
                                                if(FLOAT()
== NO)
                                                                Error(4);
                                                }
                return(OK);
                }
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
//             Ðåàëèçàöèÿ íåòåðìèíàëà <Èäåíòèôèêàòîð>.
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
int IDENT(void)
                {
#ifdef TEST
cprintf("IDENT -
Ïðîâåðêà íà Èäåíòèôèêàòîð ñ ñèìâîëà %c.\r\n",nx);
getch();
#endif
                fprintf(errors,"IDENT - Ïðîâåðêà íà
Èäåíòèôèêàòîð ñ ñèìâîëà %c.\n",nx);
                if(isalpha(nx))
                                isdigit(nx))

                return(NO);
                }
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
//             Ðåàëèçàöèÿ íåòåðìèíàëà <Äðîáíîå Áåç Çíàêà>.
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
int FLOAT(void)
                {
#ifdef TEST
cprintf("FLOAT   - Ïðîâåðêà íà Äðîáíîå Áåç Çíàêà ñ öèôðû
%c.\r\n",nx);
getch();
#endif
                fprintf(errors,"FLOAT   - Ïðîâåðêà íà Äðîáíîå Áåç Çíàêà ñ öèôðû %c.\n",nx);
                if(isdigit(nx))
                                {
                                while(isdigit(nx))
                                                Scan();
                                if(nx=='.')
                                                {
                                                Scan();
                                                while(isdigit(nx))
                                                                Scan();
                                                }
                                return(YES);
                                }
                return(NO);
                }
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
//             Ñêàíèðîâàíèå ñëåäóþùåãî ñèìâîëà èç ñòðîêè.
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
void Scan(void)
                {
#ifdef TEST
cprintf("SCAN  - Ñêàíèðîâàíèå. Òåêóùèé ñèìâîë '%c' ñ êîäîì
%d.\r\n",STR[pos],STR[pos]);
getch();
#endif
                fprintf(errors,"SCAN  - Ñêàíèðîâàíèå. Òåêóùèé ñèìâîë '%c' ñ êîäîì
%d.\n",STR[pos],STR[pos]);
                nx=STR[pos];
                pos++;
                }
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
//             Îáðàáîòêà îøèáîê.
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
void Error(int num,char* s)
                {
                char *E[40]=
                                 
{
                                 
"Îæèäàåòñÿ '+' èëè '-'",
                                 
"Îæèäàåòñÿ '*', '/' èëè '**'",
                                 
"Îæèäàåòñÿ ')'",
                                 
"Îæèäàåòñÿ èäåíòèôèêàòîð èëè Äðîáíîå áåç çíàêà",
                                 
"Íå îïðåäåëåí èäåíòèôèêàòîð ",
                                 
"Íå íàéäåí îïåðàòîð GOTO\r\nÑòðîêà ðàçáîðó íå ïîäëåæèò",
                                 
NULL
                                 
};
                sprintf(mes[ERR1][ERR2],"%s%s",E[num-1],s);
                fprintf(errors,"––––––––––––––––––––––––––––––––––––––––––––––––––––––––\n");
                fprintf(errors,"Error - Îøèáêà ñòðîêà %d, îøèáêà
# %d.\n",ERR1,ERR2);
#ifdef TEST
cprintf("Error - Îøèáêà:
ñòðîêà # %d, îøèáêà # %d.\r\n",ERR1,ERR2);
cprintf("%s\r\n",mes[ERR1][ERR2]);
Beep(1000,200);
getch();
#endif
                fprintf(errors,"%s\n",mes[ERR1][ERR2]);
                fprintf(errors,"––––––––––––––––––––––––––––––––––––––––––––––––––––––––\n");
                ERR2++;
                mes[ERR1][ERR2][0]=NULL;
                }
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
//             Ïîäêëþ÷àåìûé ôàéë.
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
#include"intface.h"             // Ôàéë ñ ôóíêöèÿìè èíòåðôåéñà.
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
// Ó 1997 Áîðçîâ
Àíäðåé Hèêîëàåâè÷. E-mail: ANDREY@RedHouse.nstu.nsk.su.
//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
Ëèòåðàòóðà.
1. Êóðñ ëåêöèé ïî ñèñòåìíîìó
ïðîãðàììèðîâàíèþ.
2. Ãåðáåðò Øèëäò «C äëÿ ïðîôåññèîíàëüíûõ ïðîãðàììèñòîâ».
ðåôåðàòû Ðåêîìåíäóåì ðåôåðàòûðåôåðàòû

     
Ðåôåðàòû @2011