This code is a Flask application that creates a web page for converting a file to pseudocode.
It does this by doing the following:
- Imports the necessary modules such as Flask, request and os.
- Creates an instance of Flask web application.
- Defines a route for the root URL '/' which renders an HTML template 'index.html'.
- Defines another route '/convert' which is only accessible via a POST request.
- When a file is posted to the '/convert' route, it checks if the file 'prog.txt' exists and removes it if it does.
- It then saves the posted file as 'prog.txt'
- It generates an output file 'output.txt' which is read and the contents are saved in a variable "pseudocode"
- The template 'index.html' is rendered again but this time with the pseudocode variable passed to it. Finally, the script runs the flask application in debug mode which allows for the application to be reloaded automatically when changes are made to the code.
Converting C++ to LaTeX PseudoCode is given below:
This script reads a given file and converts its code to pseudocode and writes the output in a file called "output.txt"
First, it creates global variables, such as lists of keywords for conditions and loops, a list of characters to stop at when parsing the file, and a list of bracket characters. It also opens the output file in write mode.
The script defines several functions:
- The comm() function checks if a line has a single-line comment marker.
- The func_cin() function handles lines that contain input statements and writes the corresponding pseudocode to the output file.
- The func_cout() function handles lines that contain output statements and writes the corresponding pseudocode to the output file.
- The func_return() function handles lines that contain return statements and writes the corresponding pseudocode to the output file.
- The func_cond() function handles lines that contain conditional statements and writes the corresponding pseudocode to the output file.
- The func_loop() function handles lines that contain loop statements and writes the corresponding pseudocode to the output file.
- The func_state() function handles lines that contain operation statements and writes the corresponding pseudocode to the output file.
- The func_comm() function handles lines that contain only comment and writes the corresponding pseudocode to the output file. It then reads the input file line by line, and calls the appropriate function based on the keyword used in the line.
Finally, it closes the output file.
Link for Tutorial Video: https://drive.google.com/file/d/1eA_pvJRxE1R8_PEUlp4hjSe-5canCD6L/view?usp=share_link
Link for Website: http://frankenstein0208.pythonanywhere.com/