Skip to content
Snippets Groups Projects
Commit ae8be18b authored by johti17's avatar johti17
Browse files

Updated the documentation for Lab IV

parent 706c352e
No related branches found
No related tags found
1 merge request!5Feedback 2023
......@@ -132,3 +132,34 @@ The file ``main.cc`` contains a sample main program.
You may have to modify it depending on how you choose to report errors from your parser.
If the scanner encounters an error it will throw an object of type :class`ScannerError`.
Your main program should catch this exception (the sample main program does), print an error message (you can print a :class:`ScannerError` object using stream operators) and then perform error recovery.
Testing your solution
---------------------
A test script is available called test.py with an auxilary file called test.txt.
You may test your solution by using the following command::
python3 test.py test.txt
The output of running this test program should be something like this::
=============================================================================
| 0: 1+2*3^-4 | Expected: 1.02469 | Got: 1.02469 | PASS |
| 1: 1+2/3 | Expected: 1.66667 | Got: 1.66667 | PASS |
| 2: (1+2)/3 | Expected: 1 | Got: 1 | PASS |
| 3: 2*3+5 | Expected: 11 | Got: 11 | PASS |
| 4: 2*(3+5) | Expected: 16 | Got: 16 | PASS |
| 5: 2^2^3 | Expected: 256 | Got: 256 | PASS |
| 6: 2*2^2*2 | Expected: 16 | Got: 16 | PASS |
| 7: (2*2)^(2*2) | Expected: 256 | Got: 256 | PASS |
| 8: 2^2*10 | Expected: 40 | Got: 40 | PASS |
| 9: 1--1 | Expected: 2 | Got: 2 | PASS |
| 10: 1*2^2+3/4^-1 | Expected: 16 | Got: 16 | PASS |
| 11: (-4*-4+4^2) | Expected: 32 | Got: 32 | PASS |
| 12: ((-4*-4+4^2)-32+1) | Expected: 1 | Got: 1 | PASS |
| 13: -(-1--(-(-10--100))) | Expected: 91 | Got: 91 | PASS |
| 14: e | Expected: 2.71828 | Got: 2.71828 | PASS |
| 15: pi | Expected: 3.14159 | Got: 3.14159 | PASS |
| 16: e^pi | Expected: 23.1407 | Got: 23.1407 | PASS |
| 17: log10(10) | Expected: 1 | Got: 1 | PASS |
| 18: sin(pi)+cos(pi) | Expected: -1 | Got: -1 | PASS |
| 19: log(e^e) | Expected: 2.71828 | Got: 2.71828 | PASS |
| 20: sin(pi/2)+cos(0)+tan(pi/4) | Expected: 3 | Got: 3 | PASS |
=============================================================================
......@@ -42,3 +42,26 @@ Hand in the following
Demonstrate your solution to your lab assistant during a laboratory session.
Send an e-mail (one e-mail per group) with your modified code to the same assistant, put TDDD55, assignment number and your LiU logins in the e-mail subject line.
Getting Started
---------------
In this lab you will be working with a quite large codebase.
Documentation concerning this codebase is available under skeleton at the left side in the tab tab "The Skeleton".
It is recommended that you start by implementing the different rules for expressions.
A test program is available at `./test/expression_test.prog`.
However, it might be useful to write your own program and test simple expressions on a step by step basis.
To run the compiler on your own program, named for instance myProgram.prog execute::
./compiler ./test/myProgram.prog
If you want to run the program with debugging information you may run::
./compiler -d ./test/myProgram.prog
See the different files in the test folders for examples on how to write programs in this language.
Troubleshooting
---------------
Make sure that you have checked all places in parser.y with the phrase "Your Code Here".
Once you have done so you can execute the following sequence of commands to check your compiler::
./compiler ./test/test.prog > output.txt
diff -y ./output.txt ../traces/trace-lab3.txt
Using this commands you will get a side by side comparision of your own output and a trace.
Take note that the memory addresses might differ for some entries, this is ok.
......@@ -26,3 +26,15 @@ Questions
For example, assigning a constant to a variable causes two quads to be generated, where one would have been enough.
There are a number of other situations where equally bad code is generated.
Suggest at least one way of eliminating most of the bad code that is generated.
Testing your solution
---------------------
To test your solution you may run the code-test.sh script located in the lab3-4 folder.
You can run this script using the following command::
bash ./codegen-test.sh
However, it might be wise to employ a step by step strategy.
Hence, similar to Lab III you may write your own test program and test it as you add new features to the backend.
Assuming you have written your own program you may test this program by invoking the compiler in the following way::
./compiler -c ./test/myProgram.prog > myProgram.c
gcc -g -o myProgram myProgram.c -lm
./myProgram
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment