Initial check in lib
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
unit dpglib.TokenParser;
|
||||
|
||||
uses
|
||||
{
|
||||
dpglib.Types;
|
||||
dpglib.StringSymbol;
|
||||
dpglib.TokenSymbol;
|
||||
}
|
||||
|
||||
parser TTokenParser;
|
||||
options
|
||||
{
|
||||
importVocab = dpglib.TokenLexer;
|
||||
k = 3;
|
||||
}
|
||||
|
||||
tokenFile [tm:ITokenManager]
|
||||
:
|
||||
name: ID
|
||||
(tokenLine[tm])*
|
||||
;
|
||||
|
||||
tokenLine [tm:ITokenManager]
|
||||
local
|
||||
{
|
||||
t : IToken;
|
||||
s : IToken;
|
||||
v : integer;
|
||||
sl: IStringSymbol;
|
||||
ts: ITokenSymbol;
|
||||
x : AnsiString;
|
||||
}
|
||||
: {
|
||||
t := nil;
|
||||
s := nil;
|
||||
}
|
||||
|
||||
( s1: STRING { s := s1; }
|
||||
|
||||
| lab: ID { t := lab; }
|
||||
ASSIGN
|
||||
s2: STRING { s := s2; }
|
||||
|
||||
| id: ID { t := id; }
|
||||
LPAREN
|
||||
para: STRING
|
||||
RPAREN
|
||||
|
||||
| id2: ID { t := id2; }
|
||||
)
|
||||
ASSIGN
|
||||
i: 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;
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user