Class AnIdentifierToken

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type AnIdentifierToken = class(ATokenFromSource)

Description

This token represents an identifier read from the source. Identifiers have the potential of being reserved words or operators recognized by the language; otherwise, they are treated as symbols for entry into a symbol table.

Identifiers are distinct from special tokens in that they generally must contain one or more alphanumeric characters in them, whereas a special token may be composed entirely of symbol characters.

Hierarchy

Overview

Fields

Protected MySymbol: ASymbol;

Methods

Public function init: boolean; override;
Public function shallowCopyFrom(const Other: AnObject): boolean; override;
Public function writeSelfTo(const Dest: AStream): TStreamIOSize; override;
Public function readFrom(const Source: AStream): TStreamIOSize; override;
Public function Symbol: ASymbol; virtual;
Public function SetSymbol(const NewSymbol: ASymbol): ASymbol; virtual;

Description

Fields

Protected MySymbol: ASymbol;

Refers to the symbol represented by the token

Methods

Public function init: boolean; override;

Initializer

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

Construct a shallow copy of the other object.

This method extends the behavior inherited from ATokenFromSource.shallowCopyFrom: it calls that method, then checks to see whether Other is an instance of AnIdentifierToken. If so, it copies the value of AnIdentifierToken.Symbol from Other to Self, overwriting the values in Self.

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. The copy will NOT be automatically placed in the list to which Other belongs, if any, but the caller is free to do so.

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

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

This method builds on the behavior inherited from ATokenFromSource; it calls the inherited routine and then, if applicable, writes the scope and index of AnIdentifierToken.Symbol to Dest.

This method is written with the assumption that Dest represents an intermediate code stream.

Returns

The total number of bytes written to Dest.

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

Read the token from the given source stream.

This method reads characters from Source until one is encountered that is not allowed to be in an identifier. It then checks to see whether the text accumulated represents a reserved word or operator recognized by the language; if so, it updates the value of its opcode. Otherwise, it is assumed that the token represents a symbol of some kind; either a new one that must be entered into a symbol table, or an existing one that has already been defined elsewhere in the source.

This method is written with the assumption that Source represents an instance of ATextInputStream. To read symbolic tokens from an intermediate code stream, an instance of ASymbolicToken should be used instead.

Returns

The total number of bytes read from Source.

Public function Symbol: ASymbol; virtual;

Retrieve a reference to the symbol represented by the token.

This reference should NOT be freed by the caller.

Public function SetSymbol(const NewSymbol: ASymbol): ASymbol; virtual;

Set the symbol represented by the token.

Returns

A reference to the previous symbol represented by the token. This reference should NOT be freed by the caller.


Generated by PasDoc 0.13.0 on 2015-01-10 17:13:18