Skip to content
Snippets Groups Projects
Commit 8ae50a94 authored by John Tinnerholm's avatar John Tinnerholm :art:
Browse files

Added a better README for Lab 2.

parent daedbda5
No related branches found
No related tags found
1 merge request!5Feedback 2023
# Instructions on how to run the test script
This folder contains the code for lab 2. A test script exists to test your implementation. To run this test script, you must execute the following command in the terminal on the IDA Lab Computers.
```bash
python3 test.py test.txt --program ./lab2
```
This assumes that you have successfully compiled the project by executing the makefile and *that the program has been configured to read successfully from stdin*.
Furthermore, the test script assumes that the lab has been completed according to the instructions, mistakes might cause the test script to malfunction.
To make the project make sure that you execute:
```
make
````
in the command line interface.
## Notes (Important)
* The test script assumes that you have Python 3 installed and that you run on the IDA Lab Systems. It is has not been tested on other systems such as MacOS or GNU/Linux.
* Initially the program will just enter an infinite loop. Hence, you will need to modify the program and get the basic scaffolding in place before you can run the test script. Thus, it might be a good idea to test of some of the arthimatic expressions in the terminal before proceeding with the test script.
To avoid inifnite loops when using files from stdin the following code snippet could be helpful.
Here we specifiy that if we encounter the end of file token we will throw an `ParserEndOfFile` error.
````c++
double Parser::<your name of the start expression>() {
//Note almost correct C++ but you will need to modify this code in order to make it run corretly. Do not simply just copy paste.
currentToken = scanner.Scan();
if (currentToken.type == kEndMark) {
throw ParserEndOfFile();
}
return <name of your expression method>();
}
````
This will be cought by the main loop which is configured in the following way:
```c++
int main(void)
{
Parser parser;
double val;
while (true)
{
try
{
cout << "Expression: " << flush;
/* Implement the parser.Parse method */
val = parser.Parse();
cout << "Result: " << val << '\n' << flush;
}
catch (ScannerError& e)
{
cerr << e << '\n' << flush;
parser.Recover();
}
catch (ParserError)
{
parser.Recover();
}
catch (ParserEndOfFile)
{
cerr << "End of file\n" << flush;
exit(0);
}
}
}
```
Note that the program will terminate if the end of file token is encountered.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment