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


C# TokenStream.PeekValue方法代码示例

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


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

示例1: ParseImport

		private Executable ParseImport(TokenStream tokens, int indention)
		{
			tokens.SkipWhitespace();

			List<Token> fromChain = null;
			List<Token> importChain = null;
			List<Token> asChain = null;
			Token firstToken = null;

			if (tokens.PeekValue() == "from")
			{
				firstToken = tokens.Pop();
				fromChain = ParseDotChainForImport(tokens);
			}

			firstToken = firstToken ?? tokens.PopExpected("import");
			importChain = ParseDotChainForImport(tokens);

			if (tokens.PopIfPresent("as"))
			{
				asChain = ParseDotChainForImport(tokens);
				if (asChain.Count > 1) throw new ParserException(asChain[0], "Expected: variable");
			}

			return new ImportStatement(firstToken, importChain, fromChain, asChain == null ? null : asChain[0]);
		}
开发者ID:blakeohare,项目名称:crython,代码行数:26,代码来源:ExecutableParser.cs

示例2: ParseBitwiseAnd

 public static Expression ParseBitwiseAnd(TokenStream tokens)
 {
     Expression left = ParseBitshift(tokens);
     string next = tokens.PeekValue();
     if (next == "^")
     {
         List<Expression> expressions = new List<Expression>() { left };
         List<Token> ops = new List<Token>();
         while (next == "^")
         {
             ops.Add(tokens.Pop());
             expressions.Add(ParseBitshift(tokens));
             next = tokens.PeekValue();
         }
         return new BinaryOpChain(expressions, ops);
     }
     return left;
 }
开发者ID:blakeohare,项目名称:pyweek-sentientstorage,代码行数:18,代码来源:ExpressionParser.cs

示例3: ParseBitshift

 public static Expression ParseBitshift(TokenStream tokens)
 {
     Expression left = ParseAddition(tokens);
     string next = tokens.PeekValue();
     if (BITSHIFT_OPERATORS.Contains(next))
     {
         List<Expression> expressions = new List<Expression>() { left };
         List<Token> ops = new List<Token>();
         while (BITSHIFT_OPERATORS.Contains(next))
         {
             ops.Add(tokens.Pop());
             expressions.Add(ParseAddition(tokens));
             next = tokens.PeekValue();
         }
         return new BinaryOpChain(expressions, ops);
     }
     return left;
 }
开发者ID:blakeohare,项目名称:pyweek-sentientstorage,代码行数:18,代码来源:ExpressionParser.cs

示例4: Parse

		public Executable Parse(TokenStream tokens, bool nestedIndentAllowed, int indention)
		{
			string next = tokens.PeekValue();

			if (nestedIndentAllowed)
			{
				switch (next)
				{
					case "def": return ParseDef(tokens, indention);
					case "class": return ParseClass(tokens, indention);
					case "if": return ParseIfLikeThing(tokens, indention);
					case "elif": return ParseIfLikeThing(tokens, indention);
					case "else": return ParseIfLikeThing(tokens, indention);
					case "for": return ParseIfLikeThing(tokens, indention);
					case "while": return ParseIfLikeThing(tokens, indention);
					default: break;
				}
			}
			switch (next)
			{
				case "break": return ParseAtomicItem(tokens, indention);
				case "continue": return ParseAtomicItem(tokens, indention);
				case "pass": return ParseAtomicItem(tokens, indention);
				case "return": return ParseReturn(tokens, indention);
				case "import": return ParseImport(tokens, indention);
				case "from": return ParseImport(tokens, indention);
				default: break;
			}


			Expression expression = ExpressionParser.Parse(tokens);

			next = tokens.PeekValue();
			if (ASSIGNMENT_OPS.Contains(next))
			{
				Token assignmentToken = tokens.Pop();
				Expression assignmentValue = ExpressionParser.Parse(tokens);
				return new Assignment(expression, assignmentToken, assignmentValue);
			}

			return new ExpressionAsExecutable(expression);
		}
开发者ID:blakeohare,项目名称:crython,代码行数:42,代码来源:ExecutableParser.cs

