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


C# TokenStream.Match方法代码示例

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


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

        private static AstNode ParseBlock(TokenStream stream)
        {
            CodeBlock ret = new CodeBlock (stream.Location);
            stream.Expect (TokenClass.OpenBrace);

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

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

示例4: ParseMulDivMod

 public static AstNode ParseMulDivMod(TokenStream stream)
 {
     AstNode expr = ParseUnary (stream);
     while (stream.Match (TokenClass.Operator)) {
         switch (stream.Current.Value) {
         case "*":
             stream.Accept (TokenClass.Operator);
             expr = new BinaryExpression (stream.Location, BinaryOperation.Mul, expr,
                 ParseUnary (stream));
             continue;
         case "/":
             stream.Accept (TokenClass.Operator);
             expr = new BinaryExpression (stream.Location, BinaryOperation.Div, expr,
                 ParseUnary (stream));
             continue;
         case "%":
             stream.Accept (TokenClass.Operator);
             expr = new BinaryExpression (stream.Location, BinaryOperation.Mod, expr,
                 ParseUnary (stream));
             continue;
         default:
             break;
         }
         break;
     }
     return expr;
 }
开发者ID:iwatakeshi,项目名称:Iodine,代码行数:27,代码来源:Parser.cs

示例5: ParseModuleName

        private static string ParseModuleName(TokenStream stream)
        {
            Token initIdent = stream.Expect (TokenClass.Identifier);

            if (stream.Match (TokenClass.Operator, ".")) {
                StringBuilder accum = new StringBuilder ();
                accum.Append (initIdent.Value);
                while (stream.Accept (TokenClass.Operator, ".")) {
                    Token ident = stream.Expect (TokenClass.Identifier);
                    accum.Append (Path.DirectorySeparatorChar);
                    accum.Append (ident.Value);
                }
                return accum.ToString ();

            } else {
                return initIdent.Value;
            }
        }
开发者ID:splitandthechro,项目名称:nginz,代码行数:18,代码来源:Parser.cs

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

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

示例8: ParseEnum

        private static AstNode ParseEnum(TokenStream stream)
        {
            stream.Expect (TokenClass.Keyword, "enum");
            string name = stream.Expect (TokenClass.Identifier).Value;
            EnumDeclaration decl = new EnumDeclaration (stream.Location, name);

            stream.Expect (TokenClass.OpenBrace);
            int defaultVal = -1;

            while (!stream.Match (TokenClass.CloseBrace)) {
                string ident = stream.Expect (TokenClass.Identifier).Value;
                if (stream.Accept (TokenClass.Operator, "=")) {
                    string val = stream.Expect (TokenClass.IntLiteral).Value;
                    int numVal = 0;
                    if (val != "") {
                        numVal = Int32.Parse (val);
                    }
                    decl.Items [ident] = numVal;
                } else {
                    decl.Items [ident] = defaultVal--;
                }
                if (!stream.Accept (TokenClass.Comma)) {
                    break;
                }
            }

            stream.Expect (TokenClass.CloseBrace);

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

示例9: ParseUse

        private static UseStatement ParseUse(TokenStream stream)
        {
            stream.Expect (TokenClass.Keyword, "use");
            bool relative = stream.Accept (TokenClass.Operator, ".");
            string ident = "";
            if (!stream.Match (TokenClass.Operator, "*"))
                ident = ParseModuleName (stream);
            if (stream.Match (TokenClass.Keyword, "from") || stream.Match (TokenClass.Comma) ||
                stream.Match (TokenClass.Operator, "*")) {
                List<string> items = new List<string> ();
                bool wildcard = false;
                if (!stream.Accept (TokenClass.Operator, "*")) {
                    items.Add (ident);
                    stream.Accept (TokenClass.Comma);
                    while (!stream.Match (TokenClass.Keyword, "from")) {
                        Token item = stream.Expect (TokenClass.Identifier);
                        items.Add (item.Value);
                        if (!stream.Accept (TokenClass.Comma)) {
                            break;
                        }
                    }
                } else {
                    wildcard = true;
                }
                stream.Expect (TokenClass.Keyword, "from");

                relative = stream.Accept (TokenClass.Operator, ".");
                string module = ParseModuleName (stream);
                return new UseStatement (stream.Location, module, items, wildcard, relative);
            }
            return new UseStatement (stream.Location, ident, relative);
        }
开发者ID:splitandthechro,项目名称:nginz,代码行数:32,代码来源:Parser.cs

示例10: ParseTypeList

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

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

示例12: ParseStatement

 private static AstNode ParseStatement(TokenStream stream)
 {
     if (stream.Match (TokenClass.Keyword)) {
         switch (stream.Current.Value) {
         case "class":
             return ParseClass (stream);
         case "enum":
             return ParseEnum (stream);
         case "interface":
             return ParseInterface (stream);
         case "func":
             return ParseFunction (stream);
         case "if":
             return ParseIf (stream);
         case "given":
             return ParseGiven (stream);
         case "for":
             return ParseFor (stream);
         case "foreach":
             return ParseForeach (stream);
         case "with":
             return ParseWith (stream);
         case "while":
             return ParseWhile (stream);
         case "do":
             return ParseDoWhile (stream);
         case "use":
             return ParseUse (stream);
         case "return":
             return ParseReturn (stream);
         case "raise":
             return ParseRaise (stream);
         case "yield":
             return ParseYield (stream);
         case "try":
             return ParseTryExcept (stream);
         case "break":
             stream.Accept (TokenClass.Keyword);
             return new BreakStatement (stream.Location);
         case "continue":
             stream.Accept (TokenClass.Keyword);
             return new ContinueStatement (stream.Location);
         case "super":
             stream.ErrorLog.AddError (ErrorType.ParserError, stream.Location,
                 "super () constructor must be called first!");
             return ParseSuperCall (stream, new ClassDeclaration (stream.Location, "", null));
         }
     }
     if (stream.Match (TokenClass.OpenBrace)) {
         return ParseBlock (stream);
     } else if (stream.Accept (TokenClass.SemiColon)) {
         return new Statement (stream.Location);
     } else if (stream.Match (TokenClass.Operator, "@")) {
         return ParseFunction (stream);
     } else {
         AstNode node = ParseExpression (stream);
         if (node == null) {
             stream.MakeError ();
         }
         return new Expression (stream.Location, node);
     }
 }
开发者ID:splitandthechro,项目名称:nginz,代码行数:62,代码来源:Parser.cs

示例13: ParseRange

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

示例14: ParseBitshift

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

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


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