Permalink
Browse files

AdventureSample - support IF/THEN

  • Loading branch information...
bobbymcr committed Apr 23, 2018
1 parent a1fab6a commit 5419e9dbaa546b2e69c2647b8bbe42ac1f1bd8ae
@@ -85,7 +85,11 @@ public void Go(string name, int dest)
public void IfThen(BasicExpression cond, BasicStatement ifTrue)
{
throw new NotImplementedException();
ifTrue.Accept(this);
ExpressionNode expr = new ExpressionNode(this.generator, this.vars, this.methods);
cond.Accept(expr);
var nz = this.generator.ValueNotEqualsExpression(expr.Value, this.generator.LiteralExpression(0));
this.lines.AddIfThen(this.lineNumber, nz);
}
public void Input(string prompt, BasicExpression v)
@@ -753,6 +757,11 @@ public void AddComment(int number, SyntaxTrivia comment)
this.Get(number).Add(comment);
}
public void AddIfThen(int number, SyntaxNode cond)
{
this.Get(number).Wrap(n => this.generator.IfStatement(cond, n));
}
public void AddGoto(int number, int destination)
{
var label = SyntaxFactory.IdentifierName(Label(destination));
@@ -884,6 +893,13 @@ public void Add(SyntaxTrivia comment)
}
}
public void Wrap(Func<IEnumerable<SyntaxNode>, SyntaxNode> wrap)
{
SyntaxNode wrapped = wrap(this.nodes);
this.nodes.Clear();
this.nodes.Add(wrapped);
}
public IEnumerable<SyntaxNode> Nodes(ISet<int> references)
{
if (references.Contains(this.number))
@@ -31,6 +31,7 @@ 140 CLS
170 GOSUB 2020
180 GOSUB 2030
190 INPUT A
200 IF A=1 THEN 190
1000 GOTO 20
2000 CLS
2010 RETURN
@@ -190,7 +191,14 @@ private int Main()
return 2;
}
L190:
;
A_n = (INPUT_n(""""));
if ((((A_n.CompareTo(1)) == (0)) ? (-1) : (0)) != (0))
{
goto L190;
}
goto L20;
return 2;
}

0 comments on commit 5419e9d

Please sign in to comment.