• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Scanner类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Scanner的典型用法代码示例。如果您正苦于以下问题:C# Scanner类的具体用法?C# Scanner怎么用?C# Scanner使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Scanner类属于命名空间,在下文中一共展示了Scanner类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ReadInvalidRepeatedTagDirective

        public void ReadInvalidRepeatedTagDirective()
        {
            using (var reader = new StreamReader(string.Format("TestData{0}example-6.17_invalid-repeated-tag-directive.yml", Path.DirectorySeparatorChar)))
            {
                var scanner = new Scanner(reader);
                var tokens = scanner.ReadTokens().ToList();

                Assert.That(tokens.Count, Is.EqualTo(9));

                var directiveTokens = tokens.FindAll(t => t is DirectiveToken).Select(t => t as DirectiveToken).ToList();
                Assert.AreEqual(2, directiveTokens.Count);

                Assert.IsNotNull(directiveTokens[0]);
                Assert.That(directiveTokens[0].Name, Is.EqualTo("TAG"));

                Assert.IsNotNull(directiveTokens[1]);
                Assert.That(directiveTokens[1].Name, Is.EqualTo("TAG"));

                var directiveParameters0 = directiveTokens[0].Parameters.ToList();
                Assert.That(directiveParameters0.Count, Is.EqualTo(2));
                Assert.That(directiveParameters0[0], Is.EqualTo("!"));
                Assert.That(directiveParameters0[1], Is.EqualTo("!foo"));

                var directiveParameters1 = directiveTokens[1].Parameters.ToList();
                Assert.That(directiveParameters1.Count, Is.EqualTo(2));
                Assert.That(directiveParameters1[0], Is.EqualTo("!"));
                Assert.That(directiveParameters1[1], Is.EqualTo("!foo"));

                var documentContentToken = tokens.Find(t => t is DocumentContentToken) as DocumentContentToken;

                Assert.IsNotNull(documentContentToken);
                Assert.AreEqual("bar", documentContentToken.Content.TrimEnd());
            }
        }
开发者ID:yaml,项目名称:YamlSharp,代码行数:34,代码来源:ScannerTest.cs


示例2: Scan

 public static IEnumerable<Token> Scan(string source)
 {
     var se = new SymbolsEnumerator(source);
     var result = new Scanner(se).Scan();
     se.Dispose();
     return result;
 }
开发者ID:ElemarJR,项目名称:Jujubas,代码行数:7,代码来源:Tokenizer.cs


示例3: Run

    void Run()
    {
        Scanner input = new Scanner(Console.In);

        long A = input.NextInt();
        long B = input.NextInt();
        int N = input.NextInt();

        Bignum a = new Bignum(0);
        Bignum b = new Bignum(0);
        Bignum one = new Bignum(1);

        int last = 0;
        for (int i = 0; i < N; i++) {
            while (A % 2 == 0 && B % 2 == 0) { A /= 2; B /= 2; }

            if (A > B || (A == B && last == 0)) {
                B *= 2;
                last = 0;
                a.Add(a);
                a.Add(one);
            } else {
                A *= 2;
                last = 1;
                b.Add(b);
                b.Add(one);
            }
        }

        a.Add(b);
        Console.WriteLine(a);
    }
开发者ID:pandeyiyer,项目名称:acm,代码行数:32,代码来源:197.cs


示例4: Run

    void Run()
    {
        Scanner input = new Scanner(Console.In);

        string[] a = new string[3];
        for (int i = 0; i < 3; i++)
            a[i] = input.Next();

        int max = 0, min = 0, max_c = 1;
        for (int i = 1; i < 3; i++) {
            if (a[i].Length > a[max].Length ||
                (a[i].Length == a[max].Length && a[i].CompareTo(a[max]) > 0)) {
                max = i;
                max_c = 1;
            } else if (a[i] == a[max]) {
                max_c++;
            } else {
                min = i;
            }
        }

        string[] names = new string[] { "Mary", "Klaus", "Peter" };

        if (max_c == 1)
            Console.WriteLine(names[max]);
        else if (max_c == 2)
            Console.WriteLine(names[min]);
        else
            Console.WriteLine("Draw");
    }
开发者ID:pandeyiyer,项目名称:acm,代码行数:30,代码来源:B117.cs


示例5: Run

    void Run()
    {
        Scanner input = new Scanner(Console.In);

        long R = input.NextInt();
        long xc = input.NextInt();
        long yc = input.NextInt();
        long x = input.NextInt() - xc;
        long y = input.NextInt() - yc;
        long dx = input.NextInt() - xc - x;
        long dy = input.NextInt() - yc - y;

        long a = dx * dx + dy * dy;
        long b = 2 * x * dx + 2 * y * dy;
        long c = x * x + y * y - R * R;
        long det = b * b - 4 * a * c;

        if (det == 0)
            Console.WriteLine("0");
        else if (det < 0)
            Console.WriteLine("-1");
        else {
            double res = Math.Sqrt(det) / a * Math.Sqrt(dx * dx + dy * dy);
            Console.WriteLine("{0:0.00000000}", res);
        }
    }
开发者ID:pandeyiyer,项目名称:acm,代码行数:26,代码来源:A148.cs


示例6: Keywords

 public void Keywords(string keyword)
 {
     var lexer = new Scanner(keyword);
     Token next = lexer.NextToken();
     Assert.That(next, Is.InstanceOf<KeywordToken>());
     Assert.That(((KeywordToken)next).Value, Is.EqualTo(keyword));
 }
开发者ID:Lateks,项目名称:Mini-PL-Interpreter,代码行数:7,代码来源:LexerTest.cs


示例7: test_lex

 public void test_lex()
 {
     Scanner lex = new Scanner();
     lex.src = "int main() { return 0; }";
     lex.Lex();
     String output = lex.ToString();
 }
开发者ID:JianpingZeng,项目名称:C-Compiler,代码行数:7,代码来源:lex_test.cs


示例8: ParseSource

        public override Microsoft.VisualStudio.Package.AuthoringScope ParseSource(ParseRequest req)
        {
            Babel.Source source = (Babel.Source)this.GetSource(req.FileName);
            bool yyparseResult = false;

            // req.DirtySpan seems to be set even though no changes have occurred
            // source.IsDirty also behaves strangely
            // might be possible to use source.ChangeCount to sync instead

            if (req.DirtySpan.iStartIndex != req.DirtySpan.iEndIndex
                || req.DirtySpan.iStartLine != req.DirtySpan.iEndLine) {
                ErrorHandler handler = new ErrorHandler();
                Scanner scanner = new Scanner(); // string interface
                Parser parser = new Parser();  // use noarg constructor
                parser.scanner = scanner;
                scanner.Handler = handler;
                parser.SetHandler(handler);
                scanner.SetSource(req.Text, 0);

                parser.MBWInit(req);
                yyparseResult = parser.Parse();

                // store the parse results
                // source.ParseResult = aast;
                source.ParseResult = null;
                source.Braces = parser.Braces;

                // for the time being, just pull errors back from the error handler
                if (handler.ErrNum > 0) {
                    foreach (Babel.Parser.Error error in handler.SortedErrorList()) {
                        TextSpan span = new TextSpan();
                        span.iStartLine = span.iEndLine = error.line - 1;
                        span.iStartIndex = error.column;
                        span.iEndIndex = error.column + error.length;
                        req.Sink.AddError(req.FileName, error.message, span, Severity.Error);
                    }
                }
            }
            switch (req.Reason) {
                case ParseReason.Check:
                case ParseReason.HighlightBraces:
                case ParseReason.MatchBraces:
                case ParseReason.MemberSelectAndHighlightBraces:
                    // send matches to sink
                    // this should (probably?) be filtered on req.Line / col
                    if (source.Braces != null) {
                        foreach (TextSpan[] brace in source.Braces) {
                            if (brace.Length == 2)
                                req.Sink.MatchPair(brace[0], brace[1], 1);
                            else if (brace.Length >= 3)
                                req.Sink.MatchTriple(brace[0], brace[1], brace[2], 1);
                        }
                    }
                    break;
                default:
                    break;
            }

            return new AuthoringScope(req.Text);
        }
开发者ID:einaregilsson,项目名称:Process-Language-Runtime,代码行数:60,代码来源:CCSLanguage.cs


示例9: Parser

 public Parser(string exp, ICalcFunction calcFunc)
 {
     this.exp = exp;
     tree = null;
     scanner = new Scanner(exp);
     this.icalcfunc = calcFunc;
 }
开发者ID:marcpiulachs,项目名称:noahylk,代码行数:7,代码来源:Parser.cs


示例10: Run

    void Run()
    {
        Scanner input = new Scanner(Console.In);

        N = input.NextInt();

        value = new int[N + 1];
        for (int i = 1; i <= N; i++)
            value[i] = input.NextInt();

        kid = new int[N + 1];
        sib = new int[N + 1];
        parent = new int[N + 1];

        for (int i = 1; i < N; i++) {
            int x = input.NextInt();
            int p = input.NextInt();
            sib[x] = kid[p];
            kid[p] = x;
            parent[x] = p;
        }

        int root = 0;
        for (int i = 1; i <= N; i++)
            if (parent[i] == 0) root = i;

        memo = new int[N + 1, 2];
        got = new bool[N + 1, 2];

        int res = Math.Max(vertCov(root, 0), vertCov(root, 1));
        Console.WriteLine(res);
    }
开发者ID:pandeyiyer,项目名称:acm,代码行数:32,代码来源:A167.cs


示例11: ReadBareDocuments

        public void ReadBareDocuments()
        {
            using (var reader = new StreamReader(Path.Combine("TestData", "example-9.3_bare-documents.yml")))
            {
                var scanner = new Scanner(reader);
                var tokens = scanner.ReadTokens().ToList();

                Assert.That(tokens.Count, Is.EqualTo(12));
                Assert.That(tokens[0], Is.InstanceOf(typeof(StreamStartToken)));
                Assert.That(tokens[1], Is.InstanceOf(typeof(DirectivesStartToken)));
                Assert.That(tokens[2], Is.InstanceOf(typeof(DirectivesEndToken)));
                Assert.That(tokens[3], Is.InstanceOf(typeof(DocumentStartToken)));
                Assert.That(tokens[4], Is.InstanceOf(typeof(DocumentContentToken)));
                Assert.That(tokens[5], Is.InstanceOf(typeof(DocumentEndToken)));
                Assert.That(tokens[6], Is.InstanceOf(typeof(DirectivesStartToken)));
                Assert.That(tokens[7], Is.InstanceOf(typeof(DirectivesEndToken)));
                Assert.That(tokens[8], Is.InstanceOf(typeof(DocumentStartToken)));
                Assert.That(tokens[9], Is.InstanceOf(typeof(DocumentContentToken)));
                Assert.That(tokens[10], Is.InstanceOf(typeof(DocumentEndToken)));
                Assert.That(tokens[11], Is.InstanceOf(typeof(StreamEndToken)));

                Assert.That(((DocumentContentToken)tokens[4]).Content, Is.Not.Empty);
                Assert.That(((DocumentContentToken)tokens[9]).Content, Is.Not.Empty);
            }
        }
开发者ID:janno-p,项目名称:YamlSharp,代码行数:25,代码来源:ScannerTest.cs


示例12: Evaluate

        public override object Evaluate(Frame environment)
        {
            if (environment == null)
            {
                throw new ArgumentNullException("Environment can not be null.");
            }
            string path = environment.FindBindingValue(Parameters[0]).ToString();
            if (!File.Exists(path))
            {
                throw new Exception("Could not find file: " + path);
            }

            using (StreamReader codeReader = new StreamReader(File.Open(path, FileMode.Open)))
            {
                Scanner scanner = new Scanner(codeReader);

                Expression expr = scanner.NextExpression;
                string evaluation = string.Empty;
                while (expr != null)
                {
                    evaluation = environment.Evaluate(expr).ToString();
                    expr = scanner.NextExpression;
                }

                return evaluation;
            }
        }
开发者ID:csaba-dery,项目名称:SInterpreter,代码行数:27,代码来源:Load.cs


示例13: Parser

 // constructs a parser for a string in memory (used for test purposes)
 // ts is the string to be parsed, source is a name to be used as the
 // filename in any error messages.
 public Parser( string source, string ts )
 {
     this.filename = source;
     sc = new Scanner(source, ts);
     DeclaredFunctionList = new List<Function>();
     UsedFunctions = new List<Function>();
 }
开发者ID:bradens,项目名称:uvc,代码行数:10,代码来源:parser.cs


示例14: button2_Click

 private void button2_Click(object sender, EventArgs e)
 {
     label2.ForeColor = Color.Cyan;
     label2.Text = "Being Compiled.";
     try
     {
         Scanner scanner = null;
         using (TextReader input = File.OpenText(openFileDialog1.FileName))
         {
             scanner = new Scanner(input);
         }
         Parser parser = new Parser(scanner.Tokens);
         CodeGen codeGen = new CodeGen(parser.Result, Path.GetFileNameWithoutExtension(openFileDialog1.FileName) + ".exe");
         label2.ForeColor = Color.Lime;
         label2.Text = "Compiled! Check the directory this program is in, or click 'Test File' and check the console.";
         button3.Enabled = true;
     }
     catch (Exception ex)
     {
         textBox3.Show();
         textBox3.Text = ex.Message;
         label2.ForeColor = Color.Red;
         label2.Text = "Error!";
         button3.Enabled = false;
     }
 }
开发者ID:Merbo,项目名称:CSharpBot,代码行数:26,代码来源:GUI.cs


示例15: Main

        public static void Main(string[] arg)
        {
            if (arg.Length == 2)
            {
              Scanner scanner = new Scanner(arg[0]);
              Parser parser = new Parser(scanner);
              parser.Parse();
              if (parser.errors.count != 0)
              {
            Console.WriteLine("*** " + parser.errors.count + " Parsing errors ***");
            return;
              }

              parser.Write("output.ir");

              IRStream tuples = parser.GetStream();

              // Code Optimizations - 100% doesn't work yet
              // tuples = SSA.DoSSAOptimizations(tuples);

              // Register Allocation
              List<IRTuple> tuples_out = Allocate.run(tuples);

              // backenders should write ARM out to arg[1]
              CodeGen.IRListToArmFile(tuples_out, arg[1]);
              Console.Write("\n");
            }
            else Console.WriteLine("Usage: tcdscc <program.swift> <output.asm>");
        }
开发者ID:TribeMedia,项目名称:tcd-swift,代码行数:29,代码来源:Main.cs


示例16: EvoQLExpression

        public EvoQLExpression(string query, IEnumerable<GetTypes> defaultTypes)
        {
            MemoryStream stream = new MemoryStream();
            String errorString;
            StreamWriter writer = new StreamWriter(stream);
            writer.Write(query);
            writer.Flush();

            Scanner scanner = new Scanner(stream);
            Parser parser = new Parser(scanner);
            MemoryStream errorStream = new MemoryStream();
            StreamWriter errorWriter = new StreamWriter(errorStream);

            parser.errors.errorStream = errorWriter;
            parser.Parse();
            errorWriter.Flush();
            errorStream.Seek(0, SeekOrigin.Begin);
            errorString = new StreamReader(errorStream).ReadToEnd();
            errorStream.Close();
            stream.Close();

            if (parser.errors.count > 0)
            {
                Errors = errorString.Split('\n');
                HadErrors = true;
            }
            else
            {
                Tree = parser.RootTree;
            }
        }
开发者ID:yonglehou,项目名称:Bermuda,代码行数:31,代码来源:EvoQLExpression.cs


示例17: Run

    void Run()
    {
        Scanner input = new Scanner(Console.In);

        N = input.NextInt();
        mat = new int[N, N];
        for (int i = 0; i < N; i++)
            for (int j = 0; j < N; j++)
                mat[i, j] = input.NextInt();

        int res = 0;
        for (int y1 = 0; y1 < N; y1++) {
            for (int x1 = 0; x1 < N; x1++) {
                int c = mat[y1, x1];
                for (int y2 = y1; y2 < N; y2++) {
                    for (int x2 = (y1 == y2 ? x1 + 1 : 0); x2 < N; x2++) {
                        if (mat[y2, x2] != c) continue;

                        int y3 = y2 + (x2 - x1);
                        int x3 = x2 + (y1 - y2);
                        if (y3 < 0 || y3 >= N || x3 < 0 || x3 >= N || mat[y3, x3] != c) continue;

                        int y4 = y1 + (x2 - x1);
                        int x4 = x1 + (y1 - y2);
                        if (y4 < 0 || y4 >= N || x4 < 0 || x4 >= N || mat[y4, x4] != c) continue;

                        res++;
                    }
                }
            }
        }

        Console.WriteLine(res/2);
    }
开发者ID:pandeyiyer,项目名称:acm,代码行数:34,代码来源:192.cs


示例18: AssignmentAndColon

 public void AssignmentAndColon()
 {
     var lexer = new Scanner(":");
     Assert.That(lexer.NextToken(), Is.InstanceOf<TypeDeclaration>());
     lexer = new Scanner(":=");
     Assert.That(lexer.NextToken(), Is.InstanceOf<AssignmentToken>());
 }
开发者ID:Lateks,项目名称:Mini-PL-Interpreter,代码行数:7,代码来源:LexerTest.cs


示例19: Main

        public static void Main(string[] args)
        {
            MemoryStream stream = new MemoryStream();
            String saber = new String('c', 4);
            StreamWriter writer = new StreamWriter(stream);
            writer.Write(@"
GET lol, troll, bla WHERE asdsadas lol test FROM:(bla NOT:lol OR (NOT:lolo OR ""lolol lolol"")) asdasd OR asdasd TO:lala OR (FROM:bla TO:(lol OR (BLA AND NOT:bla)) AND (NOT Lol OR BLA))");
            writer.Flush();

            Scanner scanner = new Scanner(stream);
            Parser parser = new Parser(scanner);
            MemoryStream errorStream = new MemoryStream();
            StreamWriter errorWriter = new StreamWriter(errorStream);

            parser.errors.errorStream = errorWriter;
            parser.Parse();
            errorWriter.Flush();
            errorStream.Seek(0, SeekOrigin.Begin);
            saber = new StreamReader(errorStream).ReadToEnd();
            errorStream.Close();
            stream.Close();
            if (parser.errors.count > 0)
            {
                Console.Out.WriteLine(saber);
            }
            else
            {
                PrintTree(parser.RootTree, 0);
            }
            Console.ReadLine();
        }
开发者ID:yonglehou,项目名称:Bermuda,代码行数:31,代码来源:Input.cs


示例20: Main

 public static void Main(string[] arg)
 {
     Scanner scanner = new Scanner(arg[0]);
     Parser parser = new Parser(scanner);
     parser.Parse();
     Console.Write(parser.errors.count + " errors detected");
 }
开发者ID:ravneetoxyent,项目名称:FortisNICU,代码行数:7,代码来源:Compile.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ScanningFunction类代码示例发布时间:2022-05-24
下一篇:
C# ScanBuff类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap