public static bool TryParse(string[] tokens, out ImportDirective id) { if (tokens.Length < 1 || tokens[0].Length == 0) { id = null; return(false); } if (tokens[0] == "@import") { if (tokens.Length < 2) { Console.Error.WriteLine("Expected symbol name after @import"); id = null; return(false); } if (tokens.Length > 2) { Console.Error.WriteLine("Too many tokens after @import"); id = null; return(false); } var ret = new ImportDirective(); ret.Label = tokens[1]; id = ret; return(true); } id = null; return(false); }
private static bool TryParseWithoutLabel(string[] tokens, out Line result) { // Attempt to parse as instruction. Instruction inst; if (Instruction.TryParse(tokens, out inst)) { result = inst; return(true); } // Attempt to parse as directive. AssemblerDirective dir; if (AssemblerDirective.TryParse(tokens, out dir)) { result = dir; return(true); } // Attempt to parse as @import. ImportDirective id; if (ImportDirective.TryParse(tokens, out id)) { result = id; return(true); } // Attempt to parse as @export. ExportDirective ed; if (ExportDirective.TryParse(tokens, out ed)) { result = ed; return(true); } result = null; return(false); }