I'm working with the scanner of an interpreter that I'm doing, but I find that the class StreamReader
becomes a bit slow with somewhat heavy files, so far I have the following:
using System.Collections.Generic;
using System.IO;
abstract class Scanner
{
// Campos...
private char[] Input;
public virtual IList<Token> Scan()
{
// Código para escanear.
return Tokens;
}
public Scanner(string _path, bool _debug)
{
// ...
using (StreamReader sr = new StreamReader(_path))
Input = sr.ReadToEnd().ToCharArray(); // Lee todo el archivo y lo convierte a un char[].
}
}
My problem is this, is there a way to not have to read the entire file and convert it into an array of char
to use it throughout the scan? What I'm looking for is to read the file, return the next character and close the file without keeping it in memory and remembering the position of the last character read.