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::<yournameofthestartexpression>() {
//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 <nameofyourexpressionmethod>();
}
````
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.