Skip to content

Commit

Permalink
fixed parsing of nested for loops
Browse files Browse the repository at this point in the history
  • Loading branch information
Walper committed Nov 22, 2023
1 parent c8f0b6c commit c72b0b3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
18 changes: 10 additions & 8 deletions LanguageParser/Parser/PreParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal sealed class PreParser
{
private readonly TokenStream _tokenStream;
private SyntaxException? _error;
private int? _targetPlacement;
private readonly Stack<int> _targetPlacement = new();

public PreParser(TokenStream tokenStream)
{
Expand Down Expand Up @@ -48,21 +48,23 @@ private IEnumerable<Token> GetTokensWithBraces()
yield return new Token(SyntaxKind.OpenBrace, "", stream.Current.Range.Start);

var index = stream.Index;
_targetPlacement = parser.ParseExpression()?.Range.End;

var target = parser.ParseExpression()?.Range.End;

while (stream.Index > index)
stream.Recede();

if (_targetPlacement is null)
if (target is null)
_error = parser.Error;
else
_targetPlacement.Push(target.Value);
}

yield return stream.Current;
if (_targetPlacement == stream.Current.Range.End)
yield return new Token(SyntaxKind.CloseBrace, "", _targetPlacement.Value);

if (_targetPlacement.TryPeek(out var currentTarget) && currentTarget == stream.Current.Range.End)
yield return new Token(SyntaxKind.CloseBrace, "", _targetPlacement.Pop());

stream.Advance();
}

Expand Down
15 changes: 15 additions & 0 deletions SimpleExecutor/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,19 @@ public string Output
// setColor("blue")
// else
// setColor("green")
// }

// setColor('transparent')
// jump(350,310)
//
// setColor('blue')
//
// for (number size =6; size <= 146; size = size + 20)
// {
// for (number i = 1; i < 4; i = i + 1)
// {
// move(size)
// rotate(90)
// size = size + 5
// }
// }

0 comments on commit c72b0b3

Please sign in to comment.