示例5: ParseRootEntity

        private static Expression ParseRootEntity(TokenStream tokens)
        {
            tokens.SkipWhitespace();
            string next = tokens.PeekValue();
            if (next == "True" || next == "False")
            {
                Token token = tokens.Pop();
                return new BooleanConstant(token, next == "True");
            }
            else if (next == "None")
            {
                Token token = tokens.Pop();
                return new NullConstant(token);
            }
            else if (next.StartsWith("'") || next.StartsWith("\""))
            {
                Token token = tokens.Pop();
                int quoteSize = next.StartsWith("'''") || next.StartsWith("\"\"\"") ? 3 : 1;
                return new StringConstant(token, Util.RemoveEscapeSequences(token, next.Substring(quoteSize, next.Length - quoteSize * 2)));
            }
            else if (next.StartsWith("r'") || next.StartsWith("r\""))
            {
                Token token = tokens.Pop();
                int quoteSize = next.StartsWith("r'''") || next.StartsWith("r\"\"\"") ? 3 : 1;

                return new StringConstant(token, next.Substring(quoteSize + 1, next.Length - quoteSize * 2 - 1));
            }
            else if (next == "(")
            {
                // Tuples or parentehsis
                Token parenthesisToken = tokens.Pop();
                List<Expression> parenthesisExpressions = new List<Expression>();
                bool nextAllowed = true;
                while (!tokens.PopIfPresent(")"))
                {
                    if (!nextAllowed) tokens.PopExpected(")"); // throws
                    parenthesisExpressions.Add(Parse(tokens));
                    nextAllowed = tokens.PopIfPresent(",");
                    tokens.SkipWhitespace();
                }

                if (parenthesisExpressions.Count > 1 || nextAllowed)
                {
                    return new InlineTuple(parenthesisToken, parenthesisExpressions);
                }
                else
                {
                    return new ParenthesisGroup(parenthesisToken, parenthesisExpressions[0]);
                }
            }
            else if (next == "[")
            {
                Token bracketToken = tokens.Pop();
                List<Expression> listItems = new List<Expression>();
                bool nextAllowed = true;
                while (!tokens.PopIfPresent("]"))
                {
                    if (!nextAllowed) tokens.PopExpected("]"); // throws
                    listItems.Add(Parse(tokens));
                    nextAllowed = tokens.PopIfPresent(",");
                    tokens.SkipWhitespace();
                }
                return new InlineList(bracketToken, listItems);
            }
            else if (next == "{")
            {
                Token braceToken = tokens.Pop();
                List<Expression> dictionaryKeys = new List<Expression>();
                List<Expression> dictionaryValues = new List<Expression>();
                bool nextAllowed = true;
                while (!tokens.PopIfPresent("}"))
                {
                    if (!nextAllowed) tokens.PopExpected("}"); // throws
                    dictionaryKeys.Add(Parse(tokens));
                    tokens.PopExpected(":");
                    dictionaryValues.Add(Parse(tokens));
                    nextAllowed = tokens.PopIfPresent(",");
                    tokens.SkipWhitespace();
                }
                return new InlineDictionary(braceToken, dictionaryKeys, dictionaryValues);
            }
            else if (next.StartsWith("0x") || next.StartsWith("0o") || next.StartsWith("0X") || next.StartsWith("0O"))
            {
                Token integerToken = tokens.Pop();
                int radix = next.ToLowerInvariant().StartsWith("0x") ? 16 : 8;
                string stringValue = next.Substring(2);
                if (stringValue.Length == 0)
                {
                    throw new ParserException(integerToken, "Invalid base " + radix + " constant.");
                }
                int value = Util.ParseNumber(integerToken, stringValue, radix);
                return new IntegerConstant(integerToken, value);
            }
            else if (next[0] >= '0' && next[0] <= '9')
            {
                Token numberToken = tokens.Pop();
                if (next.Contains('.') || next.Contains('e') || next.Contains('E'))
                {
                    double value = Util.ParseDouble(numberToken);
                    return new FloatConstant(numberToken, value);
//.........这里部分代码省略.........
开发者ID:blakeohare,项目名称:pyweek-sentientstorage,代码行数:101,代码来源:ExpressionParser.cs

示例6: ParseNot

        private static Expression ParseNot(TokenStream tokens)
        {
            tokens.SkipWhitespace();
            string next = tokens.PeekValue();
            if (next == "+" || next == "-" || next == "~")
            {
                Token token = tokens.Pop();
                Expression root = ParseExponents(tokens);
                return new Negation(token, root,
                    token.Value == "+"
                        ? Negation.PrefixType.POSITIVE
                        : token.Value == "-"
                            ? Negation.PrefixType.NEGATIVE
                            : Negation.PrefixType.BITWISE_NOT);
            }

            return ParseExponents(tokens);
        }
开发者ID:blakeohare,项目名称:pyweek-sentientstorage,代码行数:18,代码来源:ExpressionParser.cs

示例7: ParseExponents

 private static Expression ParseExponents(TokenStream tokens)
 {
     Expression left = ParseEntityWithSuffix(tokens);
     string next = tokens.PeekValue();
     if (next == "**")
     {
         List<Expression> expressions = new List<Expression>() { left };
         List<Token> ops = new List<Token>();
         while (next == "**")
         {
             ops.Add(tokens.Pop());
             expressions.Add(ParseEntityWithSuffix(tokens));
             next = tokens.PeekValue();
         }
         return new BinaryOpChain(expressions, ops);
     }
     return left;
 }
开发者ID:blakeohare,项目名称:pyweek-sentientstorage,代码行数:18,代码来源:ExpressionParser.cs

示例8: ParseEntityWithSuffix

        private static Expression ParseEntityWithSuffix(TokenStream tokens)
        {
            Expression expression = ParseRootEntity(tokens);
            bool nextAllowed;
            bool keepGoing = true;
            string next = tokens.PeekValue();

            while (keepGoing)
            {
                switch (next)
                {
                    case "[":
                        // indexing or slicing
                        Token bracketToken = tokens.Pop();
                        List<Expression> sliceComponents = new List<Expression>();
                        nextAllowed = true;
                        while (!tokens.PopIfPresent("]"))
                        {
                            if (!nextAllowed) tokens.PopExpected("]"); // throws

                            if (tokens.IsNext(":"))
                            {
                                sliceComponents.Add(null);
                            }
                            else
                            {
                                sliceComponents.Add(Parse(tokens));
                            }
                            nextAllowed = tokens.PopIfPresent(":");
                        }
                        if (nextAllowed)
                        {
                            sliceComponents.Add(null);
                        }
                        if (sliceComponents.Count == 0)
                        {
                            throw new ParserException(bracketToken, "Unexpected token.");
                        }
                        else if (sliceComponents.Count == 1)
                        {
                            expression = new IndexExpression(expression, bracketToken, sliceComponents[0]);
                        }
                        else if (sliceComponents.Count <= 3)
                        {
                            expression = new SliceExpression(expression, bracketToken, sliceComponents);
                        }
                        else
                        {
                            throw new ParserException(bracketToken, "Slice expression has too many components.");
                        }
                        break;
                    case "(":
                        // function call
                        Token openParen = tokens.Pop();
                        nextAllowed = true;
                        List<Expression> args = new List<Expression>();
                        while (!tokens.PopIfPresent(")"))
                        {
                            if (!nextAllowed) tokens.PopExpected(")"); // throws
                            args.Add(Parse(tokens));
                            nextAllowed = tokens.PopIfPresent(",");
                        }

                        expression = new FunctionInvocation(expression, args);
                        break;
                    case ".":
                        // dot field
                        Token dotToken = tokens.Pop();
                        Token fieldToken = tokens.Pop();
                        if (!Util.IsIdentifier(fieldToken))
                        {
                            throw new ParserException(fieldToken, "Invalid field.");
                        }
                        expression = new DotField(expression, dotToken, fieldToken, fieldToken.Value);
                        break;
                    default:
                        keepGoing = false;
                        break;
                }
                next = tokens.PeekValue();
            }

            return expression;
        }
开发者ID:blakeohare,项目名称:pyweek-sentientstorage,代码行数:84,代码来源:ExpressionParser.cs

示例9: ParseMultiplication

 public static Expression ParseMultiplication(TokenStream tokens)
 {
     Expression left = ParseNot(tokens);
     string next = tokens.PeekValue();
     if (MULTIPLICATION_OPERATORS.Contains(next))
     {
         List<Expression> expressions = new List<Expression>() { left };
         List<Token> ops = new List<Token>();
         while (MULTIPLICATION_OPERATORS.Contains(next))
         {
             ops.Add(tokens.Pop());
             expressions.Add(ParseNot(tokens));
             next = tokens.PeekValue();
         }
         return new BinaryOpChain(expressions, ops);
     }
     return left;
 }
开发者ID:blakeohare,项目名称:pyweek-sentientstorage,代码行数:18,代码来源:ExpressionParser.cs

示例10: ParseComparisons

 public static Expression ParseComparisons(TokenStream tokens)
 {
     Expression left = ParseBitwiseOr(tokens);
     string next = tokens.PeekValue();
     if (COMPARISON_TOKENS.Contains(next))
     {
         List<Expression> expressions = new List<Expression>() { left };
         List<Token> comparisons = new List<Token>();
         while (COMPARISON_TOKENS.Contains(next))
         {
             comparisons.Add(tokens.Pop());
             expressions.Add(ParseBitwiseOr(tokens));
             next = tokens.PeekValue();
         }
         return new ComparisonChain(expressions, comparisons);
     }
     return left;
 }
开发者ID:blakeohare,项目名称:pyweek-sentientstorage,代码行数:18,代码来源:ExpressionParser.cs


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