C# Class Axiom.RenderSystems.OpenGL.ATI.Compiler2Pass

Compiler2Pass is a generic compiler/assembler.
Provides a tokenizer in pass 1 and relies on the subclass to provide the virtual method for pass 2 PASS 1 - tokenize source: this is a simple brute force lexical scanner/analyzer that also parses the formed token for proper semantics and context in one pass it uses Look Ahead Left-Right (LALR) ruling based on Backus - Naur From notation for semantic checking and also performs context checking allowing for language dialects. PASS 2 - generate application specific instructions ie native instructions

This class must be subclassed with the subclass providing implementation for Pass 2. The subclass is responsible for setting up the token libraries along with defining the language syntax.

Show file Open project: WolfgangSt/axiom

Protected Properties

Property Type Description
activeContexts uint
charPos int
constants Axiom.Core.FloatList
currentLine int
endOfSource int
rootRulePath Axiom.RenderSystems.OpenGL.ATI.TokenRule[]
rulePathLibCount int
source string
symbolTypeLib Axiom.RenderSystems.OpenGL.ATI.SymbolDef[]
symbolTypeLibCount int
tokenInstructions Axiom.RenderSystems.OpenGL.ATI.TokenInstructionList
valueID Symbol

Public Methods

Method Description
Compile ( string source ) : bool

Compile the source - performs 2 passes: First pass is to tokinize, check semantics and context. Second pass is performed by subclass and converts tokens to application specific instructions.

Compiler2Pass ( ) : System

Default constructor.

Protected Methods

Method Description
DoPass1 ( ) : bool

perform pass 1 of compile process

Scans source for symbols that can be tokenized and then performs general semantic and context verification on each symbol before it is tokenized. A tokenized instruction list is built to be used by Pass 2.

DoPass2 ( ) : bool

Abstract method that must be set up by subclass to perform Pass 2 of compile process

FindEndOfLine ( ) : void
GetTypeDefText ( Symbol symbol ) : string

Get the text symbol for this token.

Mainly used for debugging and in test routines.

InitSymbolTypeLib ( ) : void

Initialize the type library with matching symbol text found in symbol text library. Find a default text for all Symbol Types in library. Scan through all the rules and initialize TypeLib with index to text and index to rules for non-terminal tokens. Must be called by subclass after libraries and rule database setup.

IsFloatValue ( float &val, int &length ) : bool

Check to see if the text at the present position in the source is a numerical constant.

IsSymbol ( string symbol, int &symbolSize ) : bool

Check to see if the text is in the symbol text library.

PositionToNextSymbol ( ) : bool

Position to the next possible valid symbol.

ProcessRulePath ( int rulePathIdx ) : bool

Process input source text using rulepath to determine allowed tokens.

The method is reentrant and recursive. if a non-terminal token is encountered in the current rule path then the method is called using the new rule path referenced by the non-terminal token Tokens can have the following operation states which effects the flow path of the rule Rule: defines a rule path for the non-terminal token. And: the token is required for the rule to pass. Or: if the previous tokens failed then try these ones. Optional: the token is optional and does not cause the rule to fail if the token is not found. Repeat: the token is required but there can be more than one in a sequence. End: end of the rule path - the method returns the success of the rule.

SetActiveContexts ( uint contexts ) : void

Setup ActiveContexts - should be called by subclass to setup initial language contexts.

SkipComments ( ) : void

Skips all comment specifiers.

SkipEndOfLine ( ) : void

Find the end of line marker and move past it.

SkipWhitespace ( ) : void

Skip all the whitespace which includes spaces and tabs.

ValidateToken ( int rulePathIdx, Symbol activeRuleID ) : bool

Check if current position in source has the symbol text equivalent to the TokenID.

Method Details

Compile() public method

Compile the source - performs 2 passes: First pass is to tokinize, check semantics and context. Second pass is performed by subclass and converts tokens to application specific instructions.
public Compile ( string source ) : bool
source string Source to be compiled.
return bool

Compiler2Pass() public method

Default constructor.
public Compiler2Pass ( ) : System
return System

DoPass1() protected method

perform pass 1 of compile process
Scans source for symbols that can be tokenized and then performs general semantic and context verification on each symbol before it is tokenized. A tokenized instruction list is built to be used by Pass 2.
protected DoPass1 ( ) : bool
return bool

DoPass2() protected abstract method

