Assignment 2 [10 marks]
Deadline: 8 May 2026

* This assignment can be done in teams of 5 students or less.
* Team members must be from the same lab so the TA can discuss all of them during one lab time.
* Each team must come up with their own implementation.
* Each student in the team must understand all details of the implementation.
* The code must contain no more than 15,000 characters.
* Your code must NOT include any TAB character. Convert each TAB to 4 spaces before submitting.
* You are not allowed to copy any piece of code from the internet or from any other resource.
* You are not allowed to copy any piece of code from other students.
* You are not allowed to include any files or built-in libraries, except for the described ones.
* Your coding style must follow exactly the coding style specified in CodingStyle.pdf.
* Half the mark is dedicated to test cases and following CodingStyle.
* If you have issue regarding the assignment, contact the TA, not the doctor.
* Get your submission on a flash drive or labtop and discuss your submission with the TA during the first lab after the deadline.
* The TA will not tell you your mark. He will report his evaluation to me and I will make the final evaluation.
* You are allowed to submit after the deadline with 10% mark-deduction for each late day.

--------------------------------------------------------------------------------------

* Write a standard C++ code that does the following:
* You are not allowed to use any built-in functions except: <cstdlib>, <cstdio>, <cstring>, <iostream>.
* You are not allowed to use string class, vector, or anything from STL libraries.
* Your code must be general to handle all input values.
* Write at least 20 test cases (each case is a complicated expression).
* Half the mark is dedicatd to test cases and following the CodingStyle.pdf file.

* Consider the expressions of groups of pages 459-460 of James Hein Book.
* Write a recursive descent parser that parses an expression and produces its parse tree. Print it.
* Apply reduction rules of Page 460 to convert the resulting parse tree to the parse tree of the normal form.
* Convert all intermediate parse trees of the above step to their corresponding expressions. Print trees and expression.
* Convert the parse tree of the normal form to its expression. Print tree and expression.

Example input: (the left-hand-side of the last expression of Page 460)
((x.y^-1).z)^-1

Example output:
inverse
|--product
   |--product
      |--x
      |--inverse
         |--y
   |--z

product
|--inverse
   |--z
|--inverse
   |--product
      |--x
      |--inverse
         |--y
z^-1.(x.y^-1)^-1

product
|--inverse
   |--z
|--product
   |--inverse
      |--inverse
         |--y
   |--inverse
      |--x
z^-1.((y^-1)^-1.x^-1)

product
|--inverse
   |--z
|--product
   |--y
   |--inverse
      |--x
z^-1.(y.x^-1)

--------------------------------------------------------------------------------------

To submit the code:
* Write your code in exactly one cpp text file such as myfile.cpp.
* Write your IDs and names as comments at the beginning of the code.
* Make sure that myfile.cpp contains the actual code, for example open it in Notepad (do not confuse it with cbp file).
* Encode the file using the assign_encoder tool as the following:
g++ -O3 -o assign_encoder.exe assign_encoder.cpp
assign_encoder.exe ./myfile.cpp 2 3 20101111 20102222 20113333
* The 2 in the above line is the assignment ID. The 3 in the above line is number of students.
* If you are a pre-master student, use the ID 20000000 and make sure your name exists as a comment at the beginning of the code.
* Open the resulting assign_2_20101111_20102222_20113333.bin file in a text editor.
* Make sure that the text-editor did not put any line-breaks (un-check the word-wrap option).
* Copy all the text included in the file.
* Submit the text via the following Google link, as well as your IDs. If the number of students is less than 5, put the number 00000000 in place of un-needed IDs.
https://forms.gle/8WieV3f9duCACeZN9
