Overview   Project   Class   Tree   Deprecated   Index 
Grammatica 1.5 Documentation
FRAMES    NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD

PerCederberg.Grammatica.Runtime
Class LookAheadSet

System.Object
   |
   +--LookAheadSet

   in LookAheadSet.cs

internal class LookAheadSet
extends System.Object

A token look-ahead set. This class contains a set of token id sequences. All sequences in the set are limited in length, so that no single sequence is longer than a maximum value. This class also filters out duplicates. Each token sequence also contains a repeat flag, allowing the look-ahead set to contain information about possible infinite repetitions of certain sequences. That information is important when conflicts arise between two look-ahead sets, as such a conflict cannot be resolved if the conflicting sequences can be repeated (would cause infinite loop).


Inner Classes, Typedefs, and Enums
class LookAheadSet.Sequence
          A token sequence.
 
Constructor Summary
LookAheadSet( int maxLength )
          Creates a new look-ahead set with the specified maximum length.
LookAheadSet( int maxLength, LookAheadSet set )
          Creates a duplicate look-ahead set, possibly with a different maximum length.
 
Method Summary
 void Add( int token )
          Adds a new token sequence with a single token to this set.
 void AddAll( LookAheadSet set )
          Adds all the token sequences from a specified set.
 void AddEmpty()
          Adds an empty token sequence to this set.
 LookAheadSet CreateCombination( LookAheadSet set )
          Creates a new look-ahead set that is the combination of this set with another set.
 LookAheadSet CreateFilter( LookAheadSet set )
          Creates a new look-ahead set filter.
 LookAheadSet CreateIntersection( LookAheadSet set )
          Creates a new look-ahead set that is the intersection of this set with another set.
 LookAheadSet CreateNextSet( int token )
          Creates a new look-ahead set that is the result of reading the specified token.
 LookAheadSet CreateOverlaps( LookAheadSet set )
          Creates a new look-ahead set with overlaps from another.
 LookAheadSet CreateRepetitive()
          Creates a new identical look-ahead set, except for the repeat flag being set in each token sequence.
 int[] GetInitialTokens()
          Returns a list of the initial token id:s in this look-ahead set.
 int GetMaxLength()
          Returns the length of the longest token sequence in this set.
 int GetMinLength()
          Returns the length of the shortest token sequence in this set.
 bool Intersects( LookAheadSet set )
          Checks if some token sequence is present in both this set and a specified one.
 bool IsNext( Parser parser )
          Checks if the next token(s) in the parser match any token sequence in this set.
 bool IsNext( Parser parser, int length )
          Checks if the next token(s) in the parser match any token sequence in this set.
 bool IsOverlap( LookAheadSet set )
          Checks if another look-ahead set has an overlapping token sequence.
 bool IsRepetitive()
          Checks if this look-ahead set contains a repetitive token sequence.
 void RemoveAll( LookAheadSet set )
          Removes all the token sequences from a specified set.
 int Size()
          Returns the size of this look-ahead set.
 override string ToString()
          Returns a string representation of this object.
 string ToString( Tokenizer tokenizer )
          Returns a string representation of this object.
 

Constructor Detail

LookAheadSet

public LookAheadSet( int maxLength );
Creates a new look-ahead set with the specified maximum length.
Parameters:
maxLength - the maximum token sequence length

LookAheadSet

public LookAheadSet( int maxLength, LookAheadSet set );
Creates a duplicate look-ahead set, possibly with a different maximum length.
Parameters:
maxLength - the maximum token sequence length
set - the look-ahead set to copy


Method Detail

Add

public void Add( int token );
Adds a new token sequence with a single token to this set. The sequence will only be added if it is not already in the set.
Parameters:
token - the token to add

AddAll

public void AddAll( LookAheadSet set );
Adds all the token sequences from a specified set. Only sequences not already in this set will be added.
Parameters:
set - the set to add from

AddEmpty

public void AddEmpty();
Adds an empty token sequence to this set. The sequence will only be added if it is not already in the set.

CreateCombination

