Skip to content

Instantly share code, notes, and snippets.

@MadaraUchiha
Created April 30, 2020 18:44
Show Gist options
  • Save MadaraUchiha/397dae94a15b6fe1692bd7be082f1f40 to your computer and use it in GitHub Desktop.
Save MadaraUchiha/397dae94a15b6fe1692bd7be082f1f40 to your computer and use it in GitHub Desktop.
public IEnumerable<Instruction> Transpiler(IEnumerable<Instruction> codes)
{
var state = TranspilerState.Initial;
foreach (var code of codes)
{
switch (state)
{
case TranspilerState.Initial:
if (SomeCondition(code))
{
state = TranspilerState.HitPattern;
}
break;
case TranspilerState.HitPattern:
return yield whatever;
return yield whatever;
return yield code;
state = TranspilerState.Done;
break;
case TranspilerState.Done:
yield return code;
break;
default
throw new Exception("Invalid state");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment