Esempio n. 1
0
        public static bool TryParse(string[] tokens, out ExportDirective ed)
        {
            if (tokens.Length < 1 || tokens[0].Length == 0)
            {
                ed = null;
                return(false);
            }
            if (tokens[0] == "@export")
            {
                if (tokens.Length < 2)
                {
                    Console.Error.WriteLine("Expected symbol name after @export");
                    ed = null;
                    return(false);
                }
                if (tokens.Length > 2)
                {
                    Console.Error.WriteLine("Too many tokens after @export");
                    ed = null;
                    return(false);
                }

                var ret = new ExportDirective();
                ret.Label = tokens[1];
                ed        = ret;
                return(true);
            }
            ed = null;
            return(false);
        }
Esempio n. 2
0
        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);
        }