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


C# Lexer.Scan方法代码示例

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


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

示例1: TestScanComment

        public void TestScanComment()
        {
            var lex = new Lexer.Lexer();
            var reader = new StringReader( "// Comment\n" );

            var t = lex.Scan( reader );

            Assert.AreEqual( typeof (Comment), t.GetType() );
            Assert.AreEqual( " Comment", ( (Comment) t ).Value );
        }
开发者ID:NikoM87,项目名称:Compilers-Alfred-Aho,代码行数:10,代码来源:LexerTest.cs

示例2: TestScanFloatNum

        public void TestScanFloatNum()
        {
            var lex = new Lexer.Lexer();
            var reader = new StringReader( "2. 3.14 .5" );

            var t = lex.Scan( reader );

            Assert.AreEqual( typeof (Float), t.GetType() );
            Assert.AreEqual( 2.0, ( (Float) t ).Value );

            t = lex.Scan( reader );

            Assert.AreEqual( typeof (Float), t.GetType() );
            Assert.AreEqual( 3.14, ( (Float) t ).Value );

            t = lex.Scan( reader );

            Assert.AreEqual( typeof (Float), t.GetType() );
            Assert.AreEqual( 0.5, ( (Float) t ).Value );
        }
开发者ID:NikoM87,项目名称:Compilers-Alfred-Aho,代码行数:20,代码来源:LexerTest.cs

示例3: TestScanCompare

        public void TestScanCompare()
        {
            var lex = new Lexer.Lexer();
            var reader = new StringReader( " < <= == != >= >" );

            var t = lex.Scan( reader );

            Assert.AreEqual( typeof( Word), t.GetType() );
            Assert.AreEqual( Tag.Less, t.Tag );

            t = lex.Scan( reader );

            Assert.AreEqual( typeof( Word ), t.GetType() );
            Assert.AreEqual( Tag.LessOrEqual, t.Tag );

            t = lex.Scan( reader );

            Assert.AreEqual( typeof( Word ), t.GetType() );
            Assert.AreEqual( Tag.Equal, t.Tag );

            t = lex.Scan( reader );

            Assert.AreEqual( typeof( Word ), t.GetType() );
            Assert.AreEqual( Tag.NotEqual, t.Tag );

            t = lex.Scan( reader );

            Assert.AreEqual( typeof( Word ), t.GetType() );
            Assert.AreEqual( Tag.BetterOrEqual, t.Tag );

            t = lex.Scan( reader );

            Assert.AreEqual( typeof( Word ), t.GetType() );
            Assert.AreEqual( Tag.Better, t.Tag );
        }
开发者ID:NikoM87,项目名称:Compilers-Alfred-Aho,代码行数:35,代码来源:LexerTest.cs

示例4: TestScanMultilineComment

        public void TestScanMultilineComment()
        {
            const string textComment = "Comment line 1\n" +
                                       "Comment line 2\n" +
                                       "Comment line *";
            var lex = new Lexer.Lexer();
            var reader = new StringReader( "/*" + textComment + "*/" );

            var t = lex.Scan( reader );

            Assert.AreEqual( typeof( Comment ), t.GetType() );
            Assert.AreEqual( textComment, ( (Comment)t ).Value );
        }
开发者ID:NikoM87,项目名称:Compilers-Alfred-Aho,代码行数:13,代码来源:LexerTest.cs

示例5: TestScanWord

        public void TestScanWord()
        {
            var lex = new Lexer.Lexer();
            var reader = new StringReader( "abc2" );

            var t = lex.Scan( reader );
            Assert.AreEqual( typeof( Word ), t.GetType() );
            Assert.AreEqual( "abc2", ( (Word)t ).Lexeme );
        }
开发者ID:NikoM87,项目名称:Compilers-Alfred-Aho,代码行数:9,代码来源:LexerTest.cs

示例6: TestScanNum

        public void TestScanNum()
        {
            var lex = new Lexer.Lexer();
            var reader = new StringReader( "1234567890" );

            var t = lex.Scan( reader );
            Assert.AreEqual( typeof (Num), t.GetType() );
            Assert.AreEqual( 1234567890, ( (Num) t ).Value );
        }
开发者ID:NikoM87,项目名称:Compilers-Alfred-Aho,代码行数:9,代码来源:LexerTest.cs


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