public LookAheadSet CreateCombination( LookAheadSet set );
Creates a new look-ahead set that is the combination of this set with another set. The combination is created by creating new token sequences that consist of appending all elements from the specified set onto all elements in this set. This is sometimes referred to as the cartesian product.
Parameters:
set - the set to combine with
Returns:
a new look-ahead set containing the combination

CreateFilter

public LookAheadSet CreateFilter( LookAheadSet set );
Creates a new look-ahead set filter. The filter will contain all sequences from this set, possibly left trimmed by each one of the sequences in the specified set.
Parameters:
set - the look-ahead set to trim with
Returns:
a new look-ahead set filter

CreateIntersection

public LookAheadSet CreateIntersection( LookAheadSet set );
Creates a new look-ahead set that is the intersection of this set with another set. The token sequences in the net set will only have the repeat flag set if it was set in both the identical token sequences.
Parameters:
set - the set to intersect with
Returns:
a new look-ahead set containing the intersection

CreateNextSet

public LookAheadSet CreateNextSet( int token );
Creates a new look-ahead set that is the result of reading the specified token. The new look-ahead set will contain the rest of all the token sequences that started with the specified token.
Parameters:
token - the token to read
Returns:
a new look-ahead set containing the remaining tokens

CreateOverlaps

public LookAheadSet CreateOverlaps( LookAheadSet set );
Creates a new look-ahead set with overlaps from another. All token sequences in this set that overlaps with the other set will be added to the new look-ahead set.
Parameters:
set - the look-ahead set to check with
Returns:
a new look-ahead set containing the overlaps

CreateRepetitive

public LookAheadSet CreateRepetitive();
Creates a new identical look-ahead set, except for the repeat flag being set in each token sequence.
Returns:
a new repetitive look-ahead set

GetInitialTokens

public int[] GetInitialTokens();
Returns a list of the initial token id:s in this look-ahead set. The list returned will not contain any duplicates.
Returns:
a list of the inital token id:s in this look-ahead set

GetMaxLength

public int GetMaxLength();
Returns the length of the longest token sequence in this set. This method will return zero (0) if the set is empty.
Returns:
the length of the longest token sequence

GetMinLength

public int GetMinLength();
Returns the length of the shortest token sequence in this set. This method will return zero (0) if the set is empty.
Returns:
the length of the shortest token sequence

Intersects

public bool Intersects( LookAheadSet set );
Checks if some token sequence is present in both this set and a specified one.
Parameters:
set - the look-ahead set to compare with
Returns:
true if the look-ahead sets intersect, or false otherwise

IsNext

public bool IsNext( Parser parser );
Checks if the next token(s) in the parser match any token sequence in this set.
Parameters:
parser - the parser to check
Returns:
true if the next tokens are in the set, or false otherwise

IsNext

public bool IsNext( Parser parser, int length );
Checks if the next token(s) in the parser match any token sequence in this set.
Parameters:
parser - the parser to check
length - the maximum number of tokens to check
Returns:
true if the next tokens are in the set, or false otherwise

IsOverlap

public bool IsOverlap( LookAheadSet set );
Checks if another look-ahead set has an overlapping token sequence. An overlapping token sequence is a token sequence that is identical to another sequence, but for the length. I.e. one of the two sequences may be longer than the other.
Parameters:
set - the look-ahead set to check
Returns:
true if there is some token sequence that overlaps, or false otherwise

IsRepetitive

public bool IsRepetitive();
Checks if this look-ahead set contains a repetitive token sequence.
Returns:
true if at least one token sequence is repetitive, or false otherwise

RemoveAll

public void RemoveAll( LookAheadSet set );
Removes all the token sequences from a specified set. Only sequences already in this set will be removed.
Parameters:
set - the set to remove from

Size

public int Size();
Returns the size of this look-ahead set.
Returns:
the number of token sequences in the set

ToString

public override string ToString();
Returns a string representation of this object.
Returns:
a string representation of this object

ToString

public string ToString( Tokenizer tokenizer );
Returns a string representation of this object.
Parameters:
tokenizer - the tokenizer containing the tokens
Returns:
a string representation of this object

 Overview   Project   Class   Tree   Deprecated   Index 
Grammatica 1.5 Documentation
FRAMES    NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD