1

For example if I was writing a parser.mly file like, and I have this written for expressions

expr:
    expr PLUS   expr { Binop($1, Add,   $3)   }
  | expr DIVIDE expr { Binop($1, Divide,   $3)   }

Would this be the same as

expr:
    expr DIVIDE   expr { Binop($1, Divide,   $3)   }
  | expr PLUS expr { Binop($1, Add,   $3)   }

Like I guess I'm asking if the order in which things are listed vertically matter in determining parsing precedence?

Shisui
  • 1,051
  • 1
  • 8
  • 23

1 Answers1

3

Both ocamlyacc and menhir require that you explicitly declare precedence, using the %left, %right and %nonassoc declarations. The order of productions is not relevant.

rici
  • 234,347
  • 28
  • 237
  • 341