Abstract method that must be set up by subclass to perform Pass 2 of compile process
protected abstract DoPass2 ( ) : bool
return bool

FindEndOfLine() protected method

protected FindEndOfLine ( ) : void
return void

GetTypeDefText() protected method

Get the text symbol for this token.
Mainly used for debugging and in test routines.
protected GetTypeDefText ( Symbol symbol ) : string
symbol Symbol Token ID.
return string

InitSymbolTypeLib() protected method

Initialize the type library with matching symbol text found in symbol text library. Find a default text for all Symbol Types in library. Scan through all the rules and initialize TypeLib with index to text and index to rules for non-terminal tokens. Must be called by subclass after libraries and rule database setup.
protected InitSymbolTypeLib ( ) : void
return void

IsFloatValue() protected method

Check to see if the text at the present position in the source is a numerical constant.
protected IsFloatValue ( float &val, int &length ) : bool
val float Receives the float value that is in the source.
length int Receives number of characters that make of the value in the source.
return bool

IsSymbol() protected method

Check to see if the text is in the symbol text library.
protected IsSymbol ( string symbol, int &symbolSize ) : bool
symbol string
symbolSize int
return bool

PositionToNextSymbol() protected method

Position to the next possible valid symbol.
protected PositionToNextSymbol ( ) : bool
return bool

ProcessRulePath() protected method

Process input source text using rulepath to determine allowed tokens.
The method is reentrant and recursive. if a non-terminal token is encountered in the current rule path then the method is called using the new rule path referenced by the non-terminal token Tokens can have the following operation states which effects the flow path of the rule Rule: defines a rule path for the non-terminal token. And: the token is required for the rule to pass. Or: if the previous tokens failed then try these ones. Optional: the token is optional and does not cause the rule to fail if the token is not found. Repeat: the token is required but there can be more than one in a sequence. End: end of the rule path - the method returns the success of the rule.
protected ProcessRulePath ( int rulePathIdx ) : bool
rulePathIdx int Index into to array of Token Rules that define a rule path to be processed.
return bool

SetActiveContexts() protected method

Setup ActiveContexts - should be called by subclass to setup initial language contexts.
protected SetActiveContexts ( uint contexts ) : void
contexts uint
return void

SkipComments() protected method

Skips all comment specifiers.
protected SkipComments ( ) : void
return void

SkipEndOfLine() protected method

Find the end of line marker and move past it.
protected SkipEndOfLine ( ) : void
return void

SkipWhitespace() protected method

Skip all the whitespace which includes spaces and tabs.
protected SkipWhitespace ( ) : void
return void

ValidateToken() protected method

Check if current position in source has the symbol text equivalent to the TokenID.
protected ValidateToken ( int rulePathIdx, Symbol activeRuleID ) : bool
rulePathIdx int Index into rule path database of token to validate.
activeRuleID Symbol Index of non-terminal rule that generated the token.
return bool

Property Details

activeContexts protected property

Active Contexts pattern used in pass 1 to determine which tokens are valid for a certain context.
protected uint activeContexts
return uint

charPos protected property

Current position in the source string.
protected int charPos
return int

constants protected property

Storage container for constants defined in source.
protected FloatList,Axiom.Core constants
return Axiom.Core.FloatList

currentLine protected property

Current line in the source string.
protected int currentLine
return int

endOfSource protected property

protected int endOfSource
return int

rootRulePath protected property

Reference to the root rule path - has to be set by subclass constructor.
protected TokenRule[],Axiom.RenderSystems.OpenGL.ATI rootRulePath
return Axiom.RenderSystems.OpenGL.ATI.TokenRule[]

rulePathLibCount protected property

protected int rulePathLibCount
return int

source protected property

Source to be compiled.
protected string source
return string

symbolTypeLib protected property

Reference to the Text and Token type libraries set up by subclass.
protected SymbolDef[],Axiom.RenderSystems.OpenGL.ATI symbolTypeLib
return Axiom.RenderSystems.OpenGL.ATI.SymbolDef[]

symbolTypeLibCount protected property

protected int symbolTypeLibCount
return int

tokenInstructions protected property

Container for tokens extracted from source.
protected TokenInstructionList,Axiom.RenderSystems.OpenGL.ATI tokenInstructions
return Axiom.RenderSystems.OpenGL.ATI.TokenInstructionList

valueID protected property

Needs to be initialized by the subclass before compiling occurs it defines the token ID used in the symbol type library.
protected Symbol valueID
return Symbol