-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathGS.Language.Parser.Pascal.pas
More file actions
90 lines (71 loc) · 1.74 KB
/
GS.Language.Parser.Pascal.pas
File metadata and controls
90 lines (71 loc) · 1.74 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
87
88
89
unit GS.Language.Parser.Pascal;
{$IFDEF FPC}
{$mode delphi}{$H+}
{$ENDIF FPC}
interface
uses
Classes, SysUtils, ContNrs,
GS.Language.WordTokenizer,
GS.Language.Tokenizer.Pascal,
GS.Language.Syntax.Pascal,
GS.Language.Semantic.Pascal,
GS.Language.Compiler;
type
//Group : Tokenizer, syntax checker, and semantic checker.
TPascalParser = class
private
function GetLogs: TStringList;
protected
FTokenizer : TPascalTokenizer;
FSyntaxCheck : TPascalSyntaxCheck;
FSemanticProcessor : TPascalSemanticProcessor;
public
constructor Create; virtual;
destructor Destroy; override;
function Parse(const code : string) : boolean;
property logs : TStringList read GetLogs;
end;
implementation
{ TPascalParser }
constructor TPascalParser.Create;
begin
inherited;
FTokenizer := TPascalTokenizer.Create;
FSyntaxCheck := TPascalSyntaxCheck.Create(FTokenizer);
FSemanticProcessor := TPascalSemanticProcessor.Create(FSyntaxCheck.Root);
FSyntaxCheck.Root.SemanticProcessor := FSemanticProcessor;
end;
destructor TPascalParser.Destroy;
begin
FreeAndNil(FTokenizer);
FreeAndNil(FSyntaxCheck);
FreeAndNil(FSemanticProcessor);
inherited;
end;
function TPascalParser.GetLogs: TStringList;
begin
result := FSyntaxCheck.Log;
end;
function TPascalParser.Parse(const code: string): boolean;
begin
result := true;
FTokenizer.Tokenize(code);
if FSyntaxCheck.Check then
begin
if FSemanticProcessor.Process then
begin
FSemanticProcessor.log('Semantic check success.');
end
else
begin
result := false;
FSyntaxCheck.root.log('Semantic check unsuccess.');
end;
end
else
begin
result := false;
FSyntaxCheck.root.log('Syntax check unsuccess.');
end;
end;
end.