-
-
Save juanplopes/991831 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public IEnumerable<Token> Scan(IEnumerable<char> source) | |
{ | |
var currentState = StatesTable.InitialStage; | |
var currentValue = ""; | |
Func<Token> markPartialStop = () => | |
{ | |
if (currentState.IsStop) | |
{ | |
var result = new Token(currentState.ResultingTokenId, currentValue); | |
currentState = StatesTable.InitialState; | |
currentValue = ""; | |
return result; | |
} | |
else | |
throw new ArgumentException("Invalid source", "source"); | |
}; | |
foreach (var symbol in source) | |
{ | |
if (currentState.Accepts(symbol)) | |
{ | |
currentState = StatesTable.Accept(currentState.ChangeTo(symbol)); | |
currentValue += c; | |
} | |
else yield return markPartialStop(); | |
} | |
yield return markPartialStop(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment