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


C# TokenStream.Accept方法代码示例

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


在下文中一共展示了TokenStream.Accept方法的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: 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

示例3: ParseUnary

        public static AstNode ParseUnary(TokenStream stream)
        {
            if (stream.Match (TokenClass.Operator)) {
                switch (stream.Current.Value) {
                case "-":
                    stream.Accept (TokenClass.Operator);
                    return new UnaryExpression (stream.Location, UnaryOperation.Negate, ParseUnary (
                        stream));
                case "~":
                    stream.Accept (TokenClass.Operator);
                    return new UnaryExpression (stream.Location, UnaryOperation.Not, ParseUnary (
                        stream));
                case "!":
                    stream.Accept (TokenClass.Operator);
                    return new UnaryExpression (stream.Location, UnaryOperation.BoolNot, ParseUnary (
                        stream));

                }
            }
            return ParseCallSubscriptAccess (stream);
        }
开发者ID:splitandthechro,项目名称:nginz,代码行数:21,代码来源:Parser.cs

示例4: ParseTuple

 private static AstNode ParseTuple(AstNode firstVal, TokenStream stream)
 {
     TupleExpression tuple = new TupleExpression (stream.Location);
     tuple.Add (firstVal);
     while (!stream.Match (TokenClass.CloseParan)) {
         tuple.Add (ParseExpression (stream));
         if (!stream.Accept (TokenClass.Comma)) {
             break;
         }
     }
     stream.Expect (TokenClass.CloseParan);
     return tuple;
 }
开发者ID:splitandthechro,项目名称:nginz,代码行数:13,代码来源:Parser.cs

示例5: ParseFuncParameters

        private static List<string> ParseFuncParameters(TokenStream stream,
			out bool isInstanceMethod,
			out bool isVariadic,
			out bool hasKeywordArgs)
        {
            isVariadic = false;
            hasKeywordArgs = false;
            isInstanceMethod = false;
            List<string> ret = new List<string> ();
            stream.Expect (TokenClass.OpenParan);
            if (stream.Accept (TokenClass.Keyword, "self")) {
                isInstanceMethod = true;
                if (!stream.Accept (TokenClass.Comma)) {
                    stream.Expect (TokenClass.CloseParan);
                    return ret;
                }
            }
            while (!stream.Match (TokenClass.CloseParan)) {
                if (!hasKeywordArgs && stream.Accept (TokenClass.Operator, "*")) {
                    if (stream.Accept (TokenClass.Operator, "*")) {
                        hasKeywordArgs = true;
                        Token ident = stream.Expect (TokenClass.Identifier);
                        ret.Add (ident.Value);
                    } else {
                        isVariadic = true;
                        Token ident = stream.Expect (TokenClass.Identifier);
                        ret.Add (ident.Value);
                    }
                } else {
                    if (hasKeywordArgs) {
                        stream.ErrorLog.AddError (ErrorType.ParserError, stream.Location,
                            "Argument after keyword arguments!");
                    }
                    if (isVariadic) {
                        stream.ErrorLog.AddError (ErrorType.ParserError, stream.Location,
                            "Argument after params keyword!");
                    }
                    Token param = stream.Expect (TokenClass.Identifier);
                    ret.Add (param.Value);
                }
                if (!stream.Accept (TokenClass.Comma)) {
                    break;
                }
            }
            stream.Expect (TokenClass.CloseParan);
            return ret;
        }
开发者ID:splitandthechro,项目名称:nginz,代码行数:47,代码来源:Parser.cs

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

示例7: ParsePatternOr

 private static AstNode ParsePatternOr(TokenStream stream)
 {
     AstNode expr = ParsePatternAnd (stream);
     while (stream.Match (TokenClass.Operator, "|")) {
         stream.Accept (TokenClass.Operator);
         expr = new BinaryExpression (stream.Location, BinaryOperation.Or, expr,
             ParsePatternAnd (stream));
     }
     return expr;
 }
开发者ID:splitandthechro,项目名称:nginz,代码行数:10,代码来源:Parser.cs

示例8: ParseInterface

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

            InterfaceDeclaration contract = new InterfaceDeclaration (stream.Location, name);

            stream.Expect (TokenClass.OpenBrace);

            while (!stream.Match (TokenClass.CloseBrace)) {
                if (stream.Match (TokenClass.Keyword, "func")) {
                    FunctionDeclaration func = ParseFunction (stream, true) as FunctionDeclaration;
                    contract.Add (func);
                } else {
                    stream.ErrorLog.AddError (ErrorType.ParserError, stream.Location,
                        "Interface may only contain function prototypes!");
                }
                while (stream.Accept (TokenClass.SemiColon));
            }

            stream.Expect (TokenClass.CloseBrace);

            return contract;
        }
开发者ID:splitandthechro,项目名称:nginz,代码行数:24,代码来源:Parser.cs

示例9: 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:splitandthechro,项目名称:nginz,代码行数:9,代码来源:Parser.cs

示例10: ParseFunction

        private static AstNode ParseFunction(TokenStream stream, bool prototype = false,
			ClassDeclaration cdecl = null)
        {
            if (stream.Accept (TokenClass.Operator, "@")) {
                /*
                 * Function decorators in the form of
                 * @myDecorator
                 * func foo () {
                 * }
                 * are merely syntatic sugar for
                 * func foo () {
                 * }
                 * foo = myDecorator (foo)
                 */
                AstNode expr = ParseExpression (stream); // Decorator expression
                /* This is the original function which is to be decorated */
                FunctionDeclaration idecl = ParseFunction (stream, prototype, cdecl) as FunctionDeclaration;
                /* We must construct an arglist which will be passed to the decorator */
                ArgumentList args = new ArgumentList (stream.Location);
                args.Add (new NameExpression (stream.Location, idecl.Name));
                /*
                 * Since two values can not be returned, we must return a single node containing both
                 * the function declaration and call to the decorator
                 */
                AstRoot nodes = new AstRoot (stream.Location);
                nodes.Add (idecl);
                nodes.Add (new Expression (stream.Location, new BinaryExpression (stream.Location,
                    BinaryOperation.Assign,
                    new NameExpression (stream.Location, idecl.Name),
                    new CallExpression (stream.Location, expr, args))));
                return nodes;
            }
            stream.Expect (TokenClass.Keyword, "func");
            bool isInstanceMethod;
            bool isVariadic;
            bool hasKeywordArgs;
            Token ident = stream.Expect (TokenClass.Identifier);
            List<string> parameters = ParseFuncParameters (stream,
                out isInstanceMethod,
                out isVariadic,
                out hasKeywordArgs);

            FunctionDeclaration decl = new FunctionDeclaration (stream.Location, ident != null ?
                ident.Value : "",
                isInstanceMethod,
                isVariadic,
                hasKeywordArgs,
                parameters);

            if (!prototype) {

                if (stream.Accept (TokenClass.Operator, "=>")) {
                    decl.Add (new ReturnStatement (stream.Location, ParseExpression (stream)));
                } else {
                    stream.Expect (TokenClass.OpenBrace);
                    CodeBlock scope = new CodeBlock (stream.Location);

                    if (stream.Match (TokenClass.Keyword, "super")) {
                        scope.Add (ParseSuperCall (stream, cdecl));
                    }

                    while (!stream.Match (TokenClass.CloseBrace)) {
                        scope.Add (ParseStatement (stream));
                    }

                    decl.Add (scope);
                    stream.Expect (TokenClass.CloseBrace);
                }
            }
            return decl;
        }
开发者ID:splitandthechro,项目名称:nginz,代码行数:71,代码来源:Parser.cs

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

示例12: ParseSuperCall

 public static SuperCallExpression ParseSuperCall(TokenStream stream, ClassDeclaration parent)
 {
     SuperCallExpression ret = new SuperCallExpression (stream.Location);
     stream.Expect (TokenClass.Keyword, "super");
     ret.Parent = parent;
     ret.Add (ParseArgumentList (stream));
     while (stream.Accept (TokenClass.SemiColon))
         ;
     return ret;
 }
开发者ID:splitandthechro,项目名称:nginz,代码行数:10,代码来源:Parser.cs

