Class ASyntaxRule

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type ASyntaxRule = class(ABinaryLeaf)

Description

This class represents a single syntax rule, which in its simplest form is a set of opcodes. The set can be used by a parser to determine which tokens are allowed in a given situation, which tokens are not allowed in a given situation, or the order in which tokens must be provided in a given situation.

Note that syntax rules can only grow; they cannot otherwise be modified, because it is assumed that they will be defined at compile-time as part of a language specification.

Instances of ASyntaxRule descend from ABinaryLeaf so that they can be gathered together into lists of rules, such as ASyntaxRuleset, that define the grammar for a particular parsed language.

Hierarchy

  • ASyntaxRule

Overview

Fields

Protected myComponents: TOpcodeList;

Methods

Public constructor withIdentifier(const thisKey: TSortKey; const thisList: array of TOpcode); virtual;
Public function init: boolean; override;
Public destructor destroy; override;
Public function add(const opcode: TOpcode): longint; virtual;
Public function addSeveral(const opcodeList: array of TOpcode): longint; virtual;
Public procedure push(const opcode: TOpcode); virtual;
Public procedure pushSeveral(const opcodeList: array of TOpcode); virtual;
Public function has(const opcode: TOpcode): boolean; virtual;
Public function hasAnyOf(const opcodeList: array of TOpcode): TOpcode; virtual;
Public function find(const opcode: TOpcode; afterIndex: longint = 0): longint; virtual;
Public function shallowCopyFrom(const Other: AnObject): boolean; override;
Public function selfStreamingLength: TStreamIOSize; override;
Public function writeSelfTo(const Dest: AStream): TStreamIOSize; override;
Public function readFrom(const Source: AStream): TStreamIOSize; override;
Public function census: longint; reintroduce; virtual;
Public function components: TOpcodeList; virtual;

Description

Fields

Protected myComponents: TOpcodeList;

Stores the opcodes associated with the rule

Methods

Public constructor withIdentifier(const thisKey: TSortKey; const thisList: array of TOpcode); virtual;

Construct a new rule with the specified sort key and which incorporates the specified opcodes.

The opcodes provided by thisList are used to specify the opcodes that apply to the rule.

Public function init: boolean; override;

Initializer

Public destructor destroy; override;

Free the rule and the list of opcodes associated with it.

This method is called automatically when TObject.free is called on an instance of ASyntaxRule.

Public function add(const opcode: TOpcode): longint; virtual;

Add the specified opcode to the rule.

The new opcode is placed at the end of the rule. Unlike instances of ABinaryTree, instances of ASyntaxRule allow duplicate entries.

Returns

The index of the new entry.

Public function addSeveral(const opcodeList: array of TOpcode): longint; virtual;

Add the specified opcodes to the rule.

The new opcodes are placed at the end of the rule. Unlike instances of ABinaryTree, instances of ASyntaxRule allow duplicate entries.

Returns

The total number of items added to the rule. This value will be zero (0) if System.length reports that opcodeList has a length of zero.

Public procedure push(const opcode: TOpcode); virtual;

Push the specified opcode onto the end of the rule's list of opcodes.

This method is similar in function to ASyntaxRule.add, except that it does not return the index of the new entry.

Public procedure pushSeveral(const opcodeList: array of TOpcode); virtual;

Push the specified opcodes onto the end of the rule's list of opcodes.

This method is similar in function ASyntaxRule.addSeveral, except that it does not return the total number of items added to the rule.

Public function has(const opcode: TOpcode): boolean; virtual;

Determine whether the specified opcode is a component of the rule.

This method performs a sequential search of the opcodes specified for the rule and returns True if it encounters a value that matches the specified opcode. Otherwise, it returns False.

Public function hasAnyOf(const opcodeList: array of TOpcode): TOpcode; virtual;

Determine whether one of the specified opcodes is a component of the rule.

This method performs a sequential search of the opcodes specified for the rule and returns the first opcode in opcodeList which occurs as part of the rule. If no match is found for any of the opcodes in opcodeList, this method returns TOpcode(0).

Public function find(const opcode: TOpcode; afterIndex: longint = 0): longint; virtual;

Find the first occurrence of the specified opcode in the rule, optionally beginning the search after the specified index.

This method performs a sequential search of the components of the rule and returns the index of the first occurrence of opcode that it finds. The search begins at index zero (0) unless afterIndex is specified. If afterIndex specifies a value that is greater than the value of ASyntaxRule.census, then this routine will do nothing and return -1.

Returns

The index of the rule component that matches opcode, if found; -1 otherwise.

Public function shallowCopyFrom(const Other: AnObject): boolean; override;

Construct a shallow copy of the other object.

This method extends the behavior inherited from AStringLeaf.shallowCopyFrom: it calls that routine, then checks to see whether Other is an instance of ASyntaxRule. If so, it copies the values in ASyntaxRule.components from Other to Self.

The behavior of this routine allows a full copy of Other to be added to Self, since no components of Self are deleted by this routine.

Note that this method does NOT copy any sibling or child nodes and so cannot be used to create a full copy of any descendant of ANode. Likewise, it does NOT copy the left or right subtrees and so cannot be used to create a full copy of any descendant of ABinaryLeaf. The copy will NOT be automatically placed in the binary tree to which Other belongs, if any, but the caller is free to do so, so long as the node's sort key does not match one that already exists in the tree.

Public function selfStreamingLength: TStreamIOSize; override;

Calculate the number of bytes required to stream the rule, and just the rule.

This method builds upon the behavior inherited from AStringLeaf.selfStreamingLength: it calls the inherited routine, then adds the number of bytes required to store Self.census and the opcodes themselves.

Public function writeSelfTo(const Dest: AStream): TStreamIOSize; override;

Write the rule, and just the rule, to the specified stream.

This method builds upon the behavior inherited from AStringLeaf.writeSelfTo: it first calls the inherited routine, then writes the value of Self.census to Dest followed by the opcodes belonging to the rule.

Returns

The total number of bytes written to Dest.

Public function readFrom(const Source: AStream): TStreamIOSize; override;

Read the rule from the specified stream.

This method builds upon the behavior inherited from AStringLeaf.readFrom: it first calls the inherited routine, then reads the number of opcodes to retrieve from the stream and the opcodes themselves.

Returns

The total number of bytes read from Source.

Public function census: longint; reintroduce; virtual;

Calculate the total number of components in the rule.

This method simply returns the value of System.length when applied to ASyntaxRule.components.

Public function components: TOpcodeList; virtual;

Return a reference to the list of opcodes that make up the rule.


Generated by PasDoc 0.13.0 on 2015-06-25 11:12:03