Grammar-kit : psi tree for prefix expressions


I'm trying to make a bnf  and have such a problem with priority:

When I describe rules for prefix or unary not expressions like that

     unary_not_expression ::=  ("~"|"!") expression

psi tree for  expression a = !b^c looks like it were  a = !(b^c)

Changing order in rule

     expression ::=  xor_expression  | unary_not_expression | … | primary_expression

doesn't help.  By the way, there is the same problem here in part 2.4 Compact expression parsing with priorities. Although there is such list of priorities  for an example in this tutorial

 // Expression root: expr
  // Operator priority table:
  // 0: BINARY(assign_expr)
  // 1: BINARY(plus_expr) BINARY(minus_expr)
  // 2: BINARY(mul_expr) BINARY(div_expr)
  // 3: PREFIX(unary_plus_expr) PREFIX(unary_min_expr)
  // 4: N_ARY(exp_expr)
  // 5: POSTFIX(ref_expr)
  // 6: ATOM(simple_ref_expr) ATOM(literal_expr) PREFIX(paren_expr)
in fact in makes psi tree like expression were  a = !(b^c).
My solution was to write a rule like that 

     unary_not_expression ::=  ("~"|"!") primary_expression
where rule for primary_expression is  

     primary_expression ::= parenthesized_expression | identifier | literal  

But I don't like this solution, because  primary_expression is listed in rule for expression and the whole bnf doesn't look good.
Is there any other solution for that problem?


1 comment
Comment actions Permalink

Hi Liudmila!

Thanks for mentioning. There is indeed a bug in LiverPreviewParser which is now fixed in 1.1.10_1 release.
The generated parser doesn't suffer from this:
Screen Shot 2014-08-15 at 16.31.57 .png

I've included your sample in Gramamr-Kit testData both for generated and LivePreview modes.

Here's the screenshot after the fix:

Screen Shot 2014-08-15 at 16.01.47 .png

Message was edited by: Gregory Shrago


Please sign in to leave a comment.