[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

snmpconf proposed policy language grammar change




Since the policy language is formally defined as a
subset of ISO C++, it should follow C/C++ rules of
operator precedence.  The policy language grammar
as written doesn't enforce this, and precedence
rules in yacc/bison don't solve the problem.
The simplest solution is to modify the grammar.
Therefore, I recommend that we replace the following
productions. The new rules are functionally 
equivalent, but enforce C's rules of operator precedence.

/////////////////////////////////////////////////////

OLD
~~~

binary_expression:
    unary_expression
    | binary_expression binary_operator unary_expression

binary_operator:
    '||' | '&&' | '|' | '^' | '&' | '!=' | '==' | '>=' | '<='
    | '>' |  '<' | '>>' | '<<' |  '-' |  '+' |  '%' |  '/' |  '*'

assignment_expression:
    binary_expression
    | unary_expression assignment_operator assignment_expression

/////////////////////////////////////////////////////

NEW
~~~
multiplicative_expression
	:   unary_expression
	|   multiplicative_expression MODULO unary_expression
	|   multiplicative_expression DIVIDE unary_expression
	|   multiplicative_expression TIMES unary_expression

additive_expression
	:   multiplicative_expression
	|   additive_expression MINUS multiplicative_expression
	|   additive_expression PLUS  multiplicative_expression

shift_expression
	:   additive_expression
	|   shift_expression RIGHT_SHIFT additive_expression
	|   shift_expression LEFT_SHIFT  additive_expression

relational_expression 
	:   shift_expression
	|   relational_expression GE shift_expression
	|   relational_expression LE shift_expression
	|   relational_expression GT shift_expression
	|   relational_expression LT shift_expression

equality_expression 
	:   relational_expression
	|   equality_expression NE relational_expression
	|   equality_expression EQ relational_expression

and_expression
	:   equality_expression
	|   and_expression BITWISE_AND equality_expression

exclusive_or_expression 
	:   and_expression
	|   exclusive_or_expression XOR and_expression

inclusive_or_expression
	:   exclusive_or_expression
	|   inclusive_or_expression BITWISE_OR exclusive_or_expression

logical_and_expression
	:   inclusive_or_expression
	|   logical_and_expression LOGICAL_AND inclusive_or_expression

logical_or_expression
	:   logical_and_expression
	|   logical_or_expression LOGICAL_OR logical_and_expression

assignment_expression
	:   logical_or_expression
	|   unary_expression assignment_operator assignment_expression

/////////////////////////////////////////////////////


Ray Byler