-
Notifications
You must be signed in to change notification settings - Fork 0
Functions & Methods
public static DFSA CreateInstance(string filename)
- Creates a new Deterministic Finite State Automaton and returns it.
-
filename
full path to the automaton's definition file.
-
private DFSA(string filename)
- Deterministic Finite State Automaton private constructor.
-
filename
full path to the automaton's definition file.
-
public void Print()
Displays all the Automaton's info to the
STDOUT
.
- Calls
ToString
method in aConsole.WriteLine
statement.
public bool Analyse(string sourceCode)
Analyses a source code while displaying its
Lexemes (Lexical Units)
&Tokens
one-by-one and each whether it is accepted or not.
- Returns
bool
indicating whether asourcecode : String
is accepted by the automaton's defined language.-
sourceCode
the source code the be analysed.
-
- Calls
Accepts
&SplitToken
methods.
private int Accepts(string word)
Examines a Lexeme's symbols transitions and returns the final state occurred,
0
if none (lexeme not accepted by the automaton's described language).
- Returns
int
final state of the given word,0
if none.-
word
lexeme or lexical unit.
-
private bool Accept(string word)
Examines a Lexeme's symbols transitions and returns
true
if the Lexical Unit has a validendState
, otherwise returnsfalse
.
- Returns
bool
indicating whether the given word is accepted by the automaton's described language or not.-
word
lexeme or lexical unit.
-
public IEnumerable<string> SplitToken(string word)
Splits a Lexical Unit or Lexeme to Lexemes if they contain OPERATORS. (call in
Analyse
if (tokenId == 0 && word.Contains(_operators))
).
- Returns
IEnumerable<string>
that can be looped thru.-
word
lexeme or lexical unit.
-
public override string ToString()
Returns all the Automaton's info as
String
.
- Returns
string
representation of Automaton.
public Transition(int startState, char symbol, int endState)
Transition public constructor.
public override string ToString()
Returns
string
representation of Transition.
public bool Equals(Transition other)
Returns
bool
indicating whetherthis
&other
Transitions are equal.
public int σ(int? startState, char? symbol)
The Transition function.
- Returns
int
nextstate
,-1
if no next state was found.
public bool isΣ(int? startState, char? symbol)
Returns
bool
indicating whether the current Transition is the one the being looked for. (call inTransitionsMap [] operator
)
public int this[int i, char c]
The Transition function, returns the next or final state from the given
i
state andc
symbol,-1
if no match is found.
- Returns
int
nextstate
,-1
if no next state was found.
public override string ToString()
Returns
string
representation of TransitionsMap (All its Transitions).
public Token(int tokenId, string value)
Token public constructor.
- Checks for Tokens that could not be described in TokenTypes Enum.
- Checks if the token has an accepted
final state != 0
.
public bool Accepted()
Returns
bool
indicating whether the Token is accepted or not, based on the calculation in the constructor.
public override string ToString()
Returns
string
representation of Token.
public bool Accepted()
Returns
bool
indicating whether all theTokens
in theTokensList
are accepted or not.
public override string ToString()
Returns
string
representation of TokensList (All its Tokens).
public static void AddIfNotExists(this TransitionsMap transitionsMap, Transition transition)
Adds a new Transition to the TransitionsMap if it doesn't already exist.
public static bool Has(this TransitionsMap transitionsMap, Transition transition)
Returns
bool
indicating whether a givenTransition
exists in theTransitionsMap
or not.
public static TokenType GetToken(this TokenType tokenType, int tokenId)
Returns
TokenType
from a giventokenId : int
.
public static void AddIfNotExists<T>(this List<T> list, T item)
Adds a new
item : T
to the List if it doesn't already exist.
public static bool Contains(this string @string, IEnumerable<string> predicates)
Returns
bool
indicating whether a string contains any of thepredicates
.
public static IEnumerable<string> Split(this string word, IEnumerable<string> separators)
Returns
IEnumerable<string>
containingsubwords
found by splitting the givenword
using the given separators.