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


C# TokenStream.MakeError方法代码示例

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


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

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

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


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