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


C# Compiler.TokenStream类代码示例

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


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

示例1: ParseClass

		private static AstNode ParseClass (TokenStream stream)
		{
			stream.Expect (TokenClass.Keyword, "class");
			string name = stream.Expect (TokenClass.Identifier).Value;

			List<string> baseClass = new List<string> ();
			if (stream.Accept (TokenClass.Colon)) {
				do {
					baseClass.Add (ParseClassName (stream));
				} while (stream.Accept (TokenClass.Comma));
			}

			ClassDeclaration clazz = new ClassDeclaration (stream.Location, name, baseClass);

			stream.Expect (TokenClass.OpenBrace);

			while (!stream.Match (TokenClass.CloseBrace)) {
				if (stream.Match (TokenClass.Keyword, "func") || stream.Match (TokenClass.Operator,
					    "@")) {
					FunctionDeclaration func = ParseFunction (stream, false, clazz) as FunctionDeclaration;
					if (func.Name == name) {
						clazz.Constructor = func;
					} else {
						clazz.Add (func);
					}
				} else {
					clazz.Add (ParseStatement (stream));
				}
			}

			stream.Expect (TokenClass.CloseBrace);

			return clazz;
		}
开发者ID:GruntTheDivine,项目名称:Iodine,代码行数:34,代码来源:Parser.cs

示例2: ParseAnd

 public static AstNode ParseAnd(TokenStream stream)
 {
     AstNode expr = ParseEquals (stream);
     while (stream.Accept (TokenClass.Operator, "&")) {
         expr = new BinaryExpression (stream.Location, BinaryOperation.And, expr,
             ParseEquals (stream));
     }
     return expr;
 }
开发者ID:iwatakeshi,项目名称:Iodine,代码行数:9,代码来源:Parser.cs

示例3: Scan

 public TokenStream Scan()
 {
     TokenStream retStream = new TokenStream (errorLog);
     EatWhiteSpaces ();
     while (PeekChar () != -1) {
         Token nextToken = NextToken ();
         if (nextToken != null)
             retStream.AddToken (nextToken);
         EatWhiteSpaces ();
     }
     return retStream;
 }
开发者ID:iwatakeshi,项目名称:Iodine,代码行数:12,代码来源:Tokenizer.cs

示例4: Scan

		public TokenStream Scan ()
		{
			TokenStream retStream = new TokenStream (errorLog);
			EatWhiteSpaces ();
			while (PeekChar () != -1) {
				Token nextToken = NextToken ();
				if (nextToken != null)
					retStream.AddToken (nextToken);
				EatWhiteSpaces ();
			}

			if (errorLog.ErrorCount > 0) {
				throw new SyntaxException (errorLog);
			}

			return retStream;
		}
开发者ID:GruntTheDivine,项目名称:Iodine,代码行数:17,代码来源:Tokenizer.cs

示例5: ParseAdditive

 public static AstNode ParseAdditive(TokenStream stream)
 {
     AstNode expr = ParseMultiplicative (stream);
     while (stream.Match (TokenClass.Operator)) {
         switch (stream.Current.Value) {
         case "+":
             stream.Accept (TokenClass.Operator);
             expr = new BinaryExpression (stream.Location, BinaryOperation.Add, expr,
                 ParseMultiplicative (stream));
             continue;
         case "-":
             stream.Accept (TokenClass.Operator);
             expr = new BinaryExpression (stream.Location, BinaryOperation.Sub, expr,
                 ParseMultiplicative (stream));
             continue;
         default:
             break;
         }
         break;
     }
     return expr;
 }
开发者ID:splitandthechro,项目名称:nginz,代码行数:22,代码来源:Parser.cs

示例6: ParseHash

 private static AstNode ParseHash(TokenStream stream)
 {
     stream.Expect (TokenClass.OpenBrace);
     HashExpression ret = new HashExpression (stream.Location);
     while (!stream.Match (TokenClass.CloseBrace)) {
         ret.Add (ParseExpression (stream));
         stream.Expect (TokenClass.Colon);
         ret.Add (ParseExpression (stream));
         if (!stream.Accept (TokenClass.Comma)) {
             break;
         }
     }
     stream.Expect (TokenClass.CloseBrace);
     return ret;
 }
开发者ID:splitandthechro,项目名称:nginz,代码行数:15,代码来源:Parser.cs

示例7: ParseIf

 private static AstNode ParseIf(TokenStream stream)
 {
     IfStatement ifStmt = new IfStatement (stream.Location);
     stream.Expect (TokenClass.Keyword, "if");
     stream.Expect (TokenClass.OpenParan);
     ifStmt.Add (ParseExpression (stream));
     stream.Expect (TokenClass.CloseParan);
     ifStmt.Add (ParseStatement (stream));
     if (stream.Accept (TokenClass.Keyword, "else")) {
         ifStmt.Add (ParseStatement (stream));
     } else {
         ifStmt.Add (new CodeBlock (stream.Location));
     }
     return ifStmt;
 }
开发者ID:splitandthechro,项目名称:nginz,代码行数:15,代码来源:Parser.cs

