Changeset 19 for branches/Void/UCompilator.pas
- Timestamp:
- Nov 10, 2009, 4:15:47 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Void/UCompilator.pas
r18 r19 6 6 7 7 uses 8 Classes, SysUtils, UOutputGenerator, UModel, U VoidParser, fgl;8 Classes, SysUtils, UOutputGenerator, UModel, UTokenizer, fgl, UGrammer; 9 9 10 10 type … … 23 23 private 24 24 FOnError: TOnErrorEvent; 25 Grammer: TGrammer; 25 26 procedure DoError(AText: string); 26 27 procedure ParseBeginEnd; … … 29 30 procedure ParseTypeDefinition; 30 31 procedure ParseExpression; 32 procedure InitGrammer; 31 33 public 32 34 ErrorMessages: TErrorMessageList; … … 49 51 Terminate: Boolean; 50 52 begin 51 with ErrorMessages .Adddo begin53 with ErrorMessages[ErrorMessages.Add(TErrorMessage.Create)] do begin 52 54 CodePosition := Parser.TokenStartPosition; 53 55 Text := AText; … … 147 149 end; 148 150 151 procedure TCompilator.InitGrammer; 152 var 153 RuleProgram, RuleBlock, RuleDeclaration, RuleStatement, RuleConstant, 154 RuleVariable, RuleFunction: TGrammerRule; 155 begin 156 Grammer := TGrammer.Create; 157 with Grammer do begin 158 RuleConstantDefinition := TGrammerRule.Create; 159 with RuleConstantDefinition do begin 160 Name := 'ConstantDefinition'; 161 RuleType := rtSequence; 162 end; 163 Rules.Add(RuleConstantDefinition); 164 165 RuleConstant := TGrammerRule.Create; 166 with RuleConstant do begin 167 Name := 'Constant'; 168 RuleType := rtSequence; 169 AddTerminal('const', ttIdentifier, False, False); 170 AddRule(RuleConstantDefinition, False, False); 171 end; 172 Rules.Add(RuleConstant); 173 174 RuleFunction := TGrammerRule.Create; 175 with RuleFunction do begin 176 Name := 'Function'; 177 RuleType := rtSequence; 178 end; 179 Rules.Add(RuleFunction); 180 181 RuleVariable := TGrammerRule.Create; 182 with RuleVariable do begin 183 Name := 'Variable'; 184 RuleType := rtSequence; 185 end; 186 Rules.Add(RuleVariable); 187 188 RuleStatement := TGrammerRule.Create; 189 with RuleStatement do begin 190 Name := 'Statement'; 191 RuleType := rtSequence; 192 end; 193 Rules.Add(RuleStatement); 194 195 RuleDeclaration := TGrammerRule.Create; 196 with RuleDeclaration do begin 197 Name := 'Declaration'; 198 RuleType := rtAlternative; 199 AddRule(RuleFunction, False, False); 200 AddRule(RuleConstant, False, False); 201 AddRule(RuleVariable, False, False); 202 end; 203 Rules.Add(RuleDeclaration); 204 205 RuleBlock := TGrammerRule.Create; 206 with RuleBlock do begin 207 Name := 'Block'; 208 RuleType := rtSequence; 209 AddRule(RuleDeclaration, False, True); 210 AddRule(RuleStatement, False, False); 211 end; 212 Rules.Add(RuleBlock); 213 214 RuleProgram := TGrammerRule.Create; 215 with RuleProgram do begin 216 Name := 'Program'; 217 RuleType := rtSequence; 218 AddRule(RuleBlock, False, False); 219 AddTerminal('.', ttSymbol, False, False); 220 end; 221 Rules.Add(RuleProgram); 222 223 TopRule := RuleProgram; 224 end; 225 end; 226 149 227 procedure TCompilator.Compile; 150 228 var … … 167 245 Variable: TVariable; 168 246 SourceVariable: TVariable; 169 VariableName: string;170 247 Value: string; 171 248 P: Integer; … … 282 359 constructor TCompilator.Create; 283 360 begin 361 Grammer := TGrammer.Create; 362 InitGrammer; 284 363 ErrorMessages := TErrorMessageList.Create; 285 364 SourceCode := TMemoryStream.Create; … … 290 369 destructor TCompilator.Destroy; 291 370 begin 371 Grammer.Destroy; 292 372 ErrorMessages.Destroy; 293 373 SourceCode.Destroy;
Note:
See TracChangeset
for help on using the changeset viewer.