示例13: ParseTerm

        public static AstNode ParseTerm(TokenStream stream)
        {
            switch (stream.Current.Class) {
            case TokenClass.Identifier:
                return new NameExpression (stream.Location, stream.ReadToken ().Value);
            case TokenClass.IntLiteral:
                return new IntegerExpression (stream.Location, long.Parse (
                    stream.ReadToken ().Value));
            case TokenClass.FloatLiteral:
                return new FloatExpression (stream.Location, double.Parse (
                    stream.ReadToken ().Value));
            case TokenClass.InterpolatedStringLiteral:
                AstNode val = ParseString (stream.Location, stream.ReadToken ().Value);
                if (val == null) {
                    stream.MakeError ();
                    return new StringExpression (stream.Location, "");
                }
                return val;
            case TokenClass.StringLiteral:
                return new StringExpression (stream.Location, stream.ReadToken ().Value);
            case TokenClass.OpenBracket:
                return ParseList (stream);
            case TokenClass.OpenBrace:
                return ParseHash (stream);
            case TokenClass.OpenParan:
                stream.ReadToken ();
                AstNode expr = ParseExpression (stream);
                if (stream.Accept (TokenClass.Comma)) {
                    return ParseTuple (expr, stream);
                }
                stream.Expect (TokenClass.CloseParan);
                return expr;
            case TokenClass.Keyword:
                switch (stream.Current.Value) {
                case "self":
                    stream.ReadToken ();
                    return new SelfStatement (stream.Location);
                case "true":
                    stream.ReadToken ();
                    return new TrueExpression (stream.Location);
                case "false":
                    stream.ReadToken ();
                    return new FalseExpression (stream.Location);
                case "null":
                    stream.ReadToken ();
                    return new NullExpression (stream.Location);
                case "lambda":
                    return ParseLambda (stream);
                case "match":
                    return ParseMatch (stream);
                }
                break;
            }

            stream.MakeError ();
            return null;
        }
开发者ID:splitandthechro,项目名称:nginz,代码行数:57,代码来源:Parser.cs

示例14: ParseRelationalOp

 public static AstNode ParseRelationalOp(TokenStream stream)
 {
     AstNode expr = ParseBitshift (stream);
     while (stream.Match (TokenClass.Operator)) {
         switch (stream.Current.Value) {
         case ">":
             stream.Accept (TokenClass.Operator);
             expr = new BinaryExpression (stream.Location, BinaryOperation.GreaterThan, expr,
                 ParseBitshift (stream));
             continue;
         case "<":
             stream.Accept (TokenClass.Operator);
             expr = new BinaryExpression (stream.Location, BinaryOperation.LessThan, expr,
                 ParseBitshift (stream));
             continue;
         case ">=":
             stream.Accept (TokenClass.Operator);
             expr = new BinaryExpression (stream.Location, BinaryOperation.GreaterThanOrEqu, expr,
                 ParseBitshift (stream));
             continue;
         case "<=":
             stream.Accept (TokenClass.Operator);
             expr = new BinaryExpression (stream.Location, BinaryOperation.LessThanOrEqu, expr,
                 ParseBitshift (stream));
             continue;
         case "is":
             stream.Accept (TokenClass.Operator);
             expr = new BinaryExpression (stream.Location, BinaryOperation.InstanceOf, expr,
                 ParseBitshift (stream));
             continue;
         case "isnot":
             stream.Accept (TokenClass.Operator);
             expr = new BinaryExpression (stream.Location, BinaryOperation.NotInstanceOf, expr,
                 ParseBitshift (stream));
             continue;
         case "as":
             stream.Accept (TokenClass.Operator);
             expr = new BinaryExpression (stream.Location, BinaryOperation.DynamicCast, expr,
                 ParseBitshift (stream));
             continue;
         default:
             break;
         }
         break;
     }
     return expr;
 }
开发者ID:splitandthechro,项目名称:nginz,代码行数:47,代码来源:Parser.cs

示例15: ParseOr

 public static AstNode ParseOr(TokenStream stream)
 {
     AstNode expr = ParseXor (stream);
     while (stream.Accept (TokenClass.Operator, "|")) {
         expr = new BinaryExpression (stream.Location, BinaryOperation.Or, expr, ParseXor (stream));
     }
     return expr;
 }
开发者ID:splitandthechro,项目名称:nginz,代码行数:8,代码来源:Parser.cs


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