示例8: ParseBoolOr

 private static AstNode ParseBoolOr(TokenStream stream)
 {
     AstNode expr = ParseBoolAnd (stream);
     while (stream.Match (TokenClass.Operator)) {
         switch (stream.Current.Value) {
         case "||":
             stream.Accept (TokenClass.Operator);
             expr = new BinaryExpression (stream.Location, BinaryOperation.BoolOr, expr,
                 ParseBoolAnd (stream));
             continue;
         case "??":
             stream.Accept (TokenClass.Operator);
             expr = new BinaryExpression (stream.Location, BinaryOperation.NullCoalescing, expr,
                 ParseBoolAnd (stream));
             continue;
         default:
             break;
         }
         break;
     }
     return expr;
 }
开发者ID:splitandthechro,项目名称:nginz,代码行数:22,代码来源:Parser.cs

示例9: ParseGiven

 private static AstNode ParseGiven(TokenStream stream)
 {
     GivenStatement switchStmt = new GivenStatement (stream.Location);
     stream.Expect (TokenClass.Keyword, "given");
     stream.Expect (TokenClass.OpenParan);
     switchStmt.Add (ParseExpression (stream));
     stream.Expect (TokenClass.CloseParan);
     stream.Expect (TokenClass.OpenBrace);
     AstNode defaultBlock = new AstRoot (stream.Location);
     AstRoot caseStatements = new AstRoot (stream.Location);
     while (!stream.EndOfStream && !stream.Match (TokenClass.CloseBrace)) {
         caseStatements.Add (ParseWhen (stream));
         if (stream.Accept (TokenClass.Keyword, "default")) {
             defaultBlock = ParseStatement (stream);
         }
     }
     switchStmt.Add (caseStatements);
     switchStmt.Add (defaultBlock);
     stream.Expect (TokenClass.CloseBrace);
     return switchStmt;
 }
开发者ID:splitandthechro,项目名称:nginz,代码行数:21,代码来源:Parser.cs

示例10: ParseMatch

 private static AstNode ParseMatch(TokenStream stream)
 {
     MatchExpression expr = new MatchExpression (stream.Location);
     stream.Expect (TokenClass.Keyword, "match");
     expr.Add (ParseExpression (stream));
     stream.Expect (TokenClass.OpenBrace);
     while (stream.Accept (TokenClass.Keyword, "case")) {
         AstNode condition = null;
         AstNode pattern = ParsePattern (stream);
         if (stream.Accept (TokenClass.Keyword, "when")) {
             condition = ParseExpression (stream);
         }
         stream.Expect (TokenClass.Operator, "=>");
         AstNode value = ParseExpression (stream);
         expr.Children.Add (new CaseExpression (pattern.Location, pattern, condition, value));
     }
     stream.Expect (TokenClass.CloseBrace);
     return expr;
 }
开发者ID:splitandthechro,项目名称:nginz,代码行数:19,代码来源:Parser.cs

示例11: ParsePattern

 private static AstNode ParsePattern(TokenStream stream)
 {
     return ParsePatternOr (stream);
 }
开发者ID:splitandthechro,项目名称:nginz,代码行数:4,代码来源:Parser.cs

示例12: ParseForeach

 private static AstNode ParseForeach(TokenStream stream)
 {
     stream.Expect (TokenClass.Keyword, "foreach");
     stream.Expect (TokenClass.OpenParan);
     Token identifier = stream.Expect (TokenClass.Identifier);
     stream.Expect (TokenClass.Keyword, "in");
     AstNode expr = ParseExpression (stream);
     stream.Expect (TokenClass.CloseParan);
     AstNode body = ParseStatement (stream);
     return new ForeachStatement (stream.Location, identifier.Value, expr, body);
 }
开发者ID:splitandthechro,项目名称:nginz,代码行数:11,代码来源:Parser.cs

示例13: ParseLambda

        private static AstNode ParseLambda(TokenStream stream)
        {
            stream.Expect (TokenClass.Keyword, "lambda");
            bool isInstanceMethod;
            bool isVariadic;
            bool acceptsKwargs;

            List<string> parameters = ParseFuncParameters (stream,
                out isInstanceMethod,
                out isVariadic,
                out acceptsKwargs);

            LambdaExpression decl = new LambdaExpression (stream.Location, isInstanceMethod, isVariadic, acceptsKwargs, parameters);
            if (stream.Accept (TokenClass.Operator, "=>"))
                decl.Add (new ReturnStatement (stream.Location, ParseExpression (stream)));
            else
                decl.Add (ParseStatement (stream));
            return decl;
        }
开发者ID:splitandthechro,项目名称:nginz,代码行数:19,代码来源:Parser.cs

示例14: ParseExpression

 private static AstNode ParseExpression(TokenStream stream)
 {
     return ParseAssign (stream);
 }
开发者ID:splitandthechro,项目名称:nginz,代码行数:4,代码来源:Parser.cs

示例15: ParseFor

 private static AstNode ParseFor(TokenStream stream)
 {
     ForStatement ret = new ForStatement (stream.Location);
     stream.Expect (TokenClass.Keyword, "for");
     stream.Expect (TokenClass.OpenParan);
     ret.Add (new Expression (stream.Location, ParseExpression (stream)));
     stream.Expect (TokenClass.SemiColon);
     ret.Add (ParseExpression (stream));
     stream.Expect (TokenClass.SemiColon);
     ret.Add (new Expression (stream.Location, ParseExpression (stream)));
     stream.Expect (TokenClass.CloseParan);
     ret.Add (ParseStatement (stream));
     return ret;
 }
开发者ID:splitandthechro,项目名称:nginz,代码行数:14,代码来源:Parser.cs


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