0

I've been trying to get grammarinator to generate random test programs based on the openQasm3.0 grammar (https://github.com/Qiskit/openqasm/blob/master/source/grammar/qasm3.g4), What I want to get is:

qasm3.g4 -> Antlr4py3 -> *.g4 files -> Grammarinator-generate -> a bunch of valid program files as tests.

So far what I got is:

  1. antlr4py3 -o ./somedir qasm3.g4 (which is based on the instructions given on openqasm github)
  2. Step 1 yielded a bunch of files, most importantly: qasm3Lexer.py, qasm3Parser.py, qasm3Lexer.tokens, qasm3tokens.
  3. When I looked at them, they don't seem to reminiscence what grammarinator expects. Based on info and examples that I read online, I need to feed grammarinator-process and grammarinator-generate with some g4 files, such as qasm3Lexer4 and qasm3Parser.g4 etc, but I can't find them from Step 2. I tried to feed them with the *.py files from step 2, but they generated gibberish test programs.

Some of the commands that I tried are:

i) grammarinator-process qasm3Lexer.tokens qasm3.tokens -o

ii) grammarinator-process qasm3.g4 -o output

Followed by: grammarinator-generate -l qasm3Unlexer.py -p qasm3Uparser.py -r program -n number -d depth -o test.txt

I've also tried various combinations, compared the samples with what's in qasm3, but to no avail, and I'm lost. Just wondering if someone could give me some pointers on how to proceed? Thanks in advance.

Ming
  • 55
  • 4

1 Answers1

1

Sorry about this. I have definitely misunderstood a couple of things about antlr4 and grammarinator. The latter expects the qasm3.g4 input, which then generates the corresponding Unlexer and Unparser. Thus, the process is: qasm3.g4 (from github) -> either antlr4 or grammarinator -> outputs.

So in the end I managed to get grammarinator to generate some test programs by feeding the qasm3.g4 file into it:

  1. grammarinator-process qasm3.g4 -o outputdir <--- this process generates two files, namely qasm3Unlexer.py and qasm3Unparser.py, and they are used in the next step to generate the test programs.
  2. grammarinator-generate -l outputdir/qasm3Unlexer.py -p outputdir/qasm3Unparser.py -r program (or something that you want to test out based on qasm3.g4) -n somenum -d somedepth -o outputdir/test_%d.txt
Ming
  • 55
  • 4