-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest2.pas
54 lines (45 loc) · 1.28 KB
/
Test2.pas
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
Unit Test2;
{$I define.inc}
Interface
Procedure Test;
Implementation
Uses {$IFNDEF FPC}
{$IFDEF CLASSIC}
TypInfo
{$ELSE}
System.Rtti
{$ENDIF}
, {$ENDIF}
{$IFDEF USE_STRINGS}strings,{$ENDIF}SysUtils, Lexer, PARSER, GRMRVIWR, GrmRUnit, ASTNode, TestUtil,
GLEXER, GPARSER, STREAM;
Procedure Test;
Var
mSource: PStream;
mGrammarLexer: PLexer;
mParser: PGrammarParser;
mViewer: PAstViewer;
Begin
mSource := PropmtForFile('Grammar File Path? (Default = t.xg)', 't.xg');
mGrammarLexer := PLexer(GetGrammarLexer(mSource));
TGrammarParser_Create(mParser, mGrammarLexer, GrammarRule);
If TGrammarParser_Parse(mParser) Then
WriteLn('ACCEPTED')
Else
Begin
WriteLn(Format('ERROR: Parser Message: %s', [mParser^.Parent.Error]));
WriteLn(Format('ERROR: Current Token at Pos = %d, Value = [%s], Message: %s',
[mGrammarLexer^.CurrentToken.StartPos, mGrammarLexer^.CurrentToken.Value,
mGrammarLexer^.CurrentToken.Error]));
End;
TAstViewer_Create(mViewer);
mParser^.Ast^.VMT^.Accept(mParser^.Ast, mViewer^.As_IAstVisitor);
TAstViewer_Destroy(mViewer);
Dispose(mViewer);
Writeln;
TGrammarParser_Destroy(PParser(mParser));
Dispose(mParser);
mGrammarLexer^.VMT^.Destory(mGrammarLexer);
Dispose(mGrammarLexer);
Dispose(mSource);
End;
End.