当前位置: 首页>>代码示例>>C#>>正文


C# System.IO.Peek方法代码示例

本文整理汇总了C#中System.IO.Peek方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.Peek方法的具体用法?C# System.IO.Peek怎么用?C# System.IO.Peek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO的用法示例。


在下文中一共展示了System.IO.Peek方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Scan

    private void Scan(IO.TextReader input)
    {
        while (input.Peek() != -1)
        {
            char ch = (char)input.Peek();

            // Scan individual tokens
            if (char.IsWhiteSpace(ch))
            {
                // eat the current char and skip ahead!
                input.Read();
            }
            else if (char.IsLetter(ch) || ch == '_')
            {
                // keyword or identifier

                Text.StringBuilder accum = new Text.StringBuilder();

                while (char.IsLetter(ch) || ch == '_')
                {
                    accum.Append(ch);
                    input.Read();

                    if (input.Peek() == -1)
                    {
                        break;
                    }
                    else
                    {
                        ch = (char)input.Peek();
                    }
                }

                this.result.Add(accum.ToString());
            }
            else if (ch == '"')
            {
                // string literal
                Text.StringBuilder accum = new Text.StringBuilder();

                input.Read(); // skip the '"'

                if (input.Peek() == -1)
                {
                    throw new System.Exception("unterminated string literal");
                }

                while ((ch = (char)input.Peek()) != '"')
                {
                    accum.Append(ch);
                    input.Read();

                    if (input.Peek() == -1)
                    {
                        throw new System.Exception("unterminated string literal");
                    }
                }

                // skip the terminating "
                input.Read();
                this.result.Add(accum);
            }
            else if (char.IsDigit(ch))
            {
                // numeric literal

                Text.StringBuilder accum = new Text.StringBuilder();

                while (char.IsDigit(ch))
                {
                    accum.Append(ch);
                    input.Read();

                    if (input.Peek() == -1)
                    {
                        break;
                    }
                    else
                    {
                        ch = (char)input.Peek();
                    }
                }

                this.result.Add(int.Parse(accum.ToString()));
            }
            else switch (ch)
            {
                case '+':
                    input.Read();
                    this.result.Add(Scanner.Add);
                    break;

                case '-':
                    input.Read();
                    this.result.Add(Scanner.Sub);
                    break;

                case '*':
                    input.Read();
                    this.result.Add(Scanner.Mul);
//.........这里部分代码省略.........
开发者ID:Merbo,项目名称:CSharpBot,代码行数:101,代码来源:Scanner.cs

示例2: Scan

    private void Scan(IO.TextReader input)
    {
        while (input.Peek() != -1)
        {
            char caracter = (char)input.Peek();

            // Scan individual tokens
            if (char.IsWhiteSpace(caracter))
            {
                // eat the current char and skip ahead!
                input.Read();
            }
            else if (char.IsLetter(caracter) || caracter == '_')
            {
                // keyword or identifier

                Text.StringBuilder accum = new Text.StringBuilder();

                while (char.IsLetter(caracter) || caracter == '_')
                {
                    accum.Append(caracter);
                    input.Read();

                    if (input.Peek() == -1)
                    {
                        break;
                    }
                    else
                    {
                        caracter = (char)input.Peek();
                    }
                }

                this.resultado.Add(accum.ToString());
            }
            else if (caracter == '"')
            {
                // string literal
                Text.StringBuilder accum = new Text.StringBuilder();

                input.Read(); // skip the '"'

                if (input.Peek() == -1)
                {
                    throw new System.Exception("Cadena sin terminar");
                }

                while ((caracter = (char)input.Peek()) != '"')
                {
                    accum.Append(caracter);
                    input.Read();

                    if (input.Peek() == -1)
                    {
                        throw new System.Exception("Cadena sin terminar");
                    }
                }

                // skip the terminating "
                input.Read();
                this.resultado.Add(accum);
            }
            else if (char.IsDigit(caracter))
            {
                // numeric literal

                Text.StringBuilder accum = new Text.StringBuilder();

                while (char.IsDigit(caracter))
                {
                    accum.Append(caracter);
                    input.Read();

                    if (input.Peek() == -1)
                    {
                        break;
                    }
                    else
                    {
                        caracter = (char)input.Peek();
                    }
                }

                this.resultado.Add(int.Parse(accum.ToString()));
            }
            else switch (caracter)
            {
                case '+':
                    input.Read();
                    this.resultado.Add(Scanner.Sum);
                    break;

                case '-':
                    input.Read();
                    this.resultado.Add(Scanner.Res);
                    break;

                case '*':
                    input.Read();
                    this.resultado.Add(Scanner.Mul);
//.........这里部分代码省略.........
开发者ID:FANMixco,项目名称:Simple_Compiler,代码行数:101,代码来源:Scanner.cs


注:本文中的System.IO.Peek方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。