-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_grammar.dws
More file actions
86 lines (76 loc) · 1.46 KB
/
test_grammar.dws
File metadata and controls
86 lines (76 loc) · 1.46 KB
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
// Test file for DWScript grammar
program TestGrammar;
uses
SysUtils, Math;
type
TMyClass = class
private
FValue: Integer;
public
constructor Create(AValue: Integer);
property Value: Integer read FValue write FValue;
procedure DoSomething;
function Calculate(x, y: Float): Float;
end;
// Generic type
TList<T> = class
private
FItems: array of T;
public
procedure Add(const Item: T);
function Get(Index: Integer): T;
end;
// Attribute example
[TestAttribute('Sample')]
TAttributeClass = class
end;
var
MyObject: TMyClass;
Numbers: TList<Integer>;
Message: String;
// Constructor implementation
constructor TMyClass.Create(AValue: Integer);
begin
FValue := AValue;
end;
procedure TMyClass.DoSomething;
var
I: Integer;
Lambda: procedure(x: Integer);
begin
// Anonymous method example
Lambda := procedure(x: Integer)
begin
WriteLn('Value: ' + IntToStr(x));
end;
for I := 1 to 10 do
begin
if I mod 2 = 0 then
Lambda(I)
else
Continue;
end;
end;
function TMyClass.Calculate(x, y: Float): Float;
begin
try
Result := Sqrt(x * x + y * y);
except
on E: Exception do
begin
WriteLn('Error: ' + E.Message);
Result := 0.0;
end;
end;
end;
// Main program
begin
MyObject := TMyClass.Create(42);
try
MyObject.DoSomething;
Message := 'Result: ' + FloatToStr(MyObject.Calculate(3.0, 4.0));
WriteLn(Message);
finally
MyObject.Free;
end;
end.