Class ANumericConstantToken

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type ANumericConstantToken = class(AnIdentifierToken)

Description

This class represents a numeric constant parsed from the source. Numeric constants are normally considered to be global symbols, which is why this class descends from AnIdentifierToken.

Note that this class does not override the behavior it inherits from AnIdentifierToken.writeSelfTo. The value of the token is NOT written to an intermediate code stream; this is done when the symbol table that contains the constant is written and so need not be done again.

Hierarchy

Overview

Fields

Protected myValue: Variant;

Methods

Public function init: boolean; override;
Public function isInteger: boolean; virtual;
Public function shallowCopyFrom(const Other: AnObject): boolean; override;
Public function readFrom(const Source: AStream): TStreamIOSize; override;
Public function value: Variant; virtual;

Description

Fields

Protected myValue: Variant;

Stores the computed value of the constant, as parsed from the source

Methods

Public function init: boolean; override;

Initializer

Public function isInteger: boolean; virtual;

Determine whether the constant represents an integer or a floating-point value.

This method simply calls Variants.VarIsFloat on Self.value.

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

Construct a shallow copy of the other object.

This method extends the behavior inherited from AnIdentifierToken.shallowCopyFrom: it calls that method, then checks to see whether Other is an instance of ANumericConstantToken. If so, it copies the value of ANumericConstantToken.value from Other to Self, overwriting the value 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 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 a numeric constant. It then checks to see whether the text accumulated represents a valid number; if not, it changes its opcode to TOKCAT_ERROR.

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 value: Variant; virtual;

Retrieve the computed value of the numeric constant, as parsed from the source.

The value returned by this routine represents the computed value of the token. The literal text of the token can be retrieved by calling ANumericConstantToken.text on the token.


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