Class ASymbolParser

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type ASymbolParser = class(AParsedLanguageParser)

Description

This class represents a parser that processes a source file and enters any symbols found (variable names, function names, custom types, etc.) into its symbol tables. This class does not add much to what it inherits from AParsedLanguageParser because it is intended to serve as a template from which a custom parsing class may be derived. It does, however, automaticaly construct an instance of ASymbolTableVector and an instance of ASymbolTable to serve as the global symbol table. It also provides support routines that help to enter new symbols and to look up existing ones.

Hierarchy

Overview

Fields

Protected MySymbols: ASymbolTableVector;
Protected myCurrentScope: TSymbolScope;

Methods

Public constructor forSource(const ThisParent: AParser); override;
Public function init: boolean; override;
Public destructor destroy; override;
Public function readyToParse: boolean; override;
Public function EnterSymbolInto(const thisScope: TSymbolScope; const ThisSymbol: ASymbol; const freeOnFailure: boolean = true): ASymbol; virtual;
Public function EnterSymbol(const ThisSymbol: ASymbol; const freeOnFailure: boolean = true): ASymbol; virtual;
Public function EnterGlobalSymbol(const ThisSymbol: ASymbol; const freeOnFailure: boolean = true): ASymbol; virtual;
Public function NamedSymbolIn(const thisScope: TSymbolScope; const thisName: string): ASymbol; virtual;
Public function SymbolNamed(const thisName: string): ASymbol; virtual;
Public function Symbols: ASymbolTableVector; virtual;
Public function SymbolTableAt(const thisScope: TSymbolScope): ASymbolTable; virtual;
Public function GlobalSymbols: ASymbolTable; virtual;
Public function CurrentSymbols: ASymbolTable; virtual;
Public function currentScope: TSymbolScope; virtual;

Description

Fields

Protected MySymbols: ASymbolTableVector;

Refers to the list of symbol tables maintained by the parser

Protected myCurrentScope: TSymbolScope;

Stores the current scope (the current symbol table in use at the current location in the source).

Methods

Public constructor forSource(const ThisParent: AParser); override;

Construct a new parser instance that will inherit the properties of its parent parser.

This method buils on the behavior inherited from AParsedLanguageParser.forSource: it ensures that the new parser inherits the value of ThisParent's symbols and current scope.

Public function init: boolean; override;

Initializer

Public destructor destroy; override;

Destroy the parser.

This method frees ASymbolParser.Symbols and then calls the inherited routine.

Public function readyToParse: boolean; override;

Determine whether or not the parser is ready to parse.

This method builds on the behavior inherited from AParsedLanguageParser.readyToParse. It calls the inherited routine and, if that routine returns True to indicate all is well, it checks to determine whether Self.Symbols is Nil, indicating that a descendant has not yet constructed symbol tables for itself. If this is the case, the method will first see if there is a parent parser from which it can inherit a symbol table vector. If not, it will construct an instance of ASymbolTableVector and then insert an instance of ASymbolTable into it in order to represent the global scope. This behavior allows a descendant class to construct a different class or to fill the symbol table vector in a different way.

Returns

True if the parser is ready to parse; False if not.

Public function EnterSymbolInto(const thisScope: TSymbolScope; const ThisSymbol: ASymbol; const freeOnFailure: boolean = true): ASymbol; virtual;

Enter a new symbol into the symbol table at the specified scope.

This method adds ThisSymbol to the symbol table located at thisScope. If the symbol already exists in the table, it logs a syntax error.

If freeOnFailure is True, then this method will automatically free ThisSymbol if it could not be entered into the table. This behavior allows this method to be called with the results of a constructor call (e.g., ASymbolFromSource.named) as the value of ThisSymbol.

Returns

If the insertion was successful, this method returns ThisSymbol; if the insertion was not successful, it returns Nil.

Public function EnterSymbol(const ThisSymbol: ASymbol; const freeOnFailure: boolean = true): ASymbol; virtual;

Enter a new symbol into the current symbol table.

This method adds ThisSymbol to the symbol table located at ASymbolParser.currentScope. If the symbol already exists in the table, it logs a syntax error.

If freeOnFailure is True, then this method will automatically free ThisSymbol if it could not be entered into the table. This behavior allows this method to be called with the results of a constructor call (e.g., ASymbolFromSource.named) as the value of ThisSymbol.

Returns

If the insertion was successful, this method returns ThisSymbol; if the insertion was not successful, it returns Nil.

Public function EnterGlobalSymbol(const ThisSymbol: ASymbol; const freeOnFailure: boolean = true): ASymbol; virtual;

Enter a new symbol into the global symbol table.

This method adds ThisSymbol to the global symbol table. If the symbol already exists in the table, it logs a syntax error.

If freeOnFailure is True, then this method will automatically free ThisSymbol if it could not be entered into the table. This behavior allows this method to be called with the results of a constructor call (e.g., ASymbolFromSource.named) as the value of ThisSymbol.

Returns

If the insertion was successful, this method returns ThisSymbol; if the insertion was not successful, it returns Nil.

Public function NamedSymbolIn(const thisScope: TSymbolScope; const thisName: string): ASymbol; virtual;

Find a symbol with the given name by searching first in the specified scope and then outward.

This method calls ASymbolTable.SymbolNamed on the symbol table located at thisScope and returns the result.

Returns

If the symbol is found in either thisScope or a larger scope, then a reference to it is returned; otherwise, this method returns Nil.

Public function SymbolNamed(const thisName: string): ASymbol; virtual;

Find a symbol with the given name by searching first in the current scope and then outward.

This method calls ASymbolTable.SymbolNamed on the symbol table located at ASymbolParser.currentScope and returns the result.

Returns

If the symbol is found in either the current scope or a larger scope, then a reference to it is returned; otherwise, this method returns Nil.

Public function Symbols: ASymbolTableVector; virtual;

Retrieve a reference to the vector of symbol tables maintained by the parser. The reference returned by this routine should NOT be freed by the caller.

Public function SymbolTableAt(const thisScope: TSymbolScope): ASymbolTable; virtual;

Retrieve a reference to the symbol table at the given scope. The reference returned by this routine should NOT be freed by the caller.

If thisScope represents a value that is greater than or equal to the value of ASymbolTableVector.length, then this routine will return a reference to the global symbol table.

Public function GlobalSymbols: ASymbolTable; virtual;

Retrieve a reference to the symbol table that represents the global scope. The reference returned by this routine should NOT be freed by the caller.

Public function CurrentSymbols: ASymbolTable; virtual;

Retrieve a reference to the symbol table that represents the current scope. The reference returned by this routine should NOT be freed by the caller.

This method simply calls ASymbolParser.SymbolTableAt with the current value of ASymbolParser.currentScope and returns the result.

Public function currentScope: TSymbolScope; virtual;

Retrieve the current scope.

The value returned by this routine represents the symbol table currently in use at the current token position within the source being parsed.


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