Added Set Function
This commit is contained in:
parent
65c3ab8459
commit
3460149258
@ -180,6 +180,40 @@ namespace Assignment_1
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Set(Stream source)
|
||||||
|
{
|
||||||
|
string identifier;
|
||||||
|
long resultPos = FindIdentifier(source, out identifier);
|
||||||
|
if (resultPos < 0)
|
||||||
|
{
|
||||||
|
// Couldn't match an identifier
|
||||||
|
// If ID Doesn't exist, we should make it
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
source.Position = resultPos;
|
||||||
|
string expression;
|
||||||
|
resultPos = FindExpression(source, out expression);
|
||||||
|
if (resultPos < 0)
|
||||||
|
{
|
||||||
|
// Couldn't match expression
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (Symbols.ContainsKey(identifier))
|
||||||
|
{
|
||||||
|
if (Symbols[identifier].Item2 == VariableFlags.Reserved)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error: Cannot assign to {0} as it is a reserved constant.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Symbols[identifier] = new Tuple<string, VariableFlags>(expression, Symbols[identifier].Item2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Symbols.Add(identifier, new Tuple<string, VariableFlags>(expression, VariableFlags.Empty));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
#region Data Handling
|
#region Data Handling
|
||||||
// Data Handling
|
// Data Handling
|
||||||
|
Loading…
x
Reference in New Issue
Block a user