Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If statements should support single statement then and else #228

Open
idavis opened this issue Aug 30, 2024 · 3 comments
Open

If statements should support single statement then and else #228

idavis opened this issue Aug 30, 2024 · 3 comments

Comments

@idavis
Copy link

idavis commented Aug 30, 2024

From the spec:

The statement if ( bool ) <true-body> branches to program if the Boolean evaluates to true
and may optionally be followed by else <false-body>. Both true-body and false-body can
be a single statement terminated by a semicolon, or a program block of several statements { stmt1; stmt2; }.

grammar: ifStatement: IF LPAREN expression RPAREN if_body=statementOrScope (ELSE else_body=statementOrScope)?;

if-then example:

include "stdgates.inc";
qubit q;
if (0 == 1) z q;

output:

Error: [  x QASM3 Parse Error: expected a block
   ,-[test:4:20]
 3 |         qubit q;
 4 |         if (0 == 1) z q;
   :                    ^
 5 |     
   `----
]

if-then-else example:

include "stdgates.inc";
qubit q;
if (0 == 1) z q; else x q;

output:

Error: [  x QASM3 Parse Error: expected a block
   ,-[test:4:20]
 3 |         qubit q;
 4 |         if (0 == 1) z q; else x q;
   :                    ^
 5 |     
   `----
,   x QASM3 Parse Error: stmt: expected expression, type declaration, or let
  | statement
   ,-[test:4:26]
 3 |         qubit q;
 4 |         if (0 == 1) z q; else x q;
   :                          ^
 5 |     
   `----
]
@jakelishman
Copy link
Member

Just to warn you because you're opening a lot of issues: this parser is/was experimental, and is not this second under active development. We reprioritised our efforts earlier in the year, and this parser is one of the things that got temporarily deprioritised, before we'd finished making it production ready.

We do intend to pick up development on it again, probably in the new year, but right now, there's nobody from the Qiskit team actively working on it.

@jlapeyre
Copy link
Collaborator

@idavis Thanks very much for opening these issues! They will be very useful.

@jlapeyre
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants