예제 #1
0
        public bool MoveNext()
        {
            if (IsAtEnd)
            {
                return(false);
            }

            ++tokenOffset;

            while (tokenOffset >= readTokens.Count)
            {
                string line = input.ReadLine();

                if (line != null)
                {
                    readTokens.AddRange(Tokeniser.TokeniseLine(line, input.CurrentFile, input.LineNumber));
                }
                else
                {
                    break;
                }
            }

            IsAtEnd = tokenOffset >= readTokens.Count;
            return(!IsAtEnd);
        }
 public static IEnumerable<Token> Tokenise(IPositionableInputStream input)
 {
     while (true)
     {
         string line = input.ReadLine();
         if (line == null)
         {
             break;
         }
         foreach (var token in TokeniseLine(line, input.CurrentFile, input.LineNumber))
         {
             yield return token;
         }
         yield return new Token(new FilePosition(input.CurrentFile,
             input.LineNumber, line.Length), TokenType.CodeEnder, "NL");
     }
     yield return new Token();
 }
예제 #3
0
        public static IEnumerable <Token> Tokenise(IPositionableInputStream input)
        {
label_1:
            string line = input.ReadLine();

            if (line != null)
            {
                using (IEnumerator <Token> enumerator = Tokeniser.TokeniseLine(line, input.CurrentFile, input.LineNumber).GetEnumerator()) {
                    while (enumerator.MoveNext())
                    {
                        Token token = enumerator.Current;
                        yield return(token);
                    }
                    goto label_1;
                }
            }
            else
            {
                yield return(new Token(new FilePosition(input.CurrentFile, input.LineNumber, 0), TokenType.EndOfStream, "END"));
            }
        }
        private IEnumerable<KeyValuePair<INamed<string>, string[]>> FirstPass(IPositionableInputStream input, 
            Context assemblyContext, ILog log)
        {
            while (true)
            {
                string line = input.ReadLine();
                if (line == null)
                    break;

                string[] code = Nintenlord.Utility.Parser.SplitToParameters(line);

                if (code.Length > 0)
                {
                    if (code[0].EndsWith(":"))
                    {
                        code = HandleLabels(input, assemblyContext, log, code);
                    }

                    if (code.Length == 0) continue;

                    IBuiltInCode builtIn;
                    if (buildInCodes.TryGetValue(code[0], out builtIn))
                    {
                        string error;
                        if (builtIn.Matches("Code " + code[0], code.Length - 1, out error))
                        {
                            var causedError = builtIn.FirstPass(code, assemblyContext);
                            if (causedError)
                            {
                                log.AddError(input.GetErrorString(causedError.ErrorMessage));
                            }
                            yield return new KeyValuePair<INamed<string>, string[]>(builtIn, code);
                        }
                        else
                        {
                            log.AddError(input.GetErrorString(error));
                        }
                    }
                    else
                    {
                        ICodeTemplate template = codeStorage.FindTemplate(code);

                        if (template != null)
                        {
                            if (assemblyContext.Offset % template.OffsetMod != 0)
                            {
                                log.AddError(input.GetErrorString(
                                    string.Format(
                                    "Code {0}'s offset {1} is not divisible by {2}",
                                    template.Name,
                                    assemblyContext.Offset,
                                    template.OffsetMod
                                    )));
                            }
                            assemblyContext.Offset += template.GetLengthBytes(code);
                            yield return new KeyValuePair<INamed<string>, string[]>(template, code);
                        }
                        else
                        {
                            log.AddError(input.GetErrorString(string.Format(
                                    "No code named {0} with {1} parameters found",
                                    code[0],
                                    code.Length - 1
                                    )));
                        }
                    }
                }
            }
        }
예제 #5
0
        private IEnumerable <KeyValuePair <INamed <string>, string[]> > FirstPass(IPositionableInputStream input,
                                                                                  Context assemblyContext, ILog log)
        {
            while (true)
            {
                string line = input.ReadLine();
                if (line == null)
                {
                    break;
                }

                string[] code = Nintenlord.Utility.Parser.SplitToParameters(line);

                if (code.Length > 0)
                {
                    if (code[0].EndsWith(":"))
                    {
                        code = HandleLabels(input, assemblyContext, log, code);
                    }

                    if (code.Length == 0)
                    {
                        continue;
                    }

                    IBuiltInCode builtIn;
                    if (buildInCodes.TryGetValue(code[0], out builtIn))
                    {
                        string error;
                        if (builtIn.Matches("Code " + code[0], code.Length - 1, out error))
                        {
                            var causedError = builtIn.FirstPass(code, assemblyContext);
                            if (causedError)
                            {
                                log.AddError(input.GetErrorString(causedError.ErrorMessage));
                            }
                            yield return(new KeyValuePair <INamed <string>, string[]>(builtIn, code));
                        }
                        else
                        {
                            log.AddError(input.GetErrorString(error));
                        }
                    }
                    else
                    {
                        ICodeTemplate template = codeStorage.FindTemplate(code);

                        if (template != null)
                        {
                            if (assemblyContext.Offset % template.OffsetMod != 0)
                            {
                                log.AddError(input.GetErrorString(
                                                 string.Format(
                                                     "Code {0}'s offset {1} is not divisible by {2}",
                                                     template.Name,
                                                     assemblyContext.Offset,
                                                     template.OffsetMod
                                                     )));
                            }
                            assemblyContext.Offset += template.GetLengthBytes(code);
                            yield return(new KeyValuePair <INamed <string>, string[]>(template, code));
                        }
                        else
                        {
                            log.AddError(input.GetErrorString(string.Format(
                                                                  "No code named {0} with {1} parameters found",
                                                                  code[0],
                                                                  code.Length - 1
                                                                  )));
                        }
                    }
                }
            }
        }