Moved Symbols to the Parser class, made it non-static, therefore instancing it instead of being a static global
All checks were successful
continuous-integration/appveyor/branch AppVeyor build succeeded
All checks were successful
continuous-integration/appveyor/branch AppVeyor build succeeded
This commit is contained in:
parent
9e68ca1fcd
commit
1bd6b1b040
@ -23,14 +23,6 @@ namespace Assignment_1
|
||||
Static = 4,
|
||||
Undef = 8
|
||||
}
|
||||
|
||||
static Dictionary<string, Tuple<string, VariableFlags>> Symbols = new()
|
||||
{
|
||||
{ "SPACE", new Tuple<string, VariableFlags>(" ", VariableFlags.Reserved | VariableFlags.NoPrint) },
|
||||
{ "TAB", new Tuple<string, VariableFlags>("\t", VariableFlags.Reserved | VariableFlags.NoPrint) },
|
||||
{ "NEWLINE", new Tuple<string, VariableFlags>("\n", VariableFlags.Reserved | VariableFlags.NoPrint) },
|
||||
{ "CARRIAGE_RETURN", new Tuple<string, VariableFlags>("\r", VariableFlags.Reserved | VariableFlags.NoPrint) }
|
||||
};
|
||||
/// <summary>
|
||||
/// Characters that cannot appear in a normal string
|
||||
/// </summary>
|
||||
@ -80,6 +72,14 @@ namespace Assignment_1
|
||||
}
|
||||
public class Parser
|
||||
{
|
||||
Dictionary<string, Tuple<string, VariableFlags>> Symbols = new()
|
||||
{
|
||||
{ "SPACE", new Tuple<string, VariableFlags>(" ", VariableFlags.Reserved | VariableFlags.NoPrint) },
|
||||
{ "TAB", new Tuple<string, VariableFlags>("\t", VariableFlags.Reserved | VariableFlags.NoPrint) },
|
||||
{ "NEWLINE", new Tuple<string, VariableFlags>("\n", VariableFlags.Reserved | VariableFlags.NoPrint) },
|
||||
{ "CARRIAGE_RETURN", new Tuple<string, VariableFlags>("\r", VariableFlags.Reserved | VariableFlags.NoPrint) }
|
||||
};
|
||||
|
||||
public enum statements
|
||||
{
|
||||
exit,
|
||||
@ -225,7 +225,6 @@ namespace Assignment_1
|
||||
{
|
||||
throw new ParserException("expected a semi-colon", 0, source.Position);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -256,9 +255,7 @@ namespace Assignment_1
|
||||
Environment.Exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -267,7 +264,14 @@ namespace Assignment_1
|
||||
}
|
||||
|
||||
#region Function Handling
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the next expression in the source meets the requirements of being a key,
|
||||
/// and optionally verify that key exists.
|
||||
/// Also contracts the key is not reserved or constant
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="checkExist"></param>
|
||||
/// <returns></returns>
|
||||
private string ValidateKey(Stream source, bool checkExist)
|
||||
{
|
||||
long keyEndPos = FindIdentifier(source, out string key);
|
||||
@ -290,6 +294,11 @@ namespace Assignment_1
|
||||
return key;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the next expression meets the requirements of being a value
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
private string ValidateValue(Stream source)
|
||||
{
|
||||
long valuePos = FindExpression(source, out string value);
|
||||
@ -303,6 +312,7 @@ namespace Assignment_1
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the 'append x y [ + z];' case &
|
||||
/// And the 'set x y [ + z];' case
|
||||
@ -337,8 +347,8 @@ namespace Assignment_1
|
||||
{
|
||||
int keyWidth = 21;
|
||||
int valueWidth = 50;
|
||||
int flagWidth = 9; // 80 char total
|
||||
StringBuilder consoleOutput = new StringBuilder();
|
||||
int flagWidth = 9;
|
||||
StringBuilder consoleOutput = new();
|
||||
consoleOutput.Append(string.Format("┌" + new string('─', keyWidth) + "┬" + new string('─', valueWidth) + "┬" + new string('─', flagWidth) + "┐\n"));
|
||||
consoleOutput.Append(string.Format("│{0}│{1}│{2}│\n", CenterString("Symbol", keyWidth), CenterString("Value", valueWidth), CenterString("Flags", flagWidth)));
|
||||
// Figure out how many symbols are eligible for printing
|
||||
|
Loading…
x
Reference in New Issue
Block a user