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


C# Parser.TakeExpression方法代码示例

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


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

示例1: Parse

		public IExpression Parse(Parser parser, IExpression left, Token<TokenType> token)
		{
			var innerToken = parser.PeekToken();

			IExpression right = null;
			switch (innerToken.Identifier)
			{
				default:
					return new ArithmeticExpression(left, right, token);

				case TokenType.Plus:
					right = parser.TakeExpression(Predecence.Plus);
					break;

				case TokenType.Minus:
					right = parser.TakeExpression(Predecence.Minus);
					break;

				case TokenType.Multiply:
					right = parser.TakeExpression(Predecence.Multiply);
					break;

				case TokenType.Divide:
					right = parser.TakeExpression(Predecence.Divide);
					break;

				case TokenType.Exponent:
					right = parser.TakeExpression(Predecence.PowerOf);
					break;
			}

			return Parse(parser, right, innerToken);
		}
开发者ID:Spanfile,项目名称:Englang,代码行数:33,代码来源:ArithmeticParselet.cs

示例2: Parse

		public IExpression Parse(Parser parser, Token<TokenType> token)
		{
			var name = parser.TakeExpression<CallExpression>(Predecence.Prefix);
			if (!name.GetArguments().All(a => a is NameExpression)) // TODO: should this constraint be handled by the parser?
				throw new ParseException(token.GetLocation(), "All arguments in function's name must be NameExpressions");

			List<IExpression> inner = new List<IExpression>();
			while (true)
			{
				var innerToken = parser.PeekToken();

				if (innerToken.Identifier == TokenType.End)
				{
					parser.TakeToken(); // consume the token we peeked
					break;
				}

				if (innerToken.Identifier == TokenType.EOF)
					throw new ParseException(innerToken.GetLocation(), "EOF token reached before End was found");

				inner.Add(parser.TakeExpression(Predecence.Prefix));
			}

			return new FunctionExpression(name, inner, token);
		}
开发者ID:Spanfile,项目名称:Englang,代码行数:25,代码来源:FunctionParselet.cs

示例3: Parse

		public IExpression Parse(Parser parser, Token<TokenType> token)
		{
			var condition = parser.TakeExpression<ConditionalExpression>(0);
			parser.TakeToken(TokenType.Then); // we want the 'then' after the condition

			List<IExpression> inner = new List<IExpression>();
			List<IExpression> elseInner = new List<IExpression>();
			while (true)
			{
				var innerToken = parser.PeekToken();

				if (innerToken.Identifier == TokenType.End)
				{
					parser.TakeToken(); // consume the token we peeked
					break;
				}

				if (innerToken.Identifier == TokenType.Else)
				{
					// ew ew ew such dry code
					// TODO: make wet

					parser.TakeToken();  // consume the token we peeked
					while (true)
					{
						innerToken = parser.PeekToken();

						if (innerToken.Identifier == TokenType.End)
						{
							parser.TakeToken(); // consume the token we peeked
							break;
						}

						if (innerToken.Identifier == TokenType.EOF)
							throw new ParseException(innerToken.GetLocation(), "EOF token reached before End was found");

						elseInner.Add(parser.TakeExpression(Predecence.Prefix));
					}
				}

				if (innerToken.Identifier == TokenType.EOF)
					throw new ParseException(innerToken.GetLocation(), "EOF token reached before End was found");

				inner.Add(parser.TakeExpression(Predecence.Prefix));
			}

			return new IfExpression(condition, inner, elseInner, token);
		}
开发者ID:Spanfile,项目名称:Englang,代码行数:48,代码来源:IfParselet.cs

示例4: Parse

		public IExpression Parse(Parser parser, Token<TokenType> token)
		{
			if (parser.PeekToken().Identifier == TokenType.LeftParen)
			{
				parser.TakeToken(); // consume the read token
				List<IValueExpression> args = new List<IValueExpression>();
				while (true)
				{
					var innerToken = parser.PeekToken();

					if (innerToken.Identifier == TokenType.RightParen)
					{
						parser.TakeToken();
						break;
					}

					if (innerToken.Identifier == TokenType.EOF)
						throw new ParseException(innerToken.GetLocation(), "EOF reached before RightParen was found");

					var expr = parser.TakeExpression<IValueExpression>(Predecence.Prefix);
					args.Add(expr);
				}

				return new CallExpression(token.Value, args, token);
			}

			return new NameExpression(token.Value, token);
		}
开发者ID:Spanfile,项目名称:Englang,代码行数:28,代码来源:NameParselet.cs

示例5: Parse

		public IExpression Parse(Parser parser, IExpression left, Token<TokenType> token)
		{
			IExpression right = parser.TakeExpression(Predecence.Assign);

			if (!(left is NameExpression)) // TODO: should the parser do this check?
				throw new ParseException(left.GetLocation(), String.Format("Assign must be to a name (got {0})", left.GetType().Name));

			return new AssignExpression(left as NameExpression, right, token);
		}
开发者ID:Spanfile,项目名称:Englang,代码行数:9,代码来源:AssignParselet.cs

示例6: Parse

		public IExpression Parse(Parser parser, Token<TokenType> token)
		{
			IExpression operand = parser.TakeExpression(Predecence.Prefix);
			return new PrefixOperatorExpression(token, operand);
		}
开发者ID:Spanfile,项目名称:Englang,代码行数:5,代码来源:PrefixOperatorParselet.cs

示例7: Parse

		public IExpression Parse(Parser parser, Token<TokenType> token)
		{
			var expr = parser.TakeExpression(Predecence.Prefix);

			return new ReturnExpression(expr, token);
		}
开发者ID:Spanfile,项目名称:Englang,代码行数:6,代码来源:ReturnParselet.cs

示例8: Parse

		public IExpression Parse(Parser parser, IExpression left, Token<TokenType> token)
		{
			var right = parser.TakeExpression(Predecence.Conditional);

			return new ConditionalExpression(left, right, token);
		}
开发者ID:Spanfile,项目名称:Englang,代码行数:6,代码来源:ConditionalParselet.cs


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