Due: 11:55pm, Friday 4 October 2024
In this assignment, you will:
- Implement a lexical analyser using lex (Problem 3).
- Implement parsers using lex and yacc (Problems 1 - 6).
- Program a Turing machine (Problem 7).
- Learn about some aspects of quantum circuits and quantum registers (Problems 2 - 6).
- Practise skills related to Pumping Lemmas and Context - Free Languages (Problem 8).
- Start working early and spread the work over time. Do as much as possible before week 10.
- Don't be deterred by the length of the document. Much of it is a tutorial and documentation.
- Download the workbench
asgn2.zipfrom Moodle. - Create a new Ed Workspace and upload the file, let Ed extract it.
- Edit the
student - idfile with your name and student ID. - Open a terminal and change into the
asgn2directory.
plus - times - power.l: Starting point for some lex files.plus - times - power.y: Starting point for some yacc files.quant.h: Should remain unaltered.prob6.awk: An awk program for a specific task.
Your submission must include:
student - idfile edited with your name and student ID.prob1.l: Obtained by modifying a copy ofplus - times - power.l.prob2.pdf: Your solution to Problem 2 (Context - Free Grammar for QCIRC).prob3.l: Obtained by modifying a copy ofplus - times - power.l.prob4.l: Obtained by modifying a copy ofprob3.l.prob4.y: Obtained by modifying a copy ofplus - times - power.y.prob5.l: Obtained by modifying a copy ofprob4.l.prob5.y: Obtained by modifying a copy ofprob4.y.prob6.txt: Ten lines, solution to Problem 6.prob7.tm: Tuatara Turing machine file.prob8.pdf: Your solution to Problem 8.
Construct prob1.l to be used with plus - times - power.y to build a parser for PLUS - TIMES - POWER.
Write a Context - Free Grammar for the language QCIRC over the alphabet {I, H, X, Y, Z, CNOT, TOF, *, ⊗, (, ) } and save it as prob2.pdf.
Construct a lex file prob3.l starting from plus - times - power.l to build a lexical analyser for QCIRC.
- Make a copy of
prob3.lcalledprob4.land modify it for use with yacc. - Construct a yacc file
prob4.yfromplus - times - power.y. - Build a parser for QCIRC that can evaluate expressions.
- Make copies of
prob4.landprob4.ycalledprob5.landprob5.yrespectively. - Modify them further to build a parser for QUANT.
- Use the
prob6.awkprogram to convert your student ID to a quantum register expression. - Copy the expression into
prob6.txtas the first line. - Run your parser on the expression and append the result to
prob6.txt.
Build a Turing machine in Tuatara v2.1 that computes the number choice function and save it as prob7.tm.
- Prove there is no Universal Regular Expression using the Pumping lemma for Regular Languages.
- Prove there is no Universal Context - Free Grammar using the Pumping lemma for Context - Free Languages. Save the proof as
prob8.pdf.
- An input file to lex ends in
.land has three parts: definitions, rules, C code. - The
plus - times - power.lfile is used as an example. It identifies tokens like nonnegative integers (NUMBER),Power(POWER), and specific characters. - When lex runs on the file, it generates
lex.yy.cwhich can be compiled to create a lexical analyser.
- An input file for yacc ends in
.yand has three parts: declarations, rules, programs. - The
plus - times - power.yfile is used as an example. It has a grammar for PLUS - TIMES - POWER and declarations for tokens and nonterminals. - To generate a parser, you need to modify
prob1.land useplus - times - power.yalong with some compilation steps.
- A quantum computer uses quantum physics for computation.
- It has a register that stores information in a superposition and a quantum circuit expression that transforms the register.
- The languages QCIRC, QREG, and QUANT are defined to describe quantum expressions.
- QCIRC is for valid quantum circuit expressions, QREG for valid quantum register expressions, and QUANT is their union.
- Input: A sequence
$k, x_{1}, x_{2},..., x_{n}$ encoded as$a^{k}ba^{x_{1}}ba^{x_{2}}b\cdots a^{x_{n}}$ . - Output:
$x_{k}$ encoded as$a^{x_{k}}$ . - A Turing machine for this function should reject invalid inputs.
- Universal regular expressions and universal context - free grammars are defined.
- The goal is to find expressions/grammars that can match/generate all relevant strings for a given set of regular expressions/context - free grammars.