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


C# Scanner.GetNextToken方法代码示例

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


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

示例1: AnalyzeAssignString_Test

        public void AnalyzeAssignString_Test()
        {
            _testScanner = new Scanner();

            List<Token> expectedList = new List<Token>();
            expectedList.Add(new Token("(", TokenType.LeftParen));
            expectedList.Add(new Token("assign", TokenType.Keyword));
            expectedList.Add(new Token("thisInt", TokenType.Identifier));
            expectedList.Add(new Token("1", TokenType.Integer));
            expectedList.Add(new Token(")", TokenType.RightParen));

            string s = "(assign thisInt 1)";

            List<Token> actualList = new List<Token>();

            while (s.Any())
            {
                var token = _testScanner.GetNextToken(ref s);
                actualList.Add(token);
                _testScanner.RemoveTokenFromBeginning(ref s, token);
            }

            ValidateExpectedVsActualTokens(expectedList, actualList);
        }
开发者ID:koswesley,项目名称:cs480,代码行数:24,代码来源:LexicalAnalyzerTest.cs

示例2: AnalyzeWhileLoopString_Test

        public void AnalyzeWhileLoopString_Test()
        {
            _testScanner = new Scanner();

            List<Token> expectedList = new List<Token>();
            expectedList.Add(new Token("(", TokenType.LeftParen));
            expectedList.Add(new Token("while", TokenType.Keyword));
            expectedList.Add(new Token("thisBool", TokenType.Identifier));
            expectedList.Add(new Token("(", TokenType.LeftParen));
            expectedList.Add(new Token("if", TokenType.Keyword));
            expectedList.Add(new Token("thisBool", TokenType.Identifier));
            expectedList.Add(new Token("false", TokenType.Boolean));
            expectedList.Add(new Token(")", TokenType.RightParen));
            expectedList.Add(new Token(")", TokenType.RightParen));

            string s = "(while thisBool (if thisBool false))";

            List<Token> actualList = new List<Token>();

            while (s.Any())
            {
                var token = _testScanner.GetNextToken(ref s);
                actualList.Add(token);
                _testScanner.RemoveTokenFromBeginning(ref s, token);
            }

            ValidateExpectedVsActualTokens(expectedList, actualList);
        }
开发者ID:koswesley,项目名称:cs480,代码行数:28,代码来源:LexicalAnalyzerTest.cs

示例3: AnalyzeTrueString_Test

        public void AnalyzeTrueString_Test()
        {
            _testScanner = new Scanner();

            Token expected = new Token("\"This is a string\"", TokenType.String);

            string s = "\"This is a string\"";

            Token actual = _testScanner.GetNextToken(ref s);

            Assert.AreEqual(expected.Key, actual.Key);
            Assert.AreEqual(expected.Type, actual.Type);
        }
开发者ID:koswesley,项目名称:cs480,代码行数:13,代码来源:LexicalAnalyzerTest.cs

示例4: AnalyzeTrueReal_Test

        public void AnalyzeTrueReal_Test()
        {
            _testScanner = new Scanner();

            Token expected = new Token("10.0", TokenType.Real);

            string s = "10.0";

            Token actual = _testScanner.GetNextToken(ref s);

            Assert.AreEqual(expected.Key, actual.Key);
            Assert.AreEqual(expected.Type, actual.Type);
        }
开发者ID:koswesley,项目名称:cs480,代码行数:13,代码来源:LexicalAnalyzerTest.cs

示例5: AnalyzeTrueOperator_Test

        public void AnalyzeTrueOperator_Test()
        {
            _testScanner = new Scanner();

            Token expected = new Token("+", TokenType.Operator);

            string s = "+";

            Token actual = _testScanner.GetNextToken(ref s);

            Assert.AreEqual(expected.Key, actual.Key);
            Assert.AreEqual(expected.Type, actual.Type);
        }
开发者ID:koswesley,项目名称:cs480,代码行数:13,代码来源:LexicalAnalyzerTest.cs

示例6: AnalyzeTrueIdentifier_Test

        public void AnalyzeTrueIdentifier_Test()
        {
            _testScanner = new Scanner();

            Token expected = new Token("thisIdentifier", TokenType.Identifier);

            string s = ("thisIdentifier");

            Token actual = _testScanner.GetNextToken(ref s);

            Assert.AreEqual(expected.Key, actual.Key);
            Assert.AreEqual(expected.Type, actual.Type);
        }
开发者ID:koswesley,项目名称:cs480,代码行数:13,代码来源:LexicalAnalyzerTest.cs

示例7: AnalyzeTrueKeyword_Test

        public void AnalyzeTrueKeyword_Test()
        {
            _testScanner = new Scanner();

            Token expected = new Token("int", TokenType.Keyword);

            string s = "int";

            Token actual = _testScanner.GetNextToken(ref s);

            Assert.AreEqual(expected.Key, actual.Key);
            Assert.AreEqual(expected.Type, actual.Type);
        }
开发者ID:koswesley,项目名称:cs480,代码行数:13,代码来源:LexicalAnalyzerTest.cs

示例8: AnalyzeTrueBoolean_Test

        public void AnalyzeTrueBoolean_Test()
        {
            _testScanner = new Scanner();

            Token expected = new Token("true", TokenType.Boolean);

            string s = "true";

            Token actual = _testScanner.GetNextToken(ref s);

            Assert.AreEqual(expected.Key, actual.Key);
            Assert.AreEqual(expected.Type, actual.Type);
        }
开发者ID:koswesley,项目名称:cs480,代码行数:13,代码来源:LexicalAnalyzerTest.cs

示例9: AnalyzePowerString_Test

        public void AnalyzePowerString_Test()
        {
            _testScanner = new Scanner();

            List<Token> expectedList = new List<Token>();
            expectedList.Add(new Token("(", TokenType.LeftParen));
            expectedList.Add(new Token("^", TokenType.Operator));
            expectedList.Add(new Token("1", TokenType.Integer));
            expectedList.Add(new Token("2", TokenType.Integer));
            expectedList.Add(new Token(")", TokenType.RightParen));

            string s = "(^ 1 2)";

            List<Token> actualList = new List<Token>();

            while (s.Any())
            {
                var token = _testScanner.GetNextToken(ref s);
                actualList.Add(token);
                _testScanner.RemoveTokenFromBeginning(ref s, token);
            }

            ValidateExpectedVsActualTokens(expectedList, actualList);
        }
开发者ID:koswesley,项目名称:cs480,代码行数:24,代码来源:LexicalAnalyzerTest.cs

示例10: AnalyzeEscapeQuoteCharacterString_Test

        public void AnalyzeEscapeQuoteCharacterString_Test()
        {
            _testScanner = new Scanner();
            List<Token> expectedTokens = new List<Token>() {
                new Token("(", TokenType.LeftParen),
                new Token("assign", TokenType.Keyword),
                new Token("thisInt", TokenType.Identifier),
                new Token("\"BOS test \\\" string \\\" EOS\"", TokenType.String),
                new Token(")", TokenType.RightParen)
            };

            List<Token> actualTokens = new List<Token>();

            string inputString = "(assign thisInt \"BOS test \\\" string \\\" EOS\")";
            while (inputString.Any()) {
                var token = _testScanner.GetNextToken(ref inputString);
                actualTokens.Add(token);
                _testScanner.RemoveTokenFromBeginning(ref inputString, token);
            }

            ValidateExpectedVsActualTokens(expectedTokens, actualTokens);
        }
开发者ID:koswesley,项目名称:cs480,代码行数:22,代码来源:LexicalAnalyzerTest.cs

示例11: AnalyzeCrazyEscapeCharacterString_Test

        public void AnalyzeCrazyEscapeCharacterString_Test()
        {
            _testScanner = new Scanner();
            List<Token> expectedTokens = new List<Token>() {
                new Token("(", TokenType.LeftParen),
                new Token("assign", TokenType.Keyword),
                new Token("thisVar", TokenType.Identifier),
                new Token("\"This is \\\"suppose\\\" to be \\\"something\\\" \\n ormal.\\; \"", TokenType.String),
                new Token(")", TokenType.RightParen)
            };

            List<Token> actualTokens = new List<Token>();

            string inputString = "(assign thisVar \"This is \\\"suppose\\\" to be \\\"something\\\" \\n ormal.\\; \")";
            while (inputString.Any()) {
                var token = _testScanner.GetNextToken(ref inputString);
                actualTokens.Add(token);
                _testScanner.RemoveTokenFromBeginning(ref inputString, token);
            }

            ValidateExpectedVsActualTokens(expectedTokens, actualTokens);
        }
开发者ID:koswesley,项目名称:cs480,代码行数:22,代码来源:LexicalAnalyzerTest.cs

示例12: Parser

 public Parser(Scanner scanner, ErrorHandler errors)
 {
     Scanner = scanner;
     Errors = errors;
     CurrentToken = Scanner.GetNextToken();
 }
开发者ID:Tuomoz,项目名称:mini-pl-interpreter,代码行数:6,代码来源:Parser.cs


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