public IExpression Parse(Parser parser, IExpression left, Token token) { var thenArm = parser.ParseExpression(); parser.Consume(TokenType.Colon); var elseArm = parser.ParseExpression(Precedence.Conditional - 1); return new ConditionalExpression(left, thenArm, elseArm); }
public IExpression Parse(Parser parser, IExpression left, Token token) { // To handle right-associative operators like "^", we allow a slightly // lower precedence when parsing the right-hand side. This will let a // parselet with the same precedence appear on the right, which will then // take *this* parselet's result as its left-hand argument. var right = parser.ParseExpression(_precedence - (_right ? 1 : 0)); return new OperatorExpression(left, _operator, right); }
public IExpression Parse(Parser parser, IExpression left, Token token) { var right = parser.ParseExpression((int)Precedence.Assignment - 1); if (!(left is NameExpression)) { throw new ParseException("The left-hand side of an assignment must be a name."); } var name = ((NameExpression)left).Name; return new AssignExpression(name, right); }
public IExpression Parse(Parser parser, IExpression left, Token token) { // Parse the comma-separated arguments until we hit, ")". var args = new List<IExpression>(); // There may be no arguments at all. if (!parser.Match(TokenType.RightParen)) { do { args.Add(parser.ParseExpression()); } while (parser.Match(TokenType.Comma)); parser.Consume(TokenType.RightParen); } return new CallExpression(left, args); }
public IExpression Parse(Parser parser, Token token) { return new NameExpression(token.Value); }
public IExpression Parse(Parser parser, Token token) { var expression = parser.ParseExpression(); parser.Consume(TokenType.RightParen); return expression; }
public IExpression Parse(Parser parser, IExpression left, Token token) { return new PostfixExpression(left, _operator); }