Changeset 212
- Timestamp:
- Apr 22, 2020, 12:04:22 PM (5 years ago)
- Location:
- branches/interpreter2
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/interpreter2/Test.pas
r205 r212 8 8 const 9 9 C: Integer = 1; 10 11 function IsZero(A: Integer): Boolean; 12 begin 13 Result := A = 0; 14 end; 15 10 16 begin 11 17 X := 'A' + 'B'; -
branches/interpreter2/UExecutor.pas
r211 r212 630 630 FuncName: string; 631 631 begin 632 if Expression.Operation = eoAdd then FuncName := '_Add' 633 else if Expression.Operation = eoSub then FuncName := '_Sub' 634 else if Expression.Operation = eoEqual then FuncName := '_Equal' 635 else if Expression.Operation = eoNotEqual then FuncName := '_NotEqual' 636 else raise Exception.Create('Unsupported operation type.'); 637 638 ExecutorFunction := Block.GetTypeFunction(Expression.TypeRef, FuncName); 632 FuncName := Expression.GetFunctionName; 633 634 ExecutorFunction := Block.GetTypeFunction(Expression.FunctionRef.ParentType, FuncName); 635 if not Assigned(ExecutorFunction) then 636 raise Exception.Create('Missing operator function ' + FuncName + ' for type ' + Expression.TypeRef.Name); 637 639 638 Result := Expression.TypeRef.ValueClass.Create; 640 639 -
branches/interpreter2/UGeneratorCSharp.pas
r208 r212 15 15 private 16 16 procedure GenerateProgram(Block: TBlock; Prog:TProgram); 17 procedure GenerateFunction(ParentBlock: TBlock; FunctionDef: TFunction); 17 18 procedure GenerateBlock(ParentBlock: TBlock; Block: TBlock); 18 19 procedure GenerateBlockConst(ParentBlock: TBlock; Block: TBlock); … … 209 210 Indent := Indent + 1; 210 211 GenerateBlock(nil, Prog.SystemBlock); 212 AddTextLine('public static void Main()'); 213 AddTextLine('{'); 214 AddTextLine(' ' + Prog.Name + ' app = new ' + Prog.Name + '();'); 215 AddTextLine(' app.Entry();'); 216 AddTextLine('}'); 217 AddTextLine(); 218 AddTextLine('public void Entry()'); 211 219 GenerateBlock(Block, Prog.Block); 212 220 Indent := Indent - 1; … … 216 224 procedure TGeneratorCSharp.GenerateBlock(ParentBlock: TBlock; Block: TBlock); 217 225 begin 218 GenerateBlockVar(ParentBlock, Block); 219 GenerateBlockConst(ParentBlock, Block); 220 GenerateBlockFunctions(ParentBlock, Block); 221 if ParentBlock = Prog.SystemBlock then 222 AddTextLine('public static void Main()'); 226 GenerateBlockVar(Block, Block); 227 GenerateBlockConst(Block, Block); 228 GenerateBlockFunctions(Block, Block); 223 229 if Block.BeginEnd.Commands.Count > 0 then begin 224 230 GenerateBeginEnd(ParentBlock, Block.BeginEnd); … … 234 240 for I := 0 to Block.Constants.Count - 1 do begin 235 241 Constant := TConstant(Block.Constants[I]); 236 AddText('static ');237 242 GenerateTypeRef(Constant.TypeRef); 238 243 AddText(' ' + Constant.Name + ' = '); … … 248 253 begin 249 254 if Block.Variables.Count > 0 then begin 250 for I := 0 to Block.Variables.Count - 1 do begin 255 for I := 0 to Block.Variables.Count - 1 do 256 if not TVariable(Block.Variables[I]).Internal then begin 251 257 Variable := TVariable(Block.Variables[I]); 252 AddText('static ');253 258 GenerateTypeRef(Variable.TypeRef); 254 259 AddTextLine(' ' + Variable.Name + ';'); … … 258 263 end; 259 264 265 procedure TGeneratorCSharp.GenerateFunction(ParentBlock: TBlock; 266 FunctionDef: TFunction); 267 var 268 I: Integer; 269 begin 270 GenerateTypeRef(FunctionDef.ResultType); 271 AddText(' ' + FunctionDef.Name + '('); 272 for I := 0 to FunctionDef.Params.Count - 1 do begin 273 GenerateTypeRef(TFunctionParameter(FunctionDef.Params[I]).TypeRef); 274 AddText(' '); 275 AddText(TFunctionParameter(FunctionDef.Params[I]).Name); 276 if I > 0 then AddText(', '); 277 end; 278 AddTextLine(')'); 279 if FunctionDef.InternalName <> '' then begin 280 AddTextLine('{'); 281 Indent := Indent + 1; 282 if FunctionDef.InternalName = 'WriteLn' then AddTextLine('Console.Write(Text + "\n");') 283 else if FunctionDef.InternalName = 'Write' then AddTextLine('Console.Write(Text);') 284 else if FunctionDef.InternalName = 'IntToStr' then AddTextLine('return Value.ToString();') 285 else if FunctionDef.InternalName = 'StrToInt' then begin 286 AddTextLine('int x = 0;'); 287 AddTextLine('if (int.TryParse(Value, out x))'); 288 AddTextLine('{'); 289 AddTextLine(' return x;'); 290 AddTextLine('} else return 0;'); 291 end; 292 293 Indent := Indent - 1; 294 AddTextLine('}'); 295 end else begin 296 GenerateBlock(ParentBlock, FunctionDef.Block); 297 AddTextLine; 298 end; 299 end; 300 260 301 procedure TGeneratorCSharp.GenerateBlockFunctions(ParentBlock: TBlock; 261 302 Block: TBlock); 262 303 var 263 304 I: Integer; 264 J: Integer;265 FunctionDef: TFunction;266 305 begin 267 306 for I := 0 to Block.Functions.Count - 1 do begin 268 FunctionDef := TFunction(Block.Functions[I]); 269 AddText('static '); 270 GenerateTypeRef(FunctionDef.ResultType); 271 AddText(' ' + FunctionDef.Name + '('); 272 for J := 0 to FunctionDef.Params.Count - 1 do begin 273 GenerateTypeRef(TFunctionParameter(FunctionDef.Params[J]).TypeRef); 274 AddText(' '); 275 AddText(TFunctionParameter(FunctionDef.Params[J]).Name); 276 if J > 0 then AddText(', '); 277 end; 278 AddTextLine(')'); 279 if FunctionDef.InternalName <> '' then begin 280 AddTextLine('{'); 281 Indent := Indent + 1; 282 if FunctionDef.InternalName = 'WriteLn' then AddTextLine('Console.Write(Text + "\n");') 283 else if FunctionDef.InternalName = 'Write' then AddTextLine('Console.Write(Text);') 284 else if FunctionDef.InternalName = 'IntToStr' then AddTextLine('return Value.ToString();') 285 else if FunctionDef.InternalName = 'StrToInt' then begin 286 AddTextLine('int x = 0;'); 287 AddTextLine('if (int.TryParse(Value, out x))'); 288 AddTextLine('{'); 289 AddTextLine(' return x;'); 290 AddTextLine('} else return 0;'); 291 end; 292 293 Indent := Indent - 1; 294 AddTextLine('}'); 295 end else begin 296 GenerateBeginEnd(ParentBlock, FunctionDef.BeginEnd); 297 AddTextLine; 298 end; 307 GenerateFunction(ParentBlock, TFunction(Block.Functions[I])); 299 308 AddTextLine; 300 309 end; -
branches/interpreter2/UGeneratorPascal.pas
r208 r212 15 15 private 16 16 procedure GenerateProgram(Block: TBlock; Prog:TProgram); 17 procedure GenerateFunction(ParentBlock: TBlock; FunctionDef: TFunction); 17 18 procedure GenerateBlock(ParentBlock: TBlock; Block: TBlock); 18 19 procedure GenerateBlockVar(ParentBlock: TBlock; Block: TBlock); 19 20 procedure GenerateBlockConst(ParentBlock: TBlock; Block: TBlock); 21 procedure GenerateBlockFunctions(ParentBlock: TBlock; Block: TBlock); 20 22 procedure GenerateBeginEnd(Block: TBlock; BeginEnd: TBeginEnd); 21 23 procedure GenerateCommand(Block: TBlock; Command: TCommand); … … 188 190 begin 189 191 if Prog.Name <> '' then AddTextLine('program ' + Prog.Name + ';'); 192 AddTextLine('{$mode delphi}'); 193 AddTextLine('uses SysUtils;'); 190 194 GenerateBlock(Block, Prog.Block); 191 195 AddTextLine('.'); 192 196 end; 193 197 198 procedure TGeneratorPascal.GenerateFunction(ParentBlock: TBlock; 199 FunctionDef: TFunction); 200 var 201 I: Integer; 202 begin 203 AddText('function ' + FunctionDef.Name); 204 if FunctionDef.Params.Count > 0 then begin 205 AddText('('); 206 for I := 0 to FunctionDef.Params.Count - 1 do begin 207 AddText(TFunctionParameter(FunctionDef.Params[I]).Name); 208 AddText(': '); 209 AddText(TFunctionParameter(FunctionDef.Params[I]).TypeRef.Name); 210 if I > 0 then AddText(', '); 211 end; 212 AddText(')'); 213 end; 214 if Assigned(FunctionDef.ResultType) then begin 215 AddText(': '); 216 AddText(FunctionDef.ResultType.Name); 217 end; 218 AddTextLine(';'); 219 if FunctionDef.InternalName <> '' then begin 220 AddTextLine('begin'); 221 Indent := Indent + 1; 222 if FunctionDef.InternalName = 'WriteLn' then AddTextLine('System.WriteLn(Text);') 223 else if FunctionDef.InternalName = 'Write' then AddTextLine('System.Write(Text);') 224 else if FunctionDef.InternalName = 'IntToStr' then AddTextLine('return SysUtils.IntToStr(Value);') 225 else if FunctionDef.InternalName = 'StrToInt' then AddTextLine('return SysUtils.StrToInt(Value);'); 226 Indent := Indent - 1; 227 AddTextLine('end;'); 228 end else begin 229 GenerateBlock(ParentBlock, FunctionDef.Block); 230 AddTextLine(';'); 231 end; 232 end; 233 194 234 procedure TGeneratorPascal.GenerateBlock(ParentBlock: TBlock; Block: TBlock); 195 235 begin 196 236 GenerateBlockConst(ParentBlock, Block); 197 237 GenerateBlockVar(ParentBlock, Block); 238 GenerateBlockFunctions(ParentBlock, Block); 198 239 GenerateBeginEnd(ParentBlock, Block.BeginEnd); 199 240 end; … … 203 244 I: Integer; 204 245 Variable: TVariable; 205 begin 206 if Block.Variables.Count > 0 then begin 246 VarCount: Integer; 247 begin 248 VarCount := 0; 249 for I := 0 to Block.Variables.Count - 1 do 250 if not TVariable(Block.Variables[I]).Internal then Inc(VarCount); 251 252 if VarCount > 0 then begin 207 253 AddTextLine('var'); 208 254 Indent := Indent + 1; 209 for I := 0 to Block.Variables.Count - 1 do begin 255 for I := 0 to Block.Variables.Count - 1 do 256 if not TVariable(Block.Variables[I]).Internal then begin 210 257 Variable := TVariable(Block.Variables[I]); 211 258 AddTextLine(Variable.Name + ': ' + Variable.TypeRef.Name + ';'); … … 249 296 end; 250 297 298 procedure TGeneratorPascal.GenerateBlockFunctions(ParentBlock: TBlock; 299 Block: TBlock); 300 var 301 I: Integer; 302 begin 303 for I := 0 to Block.Functions.Count - 1 do begin 304 GenerateFunction(ParentBlock, TFunction(Block.Functions[I])); 305 AddTextLine; 306 end; 307 end; 308 251 309 procedure TGeneratorPascal.Generate; 252 310 begin -
branches/interpreter2/UGeneratorPhp.pas
r208 r212 15 15 private 16 16 procedure GenerateProgram(Block: TBlock; Prog:TProgram); 17 procedure GenerateFunction(ParentBlock: TBlock; FunctionDef: TFunction); 17 18 procedure GenerateBlock(ParentBlock: TBlock; Block: TBlock); 18 19 procedure GenerateBlockConst(ParentBlock: TBlock; Block: TBlock); … … 201 202 end; 202 203 204 procedure TGeneratorPhp.GenerateFunction(ParentBlock: TBlock; 205 FunctionDef: TFunction); 206 var 207 I: Integer; 208 begin 209 AddText('function ' + FunctionDef.Name + '('); 210 for I := 0 to FunctionDef.Params.Count - 1 do begin 211 AddText('$' + TFunctionParameter(FunctionDef.Params[I]).Name); 212 if I > 0 then AddText(', '); 213 end; 214 AddTextLine(')'); 215 if FunctionDef.InternalName <> '' then begin 216 AddTextLine('{'); 217 Indent := Indent + 1; 218 if FunctionDef.InternalName = 'WriteLn' then AddTextLine('echo($Text."\n");') 219 else if FunctionDef.InternalName = 'Write' then AddTextLine('echo($Text);') 220 else if FunctionDef.InternalName = 'IntToStr' then AddTextLine('return $Value;') 221 else if FunctionDef.InternalName = 'StrToInt' then AddTextLine('return $Value;'); 222 Indent := Indent - 1; 223 AddTextLine('}'); 224 end else begin 225 GenerateBlock(ParentBlock, FunctionDef.Block); 226 AddTextLine; 227 end; 228 end; 229 203 230 procedure TGeneratorPhp.GenerateBlock(ParentBlock: TBlock; Block: TBlock); 204 231 begin … … 228 255 var 229 256 I: Integer; 230 J: Integer;231 FunctionDef: TFunction;232 257 begin 233 258 for I := 0 to Block.Functions.Count - 1 do begin 234 FunctionDef := TFunction(Block.Functions[I]); 235 AddText('function ' + FunctionDef.Name + '('); 236 for J := 0 to FunctionDef.Params.Count - 1 do begin 237 AddText('$' + TFunctionParameter(FunctionDef.Params[J]).Name); 238 if J > 0 then AddText(', '); 239 end; 240 AddTextLine(')'); 241 if FunctionDef.InternalName <> '' then begin 242 AddTextLine('{'); 243 Indent := Indent + 1; 244 if FunctionDef.InternalName = 'WriteLn' then AddTextLine('echo($Text."\n");') 245 else if FunctionDef.InternalName = 'Write' then AddTextLine('echo($Text);') 246 else if FunctionDef.InternalName = 'IntToStr' then AddTextLine('return $Value;') 247 else if FunctionDef.InternalName = 'StrToInt' then AddTextLine('return $Value;'); 248 Indent := Indent - 1; 249 AddTextLine('}'); 250 end else begin 251 GenerateBeginEnd(ParentBlock, FunctionDef.BeginEnd); 252 AddTextLine; 253 end; 259 GenerateFunction(ParentBlock, TFunction(Block.Functions[I])); 254 260 AddTextLine; 255 261 end; -
branches/interpreter2/UParser.pas
r211 r212 20 20 function ParseCommand(Block: TBlock; out Command: TCommand): Boolean; 21 21 function ParseProgram(SystemBlock: TBlock; out Prog: TProgram): Boolean; 22 function ParseBlock(ParentBlock: TBlock; out Block: TBlock ): Boolean;22 function ParseBlock(ParentBlock: TBlock; out Block: TBlock; ExistingBlock: TBlock = nil): Boolean; 23 23 function ParseBlockVar(Block: TBlock): Boolean; 24 24 function ParseBlockConst(Block: TBlock): Boolean; 25 function ParseFunction(Block: TBlock; out Func: TFunction): Boolean; 26 function ParseFunctionParameter(Block: TBlock; out Parameter: TFunctionParameter): Boolean; 25 27 function ParseAssignment(Block: TBlock; out Assignment: TAssignment): Boolean; 26 28 function ParseExpression(Block: TBlock; out Expression: TExpression): Boolean; … … 194 196 end; 195 197 196 function TParser.ParseBlock(ParentBlock: TBlock; out Block: TBlock ): Boolean;198 function TParser.ParseBlock(ParentBlock: TBlock; out Block: TBlock; ExistingBlock: TBlock = nil): Boolean; 197 199 var 198 200 BeginEnd: TBeginEnd; 199 begin 200 Result := False; 201 Block := TBlock.Create; 201 Func: TFunction; 202 begin 203 Result := False; 204 if Assigned(ExistingBlock) then Block := ExistingBlock 205 else Block := TBlock.Create; 202 206 Block.ParentBlock := ParentBlock; 203 ParseBlockVar(Block); 204 ParseBlockConst(Block); 207 while True do begin 208 if ParseBlockVar(Block) then begin 209 end else 210 if ParseBlockConst(Block) then begin 211 end else 212 if ParseFunction(Block, Func) then begin 213 Block.Functions.Add(Func); 214 end else begin 215 Break; 216 end; 217 end; 205 218 if ParseBeginEnd(Block, BeginEnd) then begin 206 219 Result := True; … … 208 221 Block.BeginEnd := BeginEnd; 209 222 BeginEnd.Parent := Block; 210 end else Block.Free; 223 end else begin 224 if not Assigned(ExistingBlock) then Block.Free; 225 Block := nil; 226 end; 211 227 end; 212 228 … … 291 307 end; 292 308 309 function TParser.ParseFunction(Block: TBlock; out Func: TFunction): Boolean; 310 var 311 Token: TToken; 312 FunctionParameter: TFunctionParameter; 313 NewBlock: TBlock; 314 TypeRef: TType; 315 Variable: TVariable; 316 I: Integer; 317 begin 318 Result := False; 319 if Tokenizer.CheckNext('function', tkKeyword) then begin 320 Tokenizer.Expect('function', tkKeyword); 321 Result := True; 322 Func := TFunction.Create; 323 Token := Tokenizer.GetNext; 324 if Token.Kind = tkIdentifier then begin 325 Func.Name := Token.Text; 326 if Tokenizer.CheckNext('(', tkSpecialSymbol) then begin 327 Tokenizer.Expect('(', tkSpecialSymbol); 328 while not Tokenizer.CheckNext(')', tkSpecialSymbol) do begin 329 if Func.Params.Count > 0 then Tokenizer.Expect(',', tkSpecialSymbol); 330 if ParseFunctionParameter(Block, FunctionParameter) then begin 331 Func.Params.Add(FunctionParameter); 332 end else Error('Expected function parameter.'); 333 end; 334 Tokenizer.Expect(')', tkSpecialSymbol); 335 for I := 0 to Func.Params.Count - 1 do begin 336 Variable := TVariable.Create; 337 Variable.Name := TFunctionParameter(Func.Params[I]).Name; 338 Variable.TypeRef := TFunctionParameter(Func.Params[I]).TypeRef; 339 Variable.Internal := True; 340 Func.Block.Variables.Add(Variable); 341 end; 342 end; 343 if Tokenizer.CheckNext(':', tkSpecialSymbol) then begin 344 Tokenizer.Expect(':', tkSpecialSymbol); 345 Token := Tokenizer.GetNext; 346 if Token.Kind = tkIdentifier then begin 347 TypeRef := Block.GetType(Token.Text); 348 if Assigned(TypeRef) then begin 349 Func.ResultType := TypeRef; 350 Variable := TVariable.Create; 351 Variable.Name := 'Result'; 352 Variable.TypeRef := TypeRef; 353 Variable.Internal := True; 354 Func.Block.Variables.Add(Variable); 355 end else Error('Type ' + Token.Text + ' not found'); 356 end; 357 end; 358 Tokenizer.Expect(';', tkSpecialSymbol); 359 if ParseBlock(Block, NewBlock, Func.Block) then begin 360 Tokenizer.Expect(';', tkSpecialSymbol); 361 end else Error('Expected function block'); 362 end else Error('Expected function name'); 363 end; 364 end; 365 366 function TParser.ParseFunctionParameter(Block: TBlock; out Parameter: TFunctionParameter 367 ): Boolean; 368 var 369 Token: TToken; 370 TypeRef: TType; 371 begin 372 Result := True; 373 Token := Tokenizer.GetNext; 374 if Token.Kind = tkIdentifier then begin 375 Parameter := TFunctionParameter.Create; 376 Parameter.Name := Token.Text; 377 Tokenizer.Expect(':', tkSpecialSymbol); 378 Token := Tokenizer.GetNext; 379 if Token.Kind = tkIdentifier then begin 380 TypeRef := Block.GetType(Token.Text); 381 if Assigned(TypeRef) then begin 382 Parameter.TypeRef := TypeRef; 383 end else Error('Type ' + Token.Text + ' not found'); 384 end else Error('Expected parameter type'); 385 end else Error('Expected parameter name'); 386 end; 387 293 388 function TParser.ParseAssignment(Block: TBlock; out Assignment: TAssignment): Boolean; 294 389 var … … 315 410 end else begin 316 411 Result := False; 317 Error('Assignment type mismatch. ');412 Error('Assignment type mismatch. Expected ' + Variable.TypeRef.Name + ' but got ' + Expression.GetType.Name); 318 413 end; 319 414 end; … … 348 443 Expression: TExpression; 349 444 LastPos: TTokenizerPos; 445 I: Integer; 446 ExpectedType: TType; 350 447 begin 351 448 Result := False; … … 362 459 else if Token.Text = '<>' then ExpressionOperation.Operation := eoNotEqual 363 460 else Error('Unsupported operator ' + Token.Text); 461 ExpressionOperation.FunctionRef := ExpressionOperation.TypeRef.Functions.SearchByName(ExpressionOperation.GetFunctionName); 462 if not Assigned(ExpressionOperation.FunctionRef.ResultType) then 463 raise Exception.Create('Missing result type for function'); 464 ExpressionOperation.TypeRef := ExpressionOperation.FunctionRef.ResultType; 364 465 ExpressionOperation.Items.Add(Operand); 466 I := 1; 365 467 if ParseExpression(Block, Expression) then begin 366 if Expression.GetType = Operand.GetType then 468 ExpectedType := TFunctionParameter(ExpressionOperation.FunctionRef.Params[I]).TypeRef; 469 if Expression.GetType = ExpectedType then 367 470 ExpressionOperation.Items.Add(Expression) 368 else Error('Expression operands needs to be same type. ');471 else Error('Expression operands needs to be same type. Expected ' + ExpectedType.Name + ' but found ' + Expression.GetType.Name); 369 472 end else Error('Missing operand.'); 370 473 end else Operand.Free; -
branches/interpreter2/USource.pas
r211 r212 12 12 TFunctions = class; 13 13 TBeginEnd = class; 14 TBlock = class; 14 15 15 16 TDataType = (dtNone, dtString, dtBoolean, dtInteger, dtFloat, dtColor, … … 129 130 Name: string; 130 131 TypeRef: TType; 132 Internal: Boolean; 131 133 procedure GetValue(Index: Integer; out Value); override; 132 134 function GetField(Index: Integer): TField; override; … … 183 185 Params: TFunctionParameters; 184 186 ResultType: TType; 185 BeginEnd: TBeginEnd; 187 Block: TBlock; 188 ParentType: TType; 186 189 procedure GetValue(Index: Integer; out Value); override; 187 190 function GetField(Index: Integer): TField; override; … … 194 197 195 198 TFunctions = class(TSourceNodes) 199 ParentType: TType; 196 200 function SearchByName(Name: string): TFunction; 197 201 function AddNew(Name: string): TFunction; … … 253 257 public 254 258 TypeRef: TType; 259 FunctionRef: TFunction; 255 260 Operation: TExpressionOperator; 256 261 Items: TExpressions; 262 function GetFunctionName: string; 257 263 procedure GetValue(Index: Integer; out Value); override; 258 264 function GetField(Index: Integer): TField; override; … … 839 845 procedure TFunction.GetValue(Index: Integer; out Value); 840 846 begin 841 if Index = 0 then TB eginEnd(Value) := BeginEnd847 if Index = 0 then TBlock(Value) := Block 842 848 else if Index = 1 then TFunctionParameters(Value) := Params 843 849 else if Index = 2 then TType(Value) := ResultType … … 862 868 procedure TFunction.SetValue(Index: Integer; var Value); 863 869 begin 864 if Index = 0 then B eginEnd := TBeginEnd(Value)870 if Index = 0 then Block := TBlock(Value) 865 871 else if Index = 1 then Params := TFunctionParameters(Value) 866 872 else if Index = 2 then ResultType := TType(Value) … … 872 878 begin 873 879 Params := TFunctionParameters.Create; 874 B eginEnd := TBeginEnd.Create;880 Block := TBlock.Create; 875 881 end; 876 882 877 883 destructor TFunction.Destroy; 878 884 begin 879 B eginEnd.Free;885 Block.Free; 880 886 Params.Free; 881 887 inherited Destroy; … … 910 916 begin 911 917 Functions := TFunctions.Create; 918 Functions.ParentType := Self; 912 919 end; 913 920 … … 950 957 end; 951 958 959 function TExpressionOperation.GetFunctionName: string; 960 begin 961 if Operation = eoAdd then Result := '_Add' 962 else if Operation = eoSub then Result := '_Sub' 963 else if Operation = eoEqual then Result := '_Equal' 964 else if Operation = eoNotEqual then Result := '_NotEqual' 965 else raise Exception.Create('Unsupported operation type.'); 966 end; 967 952 968 function TExpressionOperation.GetFieldsCount: Integer; 953 969 begin … … 1159 1175 Result := TFunction.Create; 1160 1176 Result.Name := Name; 1177 Result.ParentType := ParentType; 1161 1178 Add(Result); 1162 1179 end; … … 1242 1259 Result := Types.SearchByName(Name); 1243 1260 if not Assigned(Result) and Assigned(ParentBlock) then 1244 Result := ParentBlock. Types.SearchByName(Name);1261 Result := ParentBlock.GetType(Name); 1245 1262 end; 1246 1263 … … 1249 1266 Result := Constants.SearchByName(Name); 1250 1267 if not Assigned(Result) and Assigned(ParentBlock) then 1251 Result := ParentBlock. Constants.SearchByName(Name);1268 Result := ParentBlock.GetConstant(Name); 1252 1269 end; 1253 1270 … … 1256 1273 Result := Variables.SearchByName(Name); 1257 1274 if not Assigned(Result) and Assigned(ParentBlock) then 1258 Result := ParentBlock. Variables.SearchByName(Name);1275 Result := ParentBlock.GetVariable(Name); 1259 1276 end; 1260 1277 … … 1263 1280 Result := Functions.SearchByName(Name); 1264 1281 if not Assigned(Result) and Assigned(ParentBlock) then 1265 Result := ParentBlock. Functions.SearchByName(Name);1282 Result := ParentBlock.GetFunction(Name); 1266 1283 end; 1267 1284 … … 1269 1286 begin 1270 1287 Constants := TConstants.Create; 1288 Constants.Parent := Self; 1271 1289 Variables := TVariables.Create; 1290 Variables.Parent := Self; 1272 1291 Functions := TFunctions.Create; 1292 Functions.Parent := Self; 1273 1293 Types := TTypes.Create; 1294 Types.Parent := Self; 1274 1295 BeginEnd := TBeginEnd.Create; 1296 BeginEnd.Parent := Self; 1275 1297 end; 1276 1298 -
branches/interpreter2/UTokenizer.pas
r207 r212 150 150 (Text = 'else') or (Text = 'while') or (Text = 'do') or (Text = 'for') or 151 151 (Text = 'to') or (Text = 'repeat') or (Text = 'until') or (Text = 'break') or 152 (Text = 'continue') ;152 (Text = 'continue') or (Text = 'function'); 153 153 end; 154 154
Note:
See TracChangeset
for help on using the changeset viewer.