нерабочая попытка добавить вызовы функций

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
$EXTERN Lexer, Put, Arg, Open, Prout;
$ENTRY Go {
= <Open 'w' 2 <Arg 2>><Put 2 <Parser : <Lexer <Arg 1>>>>;
}
Parser {
: eTokens =
<Program
() /* список ошибок */
() /* список функций */
: eTokens
>;
}
/*
Program =
[$ENTRY] Name FunctionBody Program
| $EXTERN ExternList Program
| пусто .
*/
Program {
tErrorList tFunctions (Directive tPosDir 'ENTRY') (Name tPosName : eName) : eTokens =
<Program-Function
tFunctions eName tPosName Entry
<FunctionBody tErrorList ()() : eTokens>
>;
tErrorList tFunctions (Directive tPosDir 'ENTRY') tOtherToken : eTokens =
<Program
/* Добавляет сообщение */
/* «позиция: unexpected token токен, expected function name» */
/* Позиция и значение неожиданного токена выбирается из tOtherToken */
<AddUnexpectedToken tErrorList tOtherToken 'function name'>
tFunctions tOtherToken : eTokens
>;
tErrorList tFunctions (Name tPos : eName) : eTokens =
<Program-Function
tFunctions eName tPos Local
<FunctionBody tErrorList : eTokens>
>;
tErrorList tFunctions (Directive tPos 'EXTERN') : eTokens =
<ExternList tErrorList tFunctions : eTokens>;
tErrorList tFunctions (EOF tPos '!') =
/* Корректное завершение */
<SemanticAnalysis tErrorList <Reverse tFunctions>>; /* REVERSE */
tErrorList tFunctions tOtherToken : eTokens =
<Program
<AddUnexpectedToken
tErrorList tOtherToken 'function definion or $EXTERN'
>
tFunctions : eTokens
>;
}
FunctionBody {
tErrorList (OpenBlock tposOpenBlock '{') : eTokens =
<Pattern tErrorList () () (()()) : eTokens >;
tErrorList token : eTokens =
<Pattern <AddExpectedCharacter tErrorList token 'open function body'> () () (()()) token : eTokens >; /* ErrorList Sentences Stack Scanned :Terms */
}
AddToken {
tPattern eToken =
tPattern : eToken; /* раз такой порядок, значит не нужно будет делать reverse */
}
/* ErrorList Sentences Stack Scanned :eTerms */
Pattern {
tErrorList sentences openBrackets eScanned (Name posName : eName) : eTokens =
<Prout 'Name'><Pattern tErrorList sentences openBrackets ((Name posName : eName) :eScanned)>;
tErrorList sentences openBrackets eScanned (Char posChar : eChar) : eTokens =
<Prout 'Char'><Pattern tErrorList sentences openBrackets ((Char posChar : eChar) : eScanned) : eTokens>;
tErrorList sentences openBrackets eScanned (Number posNumber : eNumber) : eTokens =
<Prout 'Number'><Pattern tErrorList sentences openBrackets ((Number posNumber : eNumber) : eScanned) : eTokens>;
tErrorList sentences openBrackets (type eScanned) (Variable posVariable : eVariable) : eTokens =
<Prout 'Variable' eVariable><Pattern tErrorList sentences openBrackets (type((Variable posVariable : eVariable) : eScanned)) : eTokens>;
tErrorList sentences eOpenBrackets (type eScanned) (OpenBracket posBracket '(') : eTokens =
<Prout 'OpenBracket'><Pattern tErrorList sentences ((type eScanned) : eOpenBrackets) (BRACKET ()) : eTokens >;
tErrorList sentences ((type eScanned) : eOpenBrackets) (BRACKET eInBrackets) (CloseBracket posBracket ')') : eTokens =
<Prout 'CloseBracket'><Pattern tErrorList sentences eOpenBrackets (<ReverseCheckColon (BRACKET : eInBrackets ) > type eScanned) : eTokens >;
/* Если образец закончился, то есть мы встретили '=' и стек пуст: ()
значит начинаем разбирать результат */
tErrorList sentences () (() eScanned) (Assign posAssgn '=') : eTokens =
<Prout 'Assign'><Result tErrorList sentences <Reverse eScanned> () () : eTokens >; /* вызываем Result и ждем пока обработается результат, чтоб
все это прикрепить к предложениям */
tErrorList sentences () (type eScanned) (Assign posAssgn '=') : eTokens =
<Prout 'Assign'><Result tErrorList sentences <Reverse (type : eScanned)> () () : eTokens >;
tErrorList eSentences () () (CloseBlock posCloseBlock '}') : eTokens =
<Prout 'CloseBlock'><CompleteFunclion tErrorList eSentences : eTokens >;
}
Result {
tErrorList sentences pattern openBrackets eScanned (Name posName : eName) : eTokens =
<Result tErrorList sentences pattern openBrackets ((Name posName : eName) : eScanned) : eTokens>;
tErrorList sentences pattern openBrackets eScanned (Char posChar : eChar) : eTokens =
<Result tErrorList sentences pattern openBrackets ((Char posChar : eChar) : eScanned) : eTokens>;
tErrorList sentences pattern openBrackets eScanned (Number posNumber : eNumber) : eTokens =
<Result tErrorList sentences pattern openBrackets ((Number posNumber : eNumber) : eScanned) : eTokens>;
tErrorList sentences pattern openBrackets eScanned (Variable posVariable : eVariable) : eTokens =
<Result tErrorList sentences pattern openBrackets ((Variable posVariable : eVariable) : eScanned) : eTokens>;
tErrorList sentences pattern eOpenBrackets scanned (OpenBracket posBracket '(') : eTokens =
<Result tErrorList sentences pattern (scanned : eOpenBrackets) ( ) : eTokens >;
tErrorList sentences pattern (eScanned : eOpenBrackets) inBrackets (CloseBracket posBracket ')') : eTokens =
<Result tErrorList sentences pattern eOpenBrackets (<ReverseCheckColon tErrorList inBrackets> : eScanned) : eTokens >;
tErrorList eSentences pattern () scanned (Semicolon posSemicolon ';') : eTokens =
<Pattern tErrorList ((pattern <Reverse scanned>) : eSentences) () (()()) : eTokens >; /* ErrorList Sentences Stack Scanned :Terms */
}
CompleteFunclion {
tErrorList sentences : eTokens =
tErrorList <Reverse sentences> : eTokens;
}
ReverseCheckColon {
( term (Colon pos ':') :eTerms) =
<DoReverseCheck eTerms (LAST term)>;
terms = <DoReverseCheck terms (NIL)>;
/*tErrorList( term (Colon pos ':') :eTerms) =
<DoReverseCheck tErrorList eTerms (LAST term)>;
tErrorList terms = <DoReverseCheck tErrorList terms (NIL)>;*/
}
DoReverseCheck {
/* tErrorList ((Colon pos ':') : eTerms) reversed =
<DoReverseCheck
<AddUnexpectedToken tErrorList (Colon pos ':') 'colon'>
eTerms
reversed
>;*/
(term : eTerms) eReversed =
<DoReverseCheck eTerms (term : eReversed)>;
() reversed = reversed;
}
Reverse {
(term :eTerms) =
<DoReverse eTerms (LAST term)>;
terms = <DoReverse terms (NIL)>;
}
DoReverse {
(term : eTerms) eReversed =
<DoReverse eTerms (term : eReversed)>;
() reversed = reversed;
}
Program-Function {
eFunctions tName tPos sAccess
tErrorList tFunctionBody : eTokens =
<Program
tErrorList
((tName sAccess tPos tFunctionBody) : eFunctions) /* PUSH */
: eTokens
>;
}
/*
ExternList = FunctionName "," ExternList | ";"
*/
ExternList {
tErrorList eFunctions (Name tPosName tName) (Comma tPosComma ',') : eTokens =
<ExternList
tErrorList
((tName Entry tPosName NoBody) : eFunctions) /* PUSH */
: eTokens
>;
tErrorList tFunctions (Semicolon tPos ';') : eTokens =
<Program tErrorList tFunctions : eTokens>;
/*тут ещё будет обработка ошибок (нет имени, нет запятой, внезапный EOF, нет точки с запятой)*/
}
SemanticAnalysis {
tErrorList functions = tErrorList functions;
}
AddUnexpectedToken {
errorList token : eMessage =
((token : eMessage) : errorList);
}
AddExpectedCharacter {
errorList token : eMessage =
((token : eMessage) : errorList);
}