145 lines
4.9 KiB
ObjectPascal
145 lines
4.9 KiB
ObjectPascal
unit dpglib.RuleEndElem;
|
|
|
|
interface
|
|
uses
|
|
dpgrtl.types,
|
|
dpglib.types,
|
|
dpglib.Lookahead,
|
|
dpglib.BlockEndElem;
|
|
|
|
type
|
|
// =========================================================================
|
|
// Class TRuleEndElem declaration
|
|
// =========================================================================
|
|
TRuleEndElem = class( TBlockEndElem,
|
|
IRuleEndElem,
|
|
IBlockEndElem,
|
|
IAlternativeElem,
|
|
IGrammarElem)
|
|
|
|
// ---------------------------------------------------------------
|
|
// Members
|
|
// ---------------------------------------------------------------
|
|
protected
|
|
fCache : array of ILookahead;
|
|
fNoFOLLOW : boolean;
|
|
|
|
// ---------------------------------------------------------------
|
|
// Constructor/destructor
|
|
// ---------------------------------------------------------------
|
|
public
|
|
constructor Create( pGrammar: IGrammar);
|
|
destructor Destroy; override;
|
|
|
|
// ---------------------------------------------------------------
|
|
// Constructor/destructor
|
|
// ---------------------------------------------------------------
|
|
public
|
|
procedure Generate;
|
|
function Look( pK: integer): ILookahead;
|
|
function AsString : AnsiString;
|
|
|
|
// ---------------------------------------------------------------
|
|
// IRuleEndElem methods
|
|
// ---------------------------------------------------------------
|
|
protected
|
|
function GetnoFOLLOW: boolean;
|
|
function GetCache(i: integer): ILookahead;
|
|
|
|
procedure SetnoFOLLOW( pnoFOLLOW: boolean);
|
|
procedure SetCache(i:integer; pCache : ILookahead);
|
|
end;
|
|
|
|
implementation
|
|
|
|
// ****************************************************************************
|
|
// Constructor/destructor
|
|
// ****************************************************************************
|
|
// ============================================================================
|
|
// Constructor
|
|
// ============================================================================
|
|
constructor TRuleEndElem.Create(pGrammar: IGrammar);
|
|
begin
|
|
inherited Create( pGrammar);
|
|
SetLength( fCache, fGrammar.MaxK +1);
|
|
end;
|
|
|
|
// ============================================================================
|
|
// Destructor
|
|
// ============================================================================
|
|
destructor TRuleEndElem.Destroy;
|
|
var
|
|
i: integer;
|
|
|
|
begin
|
|
for i:=Low(fCache) to High(fCache) do
|
|
fCache[i] := nil;
|
|
|
|
fCache := nil;
|
|
inherited;
|
|
end;
|
|
|
|
// ****************************************************************************
|
|
// IGrammarElem overrides
|
|
// ****************************************************************************
|
|
// ============================================================================
|
|
// Generate
|
|
// ============================================================================
|
|
procedure TRuleEndElem.Generate;
|
|
begin
|
|
fGrammar.Generator.Gen(self);
|
|
end;
|
|
|
|
// ============================================================================
|
|
// Look
|
|
// ============================================================================
|
|
function TRuleEndElem.Look(pK: integer): ILookahead;
|
|
begin
|
|
result := fGrammar.LLkAnalyzer.Look( pK, self);
|
|
end;
|
|
|
|
// ============================================================================
|
|
// AsString
|
|
// ============================================================================
|
|
function TRuleEndElem.AsString: AnsiString;
|
|
begin
|
|
result := ' [RuleEnd]';
|
|
end;
|
|
|
|
// ****************************************************************************
|
|
// IRuleEndElem implementation
|
|
// ****************************************************************************
|
|
// ============================================================================
|
|
// GetnoFOLLOW
|
|
// ============================================================================
|
|
function TRuleEndElem.GetnoFOLLOW: boolean;
|
|
begin
|
|
result := fNoFOLLOW;
|
|
end;
|
|
|
|
// ============================================================================
|
|
// GetCache
|
|
// ============================================================================
|
|
function TRuleEndElem.GetCache(i: integer): ILookahead;
|
|
begin
|
|
result := fCache[i];
|
|
end;
|
|
|
|
// ============================================================================
|
|
// SetnoFOLLOW
|
|
// ============================================================================
|
|
procedure TRuleEndElem.SetnoFOLLOW(pnoFOLLOW: boolean);
|
|
begin
|
|
fNoFOLLOW := pnoFOLLOW;
|
|
end;
|
|
|
|
// ============================================================================
|
|
// SetCache
|
|
// ============================================================================
|
|
procedure TRuleEndElem.SetCache(i: integer; pCache: ILookahead);
|
|
begin
|
|
fCache[i] := pCache;
|
|
end;
|
|
|
|
end.
|