quantastica / quantum-circuit

Quantum Circuit Simulator implemented in JavaScript
MIT License
243 stars 47 forks source link

Please disambiguate unary and binary minus in QASM #49

Closed wh5a closed 3 years ago

wh5a commented 3 years ago

A statement like "cu1(-pi) q[0], q[1];" cannot be parsed correctly, unless we insert a space like so: "cu1(- pi) q[0], q[1];". This problem can be reproduced on https://quantum-circuit.com/ as well.

The antlr grammar needs to be changed. A quick search found some discussions: https://stackoverflow.com/questions/32166738/disambiguating-unary-and-binary-minus-in-antlr4-grammar https://stackoverflow.com/questions/27478834/how-compiler-distinguishes-minus-and-negative-number-during-parser-process

perak commented 3 years ago

@wh5a thank you for reporting. Will be fixed asap. In meantime, you can use -1*pi instead -pi.