Class ALinearCCompoundExpression

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type ALinearCCompoundExpression = class(ALinearCExpression)

Description

This class represents a compound expression in LinearC, which can be made up of one or more subexpressions.

Hierarchy

Overview

Fields

Protected myOperation: TOpcode;

Methods

Public function parse: int64; override;
Public function parseSubexpression: int64; virtual;
Public function performOperation: int64; virtual;
Public function performArithmeticOperation: boolean; virtual;
Public function performBitwiseOperation: boolean; virtual;
Public function performEqualityTestOperation: boolean; virtual;
Public function PreviousExpression: ALinearCExpression; virtual;
Public function CurrentExpression: ALinearCExpression; virtual;
Public function operation: TOpcode;

Description

Fields

Protected myOperation: TOpcode;

Refers to the operator encountered, if any

Methods

Public function parse: int64; override;

Parse the expression.

This method assembles the values represented by each subexpression within its scope and, for each pair of expressions, performs an operation on them. The resulting value is stored as the compound expression's value.

The subexpressions are parsed by constructing an instance of ALinearCExpression and calling its parse method.

This method is not typically called directly; instead, it is called from one of the parseUntil() methods, such as ALinearCCompoundExpression.parseUntilToken. This is because the class represents a collection of expressions which is made up of one or more individual expressions.

Public function parseSubexpression: int64; virtual;

Parse a subexpression.

This method is called automatically by ALinearCCompoundExpression.parse. It checks to ensure that the current token represents a valid expression beginning, then creates an instance of ALinearCExpression to parse the expression.

Public function performOperation: int64; virtual;

Perform the operation indicated by the ALinearCCompoundExpression.operation. This method is called by ALinearCCompoundExpression.parse after two subexpressions, separated by an operator, have been parsed.

Depending on the value of Self.operation, this method will call Self.performArithmeticOperation, Self.performBitwiseOperation, or Self.performEqualityTestOperation. If the method called returns False, then this method flags a syntax error.

Returns

The total number of errors that occurred while attempting to perform the operation. A value of zero (0) indicates success.

Public function performArithmeticOperation: boolean; virtual;

Perform an arithmetic operation that involves Self.value and the value of Self.CurrentElement.

The type of value stored in Self.value determines the type of operation performed:

If an exception is thrown when attempting to cast the value of Self.CurrentElement to the correct type, this method will exit and the caller is expected to handle the exception. When called from ALinearCCompoundExpression.performOperation, a syntax error message is generated in response to the exception.

Returns

True if the operation was successfully performed; False otherwise.

Public function performBitwiseOperation: boolean; virtual;

Perform a bitwise or logical operation that involves Self.value and the value of Self.CurrentElement.

The type of value stored in Self.value determines the type of operation performed:

If an exception is thrown when attempting to cast the value of Self.CurrentElement to the correct type, this method will exit and the caller is expected to handle the exception. When called from ALinearCCompoundExpression.performOperation, a syntax error message is generated in response to the exception.

Returns

True if the operation was successfully performed; False otherwise.

Public function performEqualityTestOperation: boolean; virtual;

Perform an equality-test operation that involves Self.value and the value of Self.CurrentElement.

The type of value stored in Self.value determines the type of operation performed:

  • If Self.value is a string, then the value of Self.CurrentElement is cast as a string and SysUtils.ansiCompareStr is used to determine the relative equality of the two string values.

  • If Self.value is an integer value or a floating point value Self.CurrentElement is cast to the appropriate type and the relevant equality test is performed.

  • For all other types, this method fails and returns False.

If an exception is thrown when attempting to cast the value of Self.CurrentElement to the correct type, this method will exit and the caller is expected to handle the exception. When called from ALinearCCompoundExpression.performOperation, a syntax error message is generated in response to the exception.

Returns

True if the operation was successfully performed; False otherwise.

Public function PreviousExpression: ALinearCExpression; virtual;

Retrieve a reference to the previous expression parsed by the compound expression.

This method simply casts the return value of Self.PreviousElement as an instance of ALinearCExpression.

Public function CurrentExpression: ALinearCExpression; virtual;

Retrieve a reference to the current expression parsed by the compound expression.

This method simply casts the return value of Self.CurrentElement as an instance of ALinearCExpression.

Public function operation: TOpcode;

Retrieve the operator encountered while parsing the compound expression, if any.

Although a compound expression will generally consist of two or more subexpressions, separated by an operator, this is not required. It is perfectly valid for a compound expression to consist of a single subexpression with no operators, in which case this method will return zero (0).


Generated by PasDoc 0.13.0 on 2015-06-25 11:07:51