Compare commits
No commits in common. "string-newline-fix" and "master" have entirely different histories.
string-new
...
master
1
.gitignore
vendored
1
.gitignore
vendored
@ -364,4 +364,3 @@ FodyWeavers.xsd
|
||||
|
||||
# Assignment 1 instructions
|
||||
assignment_instructions.txt
|
||||
159.341_Assignment_1.zip
|
||||
|
@ -180,7 +180,7 @@ namespace Assignment_1
|
||||
result = Exit(source, initSourceLength, dynamicInput);
|
||||
break;
|
||||
case Statements.append:
|
||||
result = AppendSet(source, dynamicInput);
|
||||
result = AppendSet(source);
|
||||
break;
|
||||
case Statements.list:
|
||||
long pos = FindNextWord(source, out string nextWord);
|
||||
@ -195,19 +195,19 @@ namespace Assignment_1
|
||||
}
|
||||
break;
|
||||
case Statements.print:
|
||||
result = Print(source, dynamicInput, 0);
|
||||
result = Print(source, 0);
|
||||
break;
|
||||
case Statements.printlength:
|
||||
result = Print(source, dynamicInput, 1);
|
||||
result = Print(source, 1);
|
||||
break;
|
||||
case Statements.printwords:
|
||||
result = Print(source, dynamicInput, 2);
|
||||
result = Print(source, 2);
|
||||
break;
|
||||
case Statements.printwordcount:
|
||||
result = Print(source, dynamicInput, 3);
|
||||
result = Print(source, 3);
|
||||
break;
|
||||
case Statements.set:
|
||||
result = AppendSet(source, dynamicInput, false);
|
||||
result = AppendSet(source, false);
|
||||
break;
|
||||
case Statements.reverse:
|
||||
result = Reverse(source);
|
||||
@ -321,9 +321,9 @@ namespace Assignment_1
|
||||
/// <summary>
|
||||
/// Checks if the next expression meets the requirements of being a value
|
||||
/// </summary>
|
||||
private string ValidateValue(Stream source, bool dynamicInput)
|
||||
private string ValidateValue(Stream source)
|
||||
{
|
||||
long valuePos = FindExpression(source, dynamicInput, out string value);
|
||||
long valuePos = FindExpression(source, out string value);
|
||||
if (valuePos < 0)
|
||||
{
|
||||
throw new ParserException("Could not evaluate expression", 0, source.Position);
|
||||
@ -339,10 +339,10 @@ namespace Assignment_1
|
||||
/// Handles the 'append x y [ + z];' case <br />
|
||||
/// And the 'set x y [ + z];' case
|
||||
/// </summary>
|
||||
Action AppendSet(Stream source, bool dynamicInput, bool appendMode = true)
|
||||
Action AppendSet(Stream source, bool appendMode = true)
|
||||
{
|
||||
string key = ValidateKey(source, appendMode);
|
||||
string value = ValidateValue(source, dynamicInput);
|
||||
string value = ValidateValue(source);
|
||||
if (appendMode)
|
||||
{
|
||||
return () => Symbols[key] = new Tuple<string, VariableFlags>(Symbols[key].Item1 + value, Symbols[key].Item2);
|
||||
@ -446,10 +446,10 @@ namespace Assignment_1
|
||||
/// 2: print the word count <br />
|
||||
/// 3: print the words in the value <br />
|
||||
/// </summary>
|
||||
Action Print(Stream source,bool dynamicInput, int mode = 0)
|
||||
Action Print(Stream source, int mode = 0)
|
||||
{
|
||||
StringBuilder outputString = new StringBuilder();
|
||||
string expression = ValidateValue(source, dynamicInput);
|
||||
string expression = ValidateValue(source);
|
||||
if (mode == 0)
|
||||
{
|
||||
outputString.Append(expression + Environment.NewLine);
|
||||
@ -516,7 +516,7 @@ namespace Assignment_1
|
||||
/// <summary>
|
||||
/// Parses & evaluates the expression from the stream, moving the stream to the end of the last value
|
||||
/// </summary>
|
||||
long FindExpression(Stream s, bool dynamicInput, out string expression)
|
||||
long FindExpression(Stream s, out string expression)
|
||||
{
|
||||
string result = "";
|
||||
bool IsAppendSet = true;
|
||||
@ -529,7 +529,7 @@ namespace Assignment_1
|
||||
}
|
||||
else
|
||||
{
|
||||
long val = FindValue(s, dynamicInput, out string value);
|
||||
long val = FindValue(s, out string value);
|
||||
if (val == -1)
|
||||
{
|
||||
Console.WriteLine("Could not parse value");
|
||||
@ -569,28 +569,14 @@ namespace Assignment_1
|
||||
/// <summary>
|
||||
/// Finds the next value expression in the stream
|
||||
/// </summary>
|
||||
long FindValue(Stream s, bool dynamicInput, out string returnedValue)
|
||||
long FindValue(Stream s, out string returnedValue)
|
||||
{
|
||||
SkipWhitespace(s);
|
||||
char result = PeekChar(s);
|
||||
if (result == '\"')
|
||||
{
|
||||
// The first char is a ", i.e. the start of a literal - search as if it were a literal.
|
||||
// If the literal reaches the end of the string & the last char is not ", then we are
|
||||
// expecting more - insert a new line into the stream
|
||||
long literalPos = FindLiteral(s, out returnedValue);
|
||||
if (dynamicInput)
|
||||
{
|
||||
long orig = s.Position;
|
||||
s.Position = literalPos - 1;
|
||||
if (literalPos == s.Length && ReadChar(s) != '"')
|
||||
{
|
||||
s.WriteByte((byte)'\n');
|
||||
literalPos++;
|
||||
}
|
||||
s.Position = orig;
|
||||
}
|
||||
return literalPos;
|
||||
return FindLiteral(s, out returnedValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user