associativity

Expression grammar with exponentiation operator using Boost Spirit

戏子无情 提交于 2019-12-23 12:22:05
问题 I would like to add the exponentiation operator to the expression grammar provided in the Boost spirit samples. The BNF grammar is the following: (see this answer for example: "Unambiguous grammar for exponentiation operation" ) E -> E + T | E - T | T T -> T * F | T / F | X X -> X ^ Y | Y Y -> i | (E) which I translated to Boost spirit like this: template <typename Iterator> struct calculator : qi::grammar<Iterator, ascii::space_type> { calculator() : calculator::base_type(expression) { qi:

What is the precedence among operators in XPath?

假如想象 提交于 2019-12-21 21:14:55
问题 In this XPath expression: //div[@id=”myID”]|p , does the // operator get applied to both sides of the union operator? Or would this expression simply return all div elements in the document that have an id attribute value of myID and all p elements that are children of the context node? Is there a reference for XPath operator binding and associativity? 回答1: XPath Operator Order Precedence The XPath EBNF grammar implies the following precedence among operators ( lowest to highest ): Source :

Why is function composition in Haskell right associative?

蓝咒 提交于 2019-12-20 09:28:37
问题 Mathematically the function composition operation is associative. Hence: f . (g . h) = (f . g) . h Thus the function composition operation may be defined to be either left associative or right associative. Since normal function application in Haskell (i.e. the juxtaposition of terms, not the $ operation) is left associative in my opinion function composition should also be left associative. After all most people in the world (including myself) are used to reading from left to right.

What is associativity of operators and why is it important?

試著忘記壹切 提交于 2019-12-17 08:05:29
问题 What is associativity (for an operator) and why is it important? Updated: operator associativity 回答1: For operators, associativity means that when the same operator appears in a row, then which operator occurence we apply first. In the following, let Q be the operator a Q b Q c If Q is left associative, then it evaluates as (a Q b) Q c And if it is right associative, then it evaluates as a Q (b Q c) It's important, since it changes the meaning of an expression. Consider the division operator

Ternary operator left associativity

送分小仙女□ 提交于 2019-12-17 06:36:11
问题 In the PHP manual, I find the following 'user contributed note' under "Operators". Note that in php the ternary operator ?: has a left associativity unlike in C and C++ where it has right associativity. You cannot write code like this (as you may have accustomed to in C/C++): <?php $a = 2; echo ( $a == 1 ? 'one' : $a == 2 ? 'two' : $a == 3 ? 'three' : $a == 4 ? 'four' : 'other'); echo "\n"; // prints 'four' I actually try it and it really prints four . However I could not understand the

Operator Associativity

自古美人都是妖i 提交于 2019-12-13 07:04:54
问题 I have the following EBNF expression grammar: <expr> -> <term> { (+|-) <term> } <term> -> <factor> { (*|/|%) <factor> } <factor> -> <pow> { ** <pow> } <pow> -> ( <expr> ) | <id> <id> -> A | B | C I need to determine if the grammar enforces any particular associativity for its operators, or if that would have to be implemented in the parser code. From what I have read so far, it doesn't look like it does, but I am having a hard time understanding what causes associativity. Any help would be

Why is the $! operator right-associative?

会有一股神秘感。 提交于 2019-12-12 12:12:15
问题 I'm just learning Haskell and I'm still not entirely clear on when and how strict evaluation is forced When I want a function to evaluate its arguments strictly I find myself writing ((f $! x) $! y ) $! z which seems weird. Shouldn't $! be left-associative so I could write f $! x $! y $! z and have it do what I want? Am I completely misunderstanding the $! operator? 回答1: Argument against I found a proposal from 2008 in haskell-prime to make the $ and $! operators left-associative: https://ghc

Associativity of comparison operators in Python

孤人 提交于 2019-12-11 13:00:18
问题 What is the associativity of comparison operators in Python? It is straightforward for three comparisons, but for more than that, I'm not sure how it does it. They don't seem to be right- or left-associative. For example: >>> 7410 >= 8690 <= -4538 < 9319 > -7092 False >>> (((7410 >= 8690) <= -4538) < 9319) > -7092 True So, not left-associative. >>> 81037572 > -2025 < -4722 < 6493 False >>> (81037572 > (-2025 < (-4722 < 6493))) True So it's not right-associative either. I have seen some places

Precedence and associativity of operators in C [duplicate]

微笑、不失礼 提交于 2019-12-11 06:27:01
问题 This question already has answers here : Why are these constructs using pre and post-increment undefined behavior? (14 answers) Closed 6 years ago . Please have a look at following code snippet: int a = 10, b; b = (a) + (++a); //2 printf("b = %d\n", b); Output: b = 22 In statement 2, there are 4 distinct operators. Out of which () has highest precedence. Since associativity of () operator is left to right why b = 22 and not 21 ? $ gcc --version gcc (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3 回答1: b

ternary operator and assignment operator

天涯浪子 提交于 2019-12-10 21:11:19
问题 in Does the C/C++ ternary operator actually have the same precedence as assignment operators? Luchian Grigore's answer says that cases like a ? b : c = d will always be inferred as a ? b : ( c = d ) because both = and ?: associate right to left so in c++ k = 21 > 3 ? j = 12 : j = 10; and k = 1 > 3 ? j = 12 : j = 10; both are fine. In C k = 21 > 3 ? 12 : j = 10 returns error invalid lvalue in assignment. Shouldn't above be inferred as (and return no error) k= 21 > 3 ? 12 : ( j = 10 ) I assume