131 lines
4.7 KiB
ObjectPascal
131 lines
4.7 KiB
ObjectPascal
// ----------------------------------------------------------------------------
|
|
// All alternative blocks are "terminated" by BlockEndElements unless theye are
|
|
// rule blocks (in which case they use RuleEndElement).
|
|
// ----------------------------------------------------------------------------
|
|
unit dpglib.BlockEndElem;
|
|
|
|
interface
|
|
uses
|
|
dpglib.types,
|
|
dpglib.AlternativeElem;
|
|
|
|
type
|
|
// =========================================================================
|
|
// Class TBlockEndElem declaration
|
|
// =========================================================================
|
|
TBlockEndElem = class( TAlternativeElem,
|
|
IBlockEndElem,
|
|
IAlternativeElem,
|
|
IGrammarElem)
|
|
|
|
// ---------------------------------------------------------------
|
|
// Members
|
|
// ---------------------------------------------------------------
|
|
protected
|
|
fLock : array of boolean;
|
|
fBlock : IAlternativeBlock;
|
|
|
|
// ---------------------------------------------------------------
|
|
// Constructor/destructor
|
|
// ---------------------------------------------------------------
|
|
public
|
|
constructor Create( pGrammar: IGrammar);
|
|
destructor Destroy; override;
|
|
|
|
// ---------------------------------------------------------------
|
|
// IGrammarElem overrides
|
|
// ---------------------------------------------------------------
|
|
public
|
|
function Look( pK: integer): ILookahead;
|
|
function AsString: AnsiString;
|
|
|
|
// ---------------------------------------------------------------
|
|
// IBlockEndElem methods
|
|
// ---------------------------------------------------------------
|
|
protected
|
|
function GetBlock: IAlternativeBlock;
|
|
function GetLock( i: integer): boolean;
|
|
|
|
procedure SetBlock( pBlock: IAlternativeBlock);
|
|
procedure SetLock( i: integer; pLock: boolean);
|
|
end;
|
|
|
|
|
|
implementation
|
|
// ****************************************************************************
|
|
// Constructor/destructor
|
|
// ****************************************************************************
|
|
// ============================================================================
|
|
// Constructor
|
|
// ============================================================================
|
|
constructor TBlockEndElem.Create(pGrammar: IGrammar);
|
|
begin
|
|
inherited Create( pGrammar);
|
|
SetLength( fLock, pGrammar.MaxK + 1);
|
|
end;
|
|
|
|
// ============================================================================
|
|
// Destructor
|
|
// ============================================================================
|
|
destructor TBlockEndElem.Destroy;
|
|
begin
|
|
fLock := nil;
|
|
inherited;
|
|
end;
|
|
|
|
// ****************************************************************************
|
|
// IGrammarElem overrides
|
|
// ****************************************************************************
|
|
// ============================================================================
|
|
// Look
|
|
// ============================================================================
|
|
function TBlockEndElem.Look(pK: integer): ILookahead;
|
|
begin
|
|
result := fGrammar.LLkAnalyzer.Look( pK, self);
|
|
end;
|
|
|
|
// ============================================================================
|
|
// AsString
|
|
// ============================================================================
|
|
function TBlockEndElem.AsString: AnsiString;
|
|
begin
|
|
result := ' [BlkEnd]';
|
|
end;
|
|
|
|
// ****************************************************************************
|
|
// IBlockEndElem overrides
|
|
// ****************************************************************************
|
|
// ============================================================================
|
|
// GetBlock
|
|
// ============================================================================
|
|
function TBlockEndElem.GetBlock: IAlternativeBlock;
|
|
begin
|
|
result := fBlock;
|
|
end;
|
|
|
|
// ============================================================================
|
|
// GetLock
|
|
// ============================================================================
|
|
function TBlockEndElem.GetLock(i: integer): boolean;
|
|
begin
|
|
Result := fLock[i];
|
|
end;
|
|
|
|
// ============================================================================
|
|
// SetBlock
|
|
// ============================================================================
|
|
procedure TBlockEndElem.SetBlock(pBlock: IAlternativeBlock);
|
|
begin
|
|
fBlock := pBlock;
|
|
end;
|
|
|
|
// ============================================================================
|
|
// SetLock
|
|
// ============================================================================
|
|
procedure TBlockEndElem.SetLock(i: integer; pLock: boolean);
|
|
begin
|
|
fLock[i] := pLock;
|
|
end;
|
|
|
|
end.
|