Permalink
Browse files

AdventureSample - handle FOR/NEXT with many preceding stmts on same line

  • Loading branch information...
bobbymcr committed May 3, 2018
1 parent 8fee31c commit 30ba55f8c38dc6772b547d4f8833b302a8f20a19
@@ -1169,6 +1169,7 @@ public IEnumerable<SyntaxNode> Main()
public void For(int number, SyntaxNode vx, SyntaxNode sx, SyntaxNode ex, SyntaxNode sp)
{
this.Get(number).Add(null);
this.loops.Push(number, vx, sx, ex, sp);
}
@@ -1183,7 +1184,18 @@ public void Next(int end, SyntaxNode vx)
{
break;
}
else if (n >= start)
else if (n == start)
{
IEnumerable<SyntaxNode> nodes = null;
Line line = this.statements[n];
line.Reduce(ns =>
{
nodes = ns;
return Enumerable.Empty<SyntaxNode>();
});
body.AddRange(nodes);
}
else if (n > start)
{
body.AddRange(this.statements[n].Nodes());
this.statements.Remove(n);
@@ -9,6 +9,34 @@ namespace GWBas2CS.Test
public sealed class ForNextStatements
{
[Fact]
public void ManyStatementsOneLine()
{
const string Input =
@"10 CLS : FOR I=1 TO 5
20 A=I*2
30 NEXT I";
const string Expected = @"*
private int Main()
{
this.Init();
CLS();
I_n = (1);
while ((I_n) <= (5))
{
A_n = ((I_n) * (2));
I_n = ((I_n) + (1));
}
return 2;
}
*";
string actual = Test.Translate("MyProg", Input);
actual.Should().Match(Expected);
}
[Fact]
public void TwoNested()
{

0 comments on commit 30ba55f

Please sign in to comment.