As per #11, this fixes the issue with multi-line literals
Some checks failed
continuous-integration/appveyor/branch AppVeyor build succeeded
continuous-integration/appveyor/pull-request AppVeyor was unable to build non-mergeable pull request
Some checks failed
continuous-integration/appveyor/branch AppVeyor build succeeded
continuous-integration/appveyor/pull-request AppVeyor was unable to build non-mergeable pull request
This commit is contained in:
parent
eb9d9cc177
commit
cd3bbe12e1
1
.gitignore
vendored
1
.gitignore
vendored
@ -364,3 +364,4 @@ FodyWeavers.xsd
|
|||||||
|
|
||||||
# Assignment 1 instructions
|
# Assignment 1 instructions
|
||||||
assignment_instructions.txt
|
assignment_instructions.txt
|
||||||
|
159.341_Assignment_1.zip
|
||||||
|
@ -180,7 +180,7 @@ namespace Assignment_1
|
|||||||
result = Exit(source, initSourceLength, dynamicInput);
|
result = Exit(source, initSourceLength, dynamicInput);
|
||||||
break;
|
break;
|
||||||
case Statements.append:
|
case Statements.append:
|
||||||
result = AppendSet(source);
|
result = AppendSet(source, dynamicInput);
|
||||||
break;
|
break;
|
||||||
case Statements.list:
|
case Statements.list:
|
||||||
long pos = FindNextWord(source, out string nextWord);
|
long pos = FindNextWord(source, out string nextWord);
|
||||||
@ -195,19 +195,19 @@ namespace Assignment_1
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Statements.print:
|
case Statements.print:
|
||||||
result = Print(source, 0);
|
result = Print(source, dynamicInput, 0);
|
||||||
break;
|
break;
|
||||||
case Statements.printlength:
|
case Statements.printlength:
|
||||||
result = Print(source, 1);
|
result = Print(source, dynamicInput, 1);
|
||||||
break;
|
break;
|
||||||
case Statements.printwords:
|
case Statements.printwords:
|
||||||
result = Print(source, 2);
|
result = Print(source, dynamicInput, 2);
|
||||||
break;
|
break;
|
||||||
case Statements.printwordcount:
|
case Statements.printwordcount:
|
||||||
result = Print(source, 3);
|
result = Print(source, dynamicInput, 3);
|
||||||
break;
|
break;
|
||||||
case Statements.set:
|
case Statements.set:
|
||||||
result = AppendSet(source, false);
|
result = AppendSet(source, dynamicInput, false);
|
||||||
break;
|
break;
|
||||||
case Statements.reverse:
|
case Statements.reverse:
|
||||||
result = Reverse(source);
|
result = Reverse(source);
|
||||||
@ -321,9 +321,9 @@ namespace Assignment_1
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if the next expression meets the requirements of being a value
|
/// Checks if the next expression meets the requirements of being a value
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private string ValidateValue(Stream source)
|
private string ValidateValue(Stream source, bool dynamicInput)
|
||||||
{
|
{
|
||||||
long valuePos = FindExpression(source, out string value);
|
long valuePos = FindExpression(source, dynamicInput, out string value);
|
||||||
if (valuePos < 0)
|
if (valuePos < 0)
|
||||||
{
|
{
|
||||||
throw new ParserException("Could not evaluate expression", 0, source.Position);
|
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 />
|
/// Handles the 'append x y [ + z];' case <br />
|
||||||
/// And the 'set x y [ + z];' case
|
/// And the 'set x y [ + z];' case
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Action AppendSet(Stream source, bool appendMode = true)
|
Action AppendSet(Stream source, bool dynamicInput, bool appendMode = true)
|
||||||
{
|
{
|
||||||
string key = ValidateKey(source, appendMode);
|
string key = ValidateKey(source, appendMode);
|
||||||
string value = ValidateValue(source);
|
string value = ValidateValue(source, dynamicInput);
|
||||||
if (appendMode)
|
if (appendMode)
|
||||||
{
|
{
|
||||||
return () => Symbols[key] = new Tuple<string, VariableFlags>(Symbols[key].Item1 + value, Symbols[key].Item2);
|
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 />
|
/// 2: print the word count <br />
|
||||||
/// 3: print the words in the value <br />
|
/// 3: print the words in the value <br />
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Action Print(Stream source, int mode = 0)
|
Action Print(Stream source,bool dynamicInput, int mode = 0)
|
||||||
{
|
{
|
||||||
StringBuilder outputString = new StringBuilder();
|
StringBuilder outputString = new StringBuilder();
|
||||||
string expression = ValidateValue(source);
|
string expression = ValidateValue(source, dynamicInput);
|
||||||
if (mode == 0)
|
if (mode == 0)
|
||||||
{
|
{
|
||||||
outputString.Append(expression + Environment.NewLine);
|
outputString.Append(expression + Environment.NewLine);
|
||||||
@ -516,7 +516,7 @@ namespace Assignment_1
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parses & evaluates the expression from the stream, moving the stream to the end of the last value
|
/// Parses & evaluates the expression from the stream, moving the stream to the end of the last value
|
||||||
/// </summary>
|
/// </summary>
|
||||||
long FindExpression(Stream s, out string expression)
|
long FindExpression(Stream s, bool dynamicInput, out string expression)
|
||||||
{
|
{
|
||||||
string result = "";
|
string result = "";
|
||||||
bool IsAppendSet = true;
|
bool IsAppendSet = true;
|
||||||
@ -529,7 +529,7 @@ namespace Assignment_1
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
long val = FindValue(s, out string value);
|
long val = FindValue(s, dynamicInput, out string value);
|
||||||
if (val == -1)
|
if (val == -1)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Could not parse value");
|
Console.WriteLine("Could not parse value");
|
||||||
@ -569,14 +569,28 @@ namespace Assignment_1
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Finds the next value expression in the stream
|
/// Finds the next value expression in the stream
|
||||||
/// </summary>
|
/// </summary>
|
||||||
long FindValue(Stream s, out string returnedValue)
|
long FindValue(Stream s, bool dynamicInput, out string returnedValue)
|
||||||
{
|
{
|
||||||
SkipWhitespace(s);
|
SkipWhitespace(s);
|
||||||
char result = PeekChar(s);
|
char result = PeekChar(s);
|
||||||
if (result == '\"')
|
if (result == '\"')
|
||||||
{
|
{
|
||||||
// The first char is a ", i.e. the start of a literal - search as if it were a literal.
|
// The first char is a ", i.e. the start of a literal - search as if it were a literal.
|
||||||
return FindLiteral(s, out returnedValue);
|
// 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;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user