C Expression¶
Here the expression grammar:
/* Comment works as in C/C++ */ dummy_with_brace = [ @ignore('null') [ '{' dummy_with_brace* '}' | Base.string | Base.char | Base.read_char:c #check_not_brace(c) ] ] dummy_with_paren = [ @ignore('null') [ '(' dummy_with_paren* ')' | Base.string | Base.char | Base.read_char:c #check_not_paren(c) ] ] expression = [ assignement_expression:>_ [ ',':op #new_raw(op, op) assignement_expression:param #new_binary(_, op, param) ]* ] assign_op = [ @ignore('null') [ '=' !'=' | "+=" | "-=" | "*=" | "/=" | "%=" | "<<=" | ">>=" | "&=" | "^=" | "|=" ]:op #new_raw(_, op) ] assignement_expression = [ conditional_expression:>_ [ assign_op:op assignement_expression:param #new_binary(_, op, param) ]* ] constant_expression = [ conditional_expression:>_ ] conditional_expression = [ logical_or_expression:>_ [ '?' expression?:then ':' assignement_expression?:else #new_ternary(_, then, else) ]? ] logical_or_op = [ @ignore('null') ["||"]:op #new_raw(_, op) ] logical_or_expression = [ logical_and_expression:>_ [ logical_or_op:op logical_and_expression:param #new_binary(_, op, param) ]* ] logical_and_op = [ @ignore('null') ["&&"]:op #new_raw(_, op) ] logical_and_expression = [ or_expression:>_ [ logical_and_op:op or_expression:param #new_binary(_, op, param) ]* ] or_op = [ @ignore('null') ["|" !["|"|"="]]:op #new_raw(_, op) ] or_expression = [ xor_expression:>_ [ or_op:op xor_expression:param #new_binary(_, op, param) ]* ] xor_op = [ @ignore('null') ["^" !"="]:op #new_raw(_, op) ] xor_expression = [ and_expression:>_ [ xor_op:op and_expression:param #new_binary(_, op, param) ]* ] and_op = [ @ignore('null') ["&" !["&"|"="]]:op #new_raw(_, op) ] and_expression = [ equality_expression:>_ [ and_op:op equality_expression:param #new_binary(_, op, param) ]* ] eqneq_op = [ @ignore('null') ["==" | "!="]:op #new_raw(_, op) ] equality_expression = [ relational_expression:>_ [ eqneq_op:op relational_expression:param #new_binary(_, op, param) ]* ] cmp_op = [ @ignore('null') [ "<=" | ">=" | '<' !'<' | '>' !'>' ]:op #new_raw(_, op) ] relational_expression = [ shift_expression:>_ [ cmp_op:op shift_expression:param #new_binary(_, op, param) ]* ] shift_op = [ @ignore('null') [ "<<" !"=" | ">>" !"=" ]:op #new_raw(_, op) ] shift_expression = [ additive_expression:>_ [ shift_op:op additive_expression:param #new_binary(_, op, param) ]* ] add_op = [ @ignore('null') [ '+' !['+'|'='] | '-' !['-'|'='|'>'] ]:op #new_raw(_, op) ] additive_expression = [ multiplicative_expression:>_ [ add_op:op multiplicative_expression:param #new_binary(_, op, param) ]* ] mul_op = [ @ignore('null') [['*'|'/'|'%']:op !'='] #new_raw(_, op) ] multiplicative_expression = [ unary_expression:>_ [ mul_op:op unary_expression:param #new_binary(_, op, param) ]* ] unary_op = [ @ignore('null') ["++" |"--" |"&&" | '&' !'=' | '*' !'=' | '~' !'=' | '!' !'=' | '+' !'=' | '-' !['>'|'='] ]:op #new_raw(_, op) ] unary_expression = [ postfix_expression:>_ | __scope__:op [ unary_op:>op | Base.id:i #is_raw(op, i) ] unary_expression:expr #new_unary(_, op, expr) ] postfix_expression = [ primary_expression:>_ [ __scope__:pres [ '[' expression:expr ']' #new_array_call(pres, _, expr) | '(' func_arg_list?:args ')' #new_func_call(pres, _, args) | '.' identifier:i #new_dot(pres, _, i) | "->" identifier:i #new_arrow(pres, _, i) | ["++"|"--"]:op #new_raw(op, op) #new_post(pres, op, _) ] #bind('_', pres) ]* ] func_arg_list = [ assignement_expression:a #new_arg(_, a) [ ',' assignement_expression:a #new_arg(_, a) ]* ] primary_expression = [ '(' expression:expr ')' #new_paren(_, expr) | [ Literal.literal | identifier ]:>_ ] identifier = [ @ignore('null') [ rootidentifier:id #check_is_id(id) #new_id(_, id) ] ] rootidentifier = [ Base.id ]
-
class
cnorm.parsing.expression.
Expression
(content: str='', stream_name: str=None, raise_diagnostic=True)[source]¶ Bases:
pyrser.grammar.Grammar
interaction with other CNORM PART:
-
entry
= 'expression'¶
-
check_is_id
(self, identifier)¶
-
check_not_brace
(self, c)¶
-
check_not_paren
(self, c)¶
-
is_raw
(self, op, ident)¶
-
new_arg
(self, ast, arg)¶
-
new_array_call
(self, ast, call, index)¶
-
new_arrow
(self, ast, call, field)¶
-
new_binary
(self, ast, op, param)¶
-
new_dot
(self, ast, call, field)¶
-
new_func_call
(self, ast, call, args)¶
-
new_id
(self, ast, identifier)¶
-
new_paren
(self, ast, expr)¶
-
new_post
(self, ast, op, param)¶
-
new_raw
(self, ast, data)¶
-
new_ternary
(self, ast, then_expr, else_expr)¶
-
new_unary
(self, ast, op, param)¶
-