PLTools / Lama

Teaching language LaMa for a compiler course
GNU General Public License v3.0
70 stars 37 forks source link

Ambiguous parsing #6

Open egormkn opened 4 years ago

egormkn commented 4 years ago

Problem I found a bug in lama parser, that is somehow connected to ambiguous grammar rules for case expression and infix operators.

Example code

infix | at ++ (lhs, rhs) {
  lhs ++ rhs
}

infix -> at ++ (lhs, rhs) {
  lhs ++ rhs
}

(* Prints "WAT" *)
printf ("%s\n", 
  case "?" of
    "?" -> "W" 
  | "A" -> "T"
  esac.string
);

(* Prints W *)
printf ("%s\n", 
  case "?" of
    "?" -> "W" 
  | "A" -> "T"
  esac
)

Expected behaviour Both outputs are quite reasonable but they should be the same for both expressions.

Environment

dboulytchev commented 4 years ago

https://github.com/JetBrains-Research/Lama/issues/5#issuecomment-600263002