Files
bds.mr.dpg/src.lib/dpglib.ActionElem.pas
T
2026-01-03 18:33:48 +01:00

125 lines
4.4 KiB
ObjectPascal

unit dpglib.ActionElem;
interface
uses
dpgrtl.types,
dpglib.types,
dpglib.AlternativeElem;
type
// =========================================================================
// Class TActionElem declaration
// =========================================================================
TActionElem = class( TAlternativeElem,
IActionElem,
IAlternativeElem,
IGrammarElem)
protected
// ------------------------------------------------------------
// Members
// ------------------------------------------------------------
fActionText : AnsiString;
fIsSemPred : boolean;
public
// ------------------------------------------------------------
// Constructor/destructor
// ------------------------------------------------------------
constructor Create( pGrammar: IGrammar; pToken: IToken);
// ------------------------------------------------------------
// IGrammarElem methods
// ------------------------------------------------------------
procedure Generate;
function Look( pK: integer): ILookahead;
function AsString : AnsiString;
// ------------------------------------------------------------
// IsgpAlternativeElem methods
// ------------------------------------------------------------
// ------------------------------------------------------------
// IActionElem methods
// ------------------------------------------------------------
function GetActionText : AnsiString;
function GetSemPred : boolean;
procedure SetSempred( pSemPred: boolean);
end;
implementation
// ****************************************************************************
// Constructor/destructor
// ****************************************************************************
// ============================================================================
// Constructor
// ============================================================================
constructor TActionElem.Create(pGrammar: IGrammar; pToken: IToken);
begin
inherited Create( pGrammar);
fActionText := pToken.TokenText;
fIsSemPred := false;
end;
// ****************************************************************************
// IActionElem implementation
// ****************************************************************************
// ============================================================================
// GetActionText
// ============================================================================
function TActionElem.GetActionText: AnsiString;
begin
result := fActionText;
end;
// ============================================================================
// GetSemPred
// ============================================================================
function TActionElem.GetSemPred: boolean;
begin
result := fIsSemPred;
end;
// ============================================================================
// SetSemPred
// ============================================================================
procedure TActionElem.SetSempred(pSemPred: boolean);
begin
fIsSemPred := pSemPred;
end;
// ****************************************************************************
// IGrammarElem implementation
// ****************************************************************************
// ============================================================================
// Generate
// ============================================================================
procedure TActionElem.Generate;
begin
fGrammar.Generator.gen( self);
end;
// ============================================================================
// Look
// ============================================================================
function TActionElem.Look(pK: integer): ILookahead;
begin
result := fGrammar.LLkAnalyzer.Look( pK, self);
end;
// ============================================================================
// AsString
// ============================================================================
function TActionElem.AsString: AnsiString;
begin
result := ' {' + fActionText;
if fIsSemPred then
result := result + '}?';
end;
end.