public void Binary(TokenKind operation, int precedence, BinaryNodeBuilder <T> createBinaryNode, Associativity associativity = Associativity.Left) { int rightOperandPrecedence = precedence; if (associativity == Associativity.Right) { rightOperandPrecedence = precedence - 1; } Extend(operation, precedence, left => from symbol in Token(operation) from right in OperandAtPrecedenceLevel(rightOperandPrecedence) select createBinaryNode(left, symbol, right)); }
/// <summary> /// Registers a postfix unary operator. /// </summary> /// <param name="kind">Operator token kind.</param> /// <param name="precedence">Precedence. The bigger the number the more priority in the expression the operator has.</param> /// <param name="binaryNodeBuilder">Binary node builder function.</param> /// <param name="associativity">Operator associativity.</param> public void Binary(TokenKind kind, int precedence, BinaryNodeBuilder <TValue> binaryNodeBuilder, Associativity associativity = Associativity.Left) { var rightOperandPrecedence = associativity == Associativity.Left ? precedence : precedence - 1; Extend(kind, precedence, left => from symbol in kind.Lexeme() from right in OperandAtPrecedenceLevel(rightOperandPrecedence) select binaryNodeBuilder(left, symbol, right)); }