Class TProduction

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type TProduction = class(TObject)

Description

This is just a double-linked list of TSymbol instances. It's reference counted, so it can be used by more than one TNonTerminal.

Hierarchy

Overview

Methods

Public constructor Create;
Public destructor Destroy; override;
Public function FirstSymbol: TSymbol;
Public function LastSymbol: TSymbol;
Public function Empty: boolean;
Public procedure Collect( var FirstIndex: Cardinal; CollectValues: boolean; ProductionsList: TProductionsList; out UsedTerminals: TSetOfChars);
Public function CollectValue: string;
Public procedure DoCollectGrammarSize( var GrammarSize: Cardinal; var FirstIndexProductions: Cardinal; var UsedTerminals: TSetOfChars);
Public function GraphLabel(LongNonTerminalNames: boolean): string;
Public procedure GraphSaveToStream(Stream: TStream; LongNonTerminalNames: boolean);
Public procedure GraphSaveToFile(const FileName: string; LongNonTerminalNames: boolean);
Public procedure SaveToStream(Stream: TStream);
Public constructor CreateFromStream(Stream: TStream);
Public procedure GrammarSizes(var GrammarSize, SymbolsCount, NonTerminalsCount, TerminalsCount, BitsPerSymbol: Cardinal);
Public function Name: string;
Public procedure ReleaseSymbols;
Public procedure SimpleCalculateCollectedValue;

Properties

Public property UsedCount: Cardinal read FUsedCount;
Public property CollectedIndex: Integer read FCollectedIndex;
Public property CollectedValue: string read FCollectedValue write FCollectedValue;

Description

Methods

Public constructor Create;
 
Public destructor Destroy; override;
 
Public function FirstSymbol: TSymbol;

Note that these return special Guard symbol when production is empty.

Public function LastSymbol: TSymbol;
 
Public function Empty: boolean;
 
Public procedure Collect( var FirstIndex: Cardinal; CollectValues: boolean; ProductionsList: TProductionsList; out UsedTerminals: TSetOfChars);

This is used to recursively calculate various properties of this production, and productions referenced by used non-terminals.

Sets CollectedIndex of this production and then all referenced productions, recursively. Starts indexing using FirstIndex, and always after assigning some CollectedIndex increments FirstIndex, so FirstIndex should always indicate next free index.

Each time when index is assigned it adds the item to ProductionsList, so ProductionsList contains all the indexed items, in the indexing order. Pass ProductionsList = nil if you don't need this.

If CollectValues then also sets CollectedValue of this production and all children. CollectValues = True may eat a lot of memory for large grammars, so be careful when you set this to True.

UsedTerminals is set to all terminals used.

Public function CollectValue: string;

This is like simpler version of Collect, when all you want is to set CollectedValue. This calculates CollectedValue of this production and all references productions, and then returns CollectedValue (that's comfortable sometimes).

Public procedure DoCollectGrammarSize( var GrammarSize: Cardinal; var FirstIndexProductions: Cardinal; var UsedTerminals: TSetOfChars);
 
Public function GraphLabel(LongNonTerminalNames: boolean): string;
 
Public procedure GraphSaveToStream(Stream: TStream; LongNonTerminalNames: boolean);

Saves grammar starting from this production to a text stream, readable by graphviz. This uses DeleteIndexes and AddIndexes.

Public procedure GraphSaveToFile(const FileName: string; LongNonTerminalNames: boolean);

Like GraphSaveToStream but takes FileName as a parameter.

Public procedure SaveToStream(Stream: TStream);

Saves grammar starting from this production to a binary stream, trying to use as little bits as possible. In other words: do the compression.

Public constructor CreateFromStream(Stream: TStream);

Loads grammar from a binary stream saved by SaveToStream. In other words: do 1st part the decompression (2nd part is to actually calculate the result, this is easily done by the Collect method).

Public procedure GrammarSizes(var GrammarSize, SymbolsCount, NonTerminalsCount, TerminalsCount, BitsPerSymbol: Cardinal);

Calculate various sizes and counts of this grammar.

Public function Name: string;
 
Public procedure ReleaseSymbols;

Simply set this production to empty, forgetting about all symbols between FirstSymbol and LastSymbol. You're responsible to save somewhere FirstSymbol and/or LastSymbol references before calling this, to not leak memory.

Public procedure SimpleCalculateCollectedValue;

Calculates CollectedValue by simply iteraring over items of this production, and assuming that all children productions already have correct CollectedValue.

Properties

Public property UsedCount: Cardinal read FUsedCount;
 
Public property CollectedIndex: Integer read FCollectedIndex;
 
Public property CollectedValue: string read FCollectedValue write FCollectedValue;

This is usually calculated by various CollectXxx routines and read-only from outside.

But you can't modify it — at your own responsibility. This may be useful if you simply extend this production by new symbol — then simple update of CollectedValue may be faster than any ColllectXxx call.


Generated by PasDoc 0.10.0 on 2006-07-12 06:44:38