Permalink
Browse files

AdventureSample - support empty PRINT

  • Loading branch information...
bobbymcr committed Apr 22, 2018
1 parent d31c296 commit aa4f7afda3d28bbed3a34da2c443b7de3ebd74ad
@@ -95,7 +95,7 @@ public void Many(string name, BasicExpression[] list)
switch (name)
{
case "Print":
this.AddPrint(list[0]);
this.AddPrint(list);
break;
case "Dim":
this.AddDim(list);
@@ -201,12 +201,23 @@ private void AddGoto(int destination)
this.lines.AddGoto(this.lineNumber, destination);
}
private void AddPrint(BasicExpression expr)
private void AddPrint(BasicExpression[] exprs)
{
ExpressionNode node = new ExpressionNode(this.generator, this.vars, this.methods);
expr.Accept(node);
SyntaxNode arg = this.generator.LiteralExpression(string.Empty);
foreach (BasicExpression expr in exprs)
{
expr.Accept(node);
arg = this.generator.AddExpression(arg, node.Value);
}
this.AddPrint(arg);
}
private void AddPrint(SyntaxNode arg)
{
string name = "PRINT";
var callPrint = this.generator.InvocationExpression(SyntaxFactory.IdentifierName(name), node.Value);
var callPrint = this.generator.InvocationExpression(SyntaxFactory.IdentifierName(name), arg);
this.lines.Add(this.lineNumber, callPrint);
var output = this.generator.MemberAccessExpression(this.generator.ThisExpression(), this.generator.IdentifierName("output"));
var callWriteLine = this.generator.MemberAccessExpression(output, "WriteLine");
@@ -97,7 +97,7 @@ private bool Main()
; // My first BASIC program
L20:
;
PRINT(""HELLO, WORLD!"");
PRINT(("""") + (""HELLO, WORLD!""));
A_s = (""a string"");
A_s = (""same string"");
B1_s = (""new string"");
@@ -17,7 +17,7 @@ public void TwoOnOneLine()
private bool Main()
{
this.Init();
PRINT(""HELLO, WORLD!"");
PRINT(("""") + (""HELLO, WORLD!""));
CLS();
return false;
}
@@ -36,7 +36,7 @@ public void ThreeOnOneLine()
private bool Main()
{
this.Init();
PRINT(""HELLO, WORLD!"");
PRINT(("""") + (""HELLO, WORLD!""));
CLS();
CLS();
return false;
@@ -56,7 +56,7 @@ public void ThreeOnOneLineCommentEnd()
private bool Main()
{
this.Init();
PRINT(""HELLO, WORLD!"");
PRINT(("""") + (""HELLO, WORLD!""));
CLS() // A comment
;
return false;
@@ -0,0 +1,30 @@
// <copyright file="PrintStatements.cs" company="Brian Rogers">
// Copyright (c) Brian Rogers. All rights reserved.
// </copyright>
namespace GWBas2CS.Test
{
using FluentAssertions;
using Xunit;
public sealed class PrintStatements
{
[Fact]
public void Empty()
{
const string Input = @"10 PRINT";
const string Expected = @"*
private bool Main()
{
this.Init();
PRINT("""");
return false;
}
*";
string actual = Test.Translate("MyProg", Input);
actual.Should().Match(Expected);
}
}
}

0 comments on commit aa4f7af

Please sign in to comment.