public string VisitInfixOperation(InfixOperation infixOperation) { var leftOperandCode = GenerateExpression(infixOperation.LeftOperand); var operatorCode = GenerateInfixOperator(infixOperation.Operator.Node); var rightOperandCode = GenerateExpression(infixOperation.RightOperand); return($"{leftOperandCode}{operatorCode}{rightOperandCode}"); }
public IType VisitInfixOperation(InfixOperation infixOperation) { var leftOperandType = GetExpressionType(infixOperation.LeftOperand); var rightOperandType = GetExpressionType(infixOperation.RightOperand); if (leftOperandType != null && leftOperandType.IsSame(rightOperandType)) { return(leftOperandType.GetInfixOperationResultType(infixOperation.Operator.Node)); } _context.Error( infixOperation.Operator.Span, "type mismatch between operands of infix operation; " + $"left is \"{leftOperandType}\", but right is \"{rightOperandType}\""); return(null); }
private static IExpression ParseInfixOperation(ParserState state) { var expression = ParsePostfixOperation(state); while (!state.IsAtEnd() && state.Consume(_infixOperators)) { var @operator = state.Previous(); var rightOperand = ParsePostfixOperation(state); expression = new InfixOperation( state.NodeIdGenerator.GetNextId(), @operator, expression, rightOperand); } return(expression); }
public bool VisitInfixOperation(InfixOperation infixOperation) { if (!(IsExpressionValid(infixOperation.LeftOperand) && IsExpressionValid(infixOperation.RightOperand))) { return(false); } if (infixOperation.LeftOperand is InfixOperation child && infixOperation.Operator.Node != child.Operator.Node) { _context.Error( infixOperation.Operator.Span, "operator precedence is not supported; parentheses required"); } var leftOperandType = Typer.GetExpressionType( _context, _environment, infixOperation.LeftOperand); var rightOperandType = Typer.GetExpressionType( _context, _environment, infixOperation.RightOperand); if (leftOperandType != null && leftOperandType.GetInfixOperationResultType(infixOperation.Operator.Node) == null) { _context.Error( infixOperation.Operator.Span, $"infix operation \"{infixOperation.Operator.Node}\" " + $"is not defined for types \"{leftOperandType}\" and \"{rightOperandType}\""); return(false); } if (leftOperandType != null && leftOperandType.IsSame(rightOperandType)) { return(true); } _context.Error( infixOperation.Operator.Span, "type mismatch between operands of a infix expression; " + $"left is \"{leftOperandType}\", but right is \"{rightOperandType}\""); return(false); }
public Group(string start, string end, Precedence lbp, InfixOperation op) : base(start, lbp) { this.End = new Token(end, Precedence.End); this.implicitOp = op; }