本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例12: Parser
public Parser(Scanner scanner, ErrorHandler errors)
{
Scanner = scanner;
Errors = errors;
CurrentToken = Scanner.GetNextToken();
}