Skip to content

Commit

Permalink
Added @ as an implicit label meaning "this line"
Browse files Browse the repository at this point in the history
  • Loading branch information
martindevans committed Nov 7, 2020
1 parent 5031972 commit 46618a9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions YololAssembler/Grammar/AST/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public Result Compile(bool compress = true)
// Replace line labels
lines = Apply(Labels().ToArray(), lines.ToArray()).ToArray();

// Replace implicit line labels
lines = ApplyImplicitLabels(lines).ToArray();

// Early out if compression should not be applied
var yolol = string.Join("\n", lines);
if (!compress)
Expand All @@ -39,6 +42,16 @@ public Result Compile(bool compress = true)
return new Result(Compress(parsedYolol.Ok));
}

private IEnumerable<string> ApplyImplicitLabels(IEnumerable<string> lines)
{
var lineNum = 1;
foreach (var line in lines)
{
yield return line.Replace("@", lineNum.ToString());
lineNum++;
}
}

private static string Compress(Yolol.Grammar.AST.Program yolol)
{
//todo: compress
Expand Down
3 changes: 3 additions & 0 deletions YololAssembler/YololAssembler.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Nullable>enable</Nullable>
<StartupObject>YololAssembler.Program</StartupObject>
<Authors>Martin Evans</Authors>
<Company>Cylon</Company>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 46618a9

Please sign in to comment.