Initial check in lib
This commit is contained in:
@@ -0,0 +1,161 @@
|
||||
// ============================================================================
|
||||
// This file is generated by the Delphi Parser Generator.
|
||||
// ----------------------------------------------------------------------------
|
||||
// DPG version: 2.0.1.0r
|
||||
// Grammar: dpglib.TokenParser.g
|
||||
// ============================================================================
|
||||
unit dpglib.TokenParser;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes,
|
||||
SysUtils,
|
||||
dpglib.StringSymbol,
|
||||
dpglib.TokenParserTokens,
|
||||
dpglib.TokenSymbol,
|
||||
dpglib.Types,
|
||||
dpgrtl.llkparser,
|
||||
dpgrtl.types;
|
||||
|
||||
type
|
||||
// =========================================================================
|
||||
// Class TTokenParser declaration
|
||||
// =========================================================================
|
||||
TTokenParser = class( TLLkParser)
|
||||
|
||||
public // Public grammar rules
|
||||
procedure tokenFile ( tm:ITokenManager);
|
||||
procedure tokenLine ( tm:ITokenManager);
|
||||
|
||||
end;
|
||||
|
||||
implementation
|
||||
uses
|
||||
dpgrtl.exception,
|
||||
dpgrtl.token;
|
||||
|
||||
|
||||
// ============================================================================
|
||||
// tokenFile
|
||||
// ============================================================================
|
||||
procedure TTokenParser.tokenFile( tm:ITokenManager);
|
||||
var
|
||||
name: IToken;
|
||||
|
||||
begin
|
||||
|
||||
name := LT(1);
|
||||
match(TT_ID);
|
||||
|
||||
while(true) do
|
||||
begin
|
||||
if (( LA(1) in [TT_STRING,TT_ID])) then
|
||||
begin
|
||||
tokenLine(tm);
|
||||
end
|
||||
|
||||
else
|
||||
break;
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
// ============================================================================
|
||||
// tokenLine
|
||||
// ============================================================================
|
||||
procedure TTokenParser.tokenLine( tm:ITokenManager);
|
||||
var
|
||||
i: IToken;
|
||||
id: IToken;
|
||||
id2: IToken;
|
||||
lab: IToken;
|
||||
para: IToken;
|
||||
s1: IToken;
|
||||
s2: IToken;
|
||||
t : IToken;
|
||||
s : IToken;
|
||||
v : integer;
|
||||
sl: IStringSymbol;
|
||||
ts: ITokenSymbol;
|
||||
x : AnsiString;
|
||||
|
||||
begin
|
||||
|
||||
t := nil;
|
||||
s := nil;
|
||||
if (( LA(1) in [TT_STRING])) then
|
||||
begin
|
||||
s1 := LT(1);
|
||||
match(TT_STRING);
|
||||
s := s1;
|
||||
end
|
||||
|
||||
else if (( LA(1) in [TT_ID]) and (LA(2) in [TT_ASSIGN]) and (LA(3) in [TT_STRING])) then
|
||||
begin
|
||||
lab := LT(1);
|
||||
match(TT_ID);
|
||||
t := lab;
|
||||
match(TT_ASSIGN);
|
||||
s2 := LT(1);
|
||||
match(TT_STRING);
|
||||
s := s2;
|
||||
end
|
||||
|
||||
else if (( LA(1) in [TT_ID]) and (LA(2) in [TT_LPAREN])) then
|
||||
begin
|
||||
id := LT(1);
|
||||
match(TT_ID);
|
||||
t := id;
|
||||
match(TT_LPAREN);
|
||||
para := LT(1);
|
||||
match(TT_STRING);
|
||||
match(TT_RPAREN);
|
||||
end
|
||||
|
||||
else if (( LA(1) in [TT_ID]) and (LA(2) in [TT_ASSIGN]) and (LA(3) in [TT_INT])) then
|
||||
begin
|
||||
id2 := LT(1);
|
||||
match(TT_ID);
|
||||
t := id2;
|
||||
end
|
||||
|
||||
else
|
||||
Raise EMismatchedToken.Create( LT(1), [TT_STRING,TT_ID], InputState.FileName);
|
||||
match(TT_ASSIGN);
|
||||
i := LT(1);
|
||||
match(TT_INT);
|
||||
v := StrToIntDef( i.TokenText, -1);
|
||||
|
||||
if s <> nil then
|
||||
begin
|
||||
ts := TStringSymbol.Create( s.TokenText);
|
||||
ts.TokenType := v;
|
||||
tm.Define(ts);
|
||||
|
||||
if t <> nil then
|
||||
begin
|
||||
ts := tm.TokenSymbol[s.TokenText];
|
||||
ts.QueryInterface( IStringSymbol, sl);
|
||||
sl.Lbl := t.TokenText;
|
||||
|
||||
tm.MapToTokenSymbol( t.TokenText, sl);
|
||||
end;
|
||||
end
|
||||
|
||||
else if t <> nil then
|
||||
begin
|
||||
x := Copy( t.TokenText, 4, Length( t.TokenText)-3);
|
||||
ts := TTokenSymbol.Create( x);
|
||||
ts.TokenType := v;
|
||||
tm.Define( ts);
|
||||
|
||||
if para <> nil then
|
||||
begin
|
||||
ts := tm.TokenSymbol[ t.TokenText];
|
||||
ts.Paraphrase := para.TokenText;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
Reference in New Issue
Block a user