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 function init: boolean; override;
Public destructor destroy; override;
Public function parse: int64; 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 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 parse: int64; override;

Parse the source.

This method builds on the behavior inherited from AParsedLanguageParser.parse. It calls the inherited routine and, if that routine returns zero (0) to indicate all is well, it checks to determine whether ASymbolParser.Symbols is Nil. If so, it constructs an instance of ASymbolTableVector and then inserts 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 fill the symbol table vector in a different way.

Returns

A negative value if an error has occurred before any parsing was done. This will most likely occur if AParser.Source, AParser.Log, AParsedLanguageParser.Language, or ASymbolParser.Symbols are invalid (Nil) pointers. A positive value indicates the number of non-fatal errors that occurred while parsing. A value of zero (0) indicates all is well.

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-01-10 17:13:18