/// <summary> /// Parses a Fast program from given stream. /// </summary> public static FastPgm Parse(Stream stream, string filename = null) { var parser = new FastPgmParser(stream, filename); bool ok = parser.Parse(); if (ok) { return(parser.program); } else { throw new FastParseException("Error: fast parser failed", filename); } }
/// <summary> /// Parses a single Fast program from multiple files. /// Returns null if files is empty. /// </summary> /// <param name="files">given files</param> public static FastPgm ParseFiles(params string[] files) { FileStream stream = null; FastPgm pgm = null; foreach (var file in files) { try { FileInfo fi = new FileInfo(file); stream = fi.OpenRead(); var parser = new FastPgmParser(stream, fi.FullName); bool ok = parser.Parse(); if (!ok) { throw new FastParseException("Error: fast parser failed", fi.FullName); } if (pgm == null) { pgm = parser.program; } else { pgm.Add(parser.program.defs); } } finally { if (stream != null) { stream.Dispose(); stream = null; } } } return(pgm); }