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


C# Scanner.NextToken方法代码示例

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


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

示例1: 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

示例2: 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

示例3: DivisionSymbolIsNotConfusedWithAComment

 public void DivisionSymbolIsNotConfusedWithAComment()
 {
     var lexer = new Scanner("/");
     Assert.That(lexer.NextToken(), Is.InstanceOf<BinaryOperator>());
     lexer = new Scanner("// .. / ..\n /");
     Assert.That(((BinaryOperator) lexer.NextToken()).Value, Is.EqualTo("/"));
     Assert.That(lexer.Col, Is.EqualTo(2));
     Assert.That(lexer.Row, Is.EqualTo(2));
 }
开发者ID:Lateks,项目名称:Mini-PL-Interpreter,代码行数:9,代码来源:LexerTest.cs

示例4: CommentsAreSkipped

 public void CommentsAreSkipped()
 {
     var lexer = new Scanner("// ... \n // ... \n foo");
     var token = (Identifier) lexer.NextToken();
     Assert.That(token.Value, Is.EqualTo("foo"));
     Assert.That(token.Row, Is.EqualTo(3));
     Assert.That(token.Col, Is.EqualTo(4));
     lexer = new Scanner("/* ... \n\n*/ \tfoo");
     token = (Identifier) lexer.NextToken();
     Assert.That(token.Value, Is.EqualTo("foo"));
     Assert.That(token.Row, Is.EqualTo(3));
     Assert.That(token.Col, Is.EqualTo(7));
     lexer = new Scanner("\n\n// ...//\n// ... \n\n/* ... */ foo");
     Assert.That(((Identifier) lexer.NextToken()).Value, Is.EqualTo("foo"));
 }
开发者ID:Lateks,项目名称:Mini-PL-Interpreter,代码行数:15,代码来源:LexerTest.cs

示例5: Identifiers

 public void Identifiers()
 {
     var lexer = new Scanner("42foo");
     Assert.That(((IntegerLiteralToken) lexer.NextToken()).Value, Is.EqualTo("42"));
     Token next = lexer.NextToken();
     Assert.That(next, Is.InstanceOf<Identifier>());
     Assert.That(((Identifier) next).Value, Is.EqualTo("foo"));
     lexer = new Scanner("f_o12a");
     Assert.That(((Identifier) lexer.NextToken()).Value, Is.EqualTo("f_o12a"));
 }
开发者ID:Lateks,项目名称:Mini-PL-Interpreter,代码行数:10,代码来源:LexerTest.cs

示例6: DoubleDots

 public void DoubleDots()
 {
     var lexer = new Scanner("..");
     Assert.That(lexer.NextToken(), Is.InstanceOf<RangeOperator>());
     lexer = new Scanner(".");
     Assert.Throws<LexicalError>(() => lexer.NextToken());
     Assert.That(lexer.Col, Is.EqualTo(1));
 }
开发者ID:Lateks,项目名称:Mini-PL-Interpreter,代码行数:8,代码来源:LexerTest.cs

示例7: CombinedWhiteSpaceAndComments

 public void CombinedWhiteSpaceAndComments()
 {
     var lexer = new Scanner("\n\t\t// ... \n // ... \n     foo");
     Assert.That(((Identifier) lexer.NextToken()).Value, Is.EqualTo("foo"));
 }
开发者ID:Lateks,项目名称:Mini-PL-Interpreter,代码行数:5,代码来源:LexerTest.cs

示例8: UnaryNot

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

示例9: WhiteSpaceIsSkipped

 public void WhiteSpaceIsSkipped()
 {
     var lexer = new Scanner("\n\t\v\n  foo");
     Assert.That(((Identifier) lexer.NextToken()).Value, Is.EqualTo("foo"));
 }
开发者ID:Lateks,项目名称:Mini-PL-Interpreter,代码行数:5,代码来源:LexerTest.cs

示例10: BinaryOperators

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

示例11: StringLiterals

 public void StringLiterals()
 {
     var lexer = new Scanner("\"foo 42\"");
     Assert.That(((StringLiteralToken) lexer.NextToken()).Value, Is.EqualTo("foo 42"));
     Assert.That(lexer.NextToken(), Is.InstanceOf<EOF>());
     lexer = new Scanner("\"foo\\n\"");
     Assert.That(((StringLiteralToken) lexer.NextToken()).Value, Is.EqualTo("foo\n"));
     lexer = new Scanner("\"foo\\\"...\\\"\"");
     Assert.That(((StringLiteralToken) lexer.NextToken()).Value, Is.EqualTo("foo\"...\""));
     lexer = new Scanner("\"foo\\\"");
     Assert.Throws<LexicalError>(() => lexer.NextToken());
     lexer = new Scanner("\"foo\\");
     Assert.Throws<LexicalError>(() => lexer.NextToken());
 }
开发者ID:Lateks,项目名称:Mini-PL-Interpreter,代码行数:14,代码来源:LexerTest.cs

示例12: Statement

 public void Statement()
 {
     var lexer = new Scanner("var x : int := 4 + (2 * \"foo\");");
     Assert.That(((KeywordToken) lexer.NextToken()).Value, Is.EqualTo("var"));
     Assert.That(((Identifier) lexer.NextToken()).Value, Is.EqualTo("x"));
     Assert.That(lexer.NextToken(), Is.InstanceOf<TypeDeclaration>());
     Assert.That(((KeywordToken) lexer.NextToken()).Value, Is.EqualTo("int"));
     Assert.That(lexer.NextToken(), Is.InstanceOf<AssignmentToken>());
     Assert.That(((IntegerLiteralToken) lexer.NextToken()).Value, Is.EqualTo("4"));
     Assert.That(((BinaryOperator) lexer.NextToken()).Value, Is.EqualTo("+"));
     Assert.That(lexer.NextToken(), Is.InstanceOf<LeftParenthesis>());
     Assert.That(((IntegerLiteralToken) lexer.NextToken()).Value, Is.EqualTo("2"));
     Assert.That(((BinaryOperator) lexer.NextToken()).Value, Is.EqualTo("*"));
     Assert.That(((StringLiteralToken) lexer.NextToken()).Value, Is.EqualTo("foo"));
     Assert.That(lexer.NextToken(), Is.InstanceOf<RightParenthesis>());
     Assert.That(lexer.NextToken(), Is.InstanceOf<EndLine>());
 }
开发者ID:Lateks,项目名称:Mini-PL-Interpreter,代码行数:17,代码来源:LexerTest.cs

示例13: ShouldBeInvalid

 public void ShouldBeInvalid()
 {
     var lexer = new Scanner("$");
     Assert.Throws<LexicalError>(() => lexer.NextToken());
     Assert.That(lexer.Col, Is.EqualTo(1));
 }
开发者ID:Lateks,项目名称:Mini-PL-Interpreter,代码行数:6,代码来源:LexerTest.cs

示例14: IntegerConstants

 public void IntegerConstants()
 {
     var lexer = new Scanner("123");
     Assert.That(((IntegerLiteralToken) lexer.NextToken()).Value, Is.EqualTo("123"));
     Assert.That(lexer.NextToken(), Is.InstanceOf<EOF>());
     lexer = new Scanner("1 23");
     var token = (IntegerLiteralToken) lexer.NextToken();
     Assert.That(token.Value, Is.EqualTo("1"));
     Assert.That(token.Row, Is.EqualTo(1));
     Assert.That(token.Col, Is.EqualTo(1));
     Assert.That(((IntegerLiteralToken) lexer.NextToken()).Value, Is.EqualTo("23"));
 }
开发者ID:Lateks,项目名称:Mini-PL-Interpreter,代码行数:12,代码来源:LexerTest.cs

示例15: InputConsistingOfWhitespaceOnly

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


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