diff --git a/README.md b/README.md index 08c03886e7ea67c4b903a1ced156b8fd1beff124..b453b2a05d5384e02a7eb7bdf183c7205b2baca7 100644 --- a/README.md +++ b/README.md @@ -7,50 +7,36 @@ The main goal of the program is to generate the result of the beta_reduction of a lambda term given as an input and to show the images of the alligator's families that represents the lambda term and the different steps of it's beta_reduction. It also allows us to see how logical, boolean and arithmetic expressions are written in lambda calculus. ## Table of contents -1. [ The structures. ] (#structures) -2. [ What to install. ] (#needs) -3. [ How to install. ] (#installations) -4. [ Utilisation. ] (#utilisation) -5. [ parsing syntax. ] (#allow) -6. [ Documentation. ] (#Docu) -7. [ Contribution. ] (#cont) -## The structures <a name="structures"></a> -Lambda terms are respresented by lists, the first element of the list is an indication to the type of the lambda term that it represents. -Variable: [VAR, name], -Abstraction: [ABS, input, output] input and output are also lambda terms -Application: [APP, first_Term, second_Term] first_term and second_term are also lambda terms - -The png images are already created, to build the image of a lambda term we just have to concatenate the existing images and to colorate the alligators and eggs by random colors. - -## What to install <a name="needs"></a> +<!-- TOC -->- [the structures](#structures)<br /> - [what to install](#needs)<br /> - [how to install](#how)<br /> - [utilisation](#utilisation)<br /> - [parsing syntax ](#parse)<br /> - [documentation](#docu)<br /> - [contribution](#contri)<br /> <!-- /TOC --> +## structures <a name="structures"></a> +Lambda terms are respresented by lists, the first element of the list is an indication to the type of the lambda term that it represents.<br /> +Variable: [VAR, name]<br /> +Abstraction: [ABS, input, output] input and output are also lambda terms<br /> +Application: [APP, first_Term, second_Term] first_term and second_term are also lambda terms<br /> +The png images are already created, to build the image of a lambda term, we just have to concatenate the existing images and to colorate the alligators and eggs by random colors. +## What to install <a name="needs"></a> -- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files -- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: - -``` -cd existing_repo -git remote add origin https://gitlab.lis-lab.fr/benjamin.monmege/alligators-python.git -git branch -M main -git push -uf origin main -``` - -## Integrate with your tools +1. PIL library (to generate images) +2. PYFIGLET library(to implement a new font) +3. keyboard module (to get an enter char) +4. shutil module (manipulate directories) -- [ ] [Set up project integrations](https://gitlab.lis-lab.fr/benjamin.monmege/alligators-python/-/settings/integrations) +## how to install <a name="how"></a> -## Collaborate with your team +- To install the needed tools, you have to use the following command:<br /> +pip install requirements.txt -- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) -- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) -- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) -- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) -- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) +## utilisation <a name="utilisation"></a> +The program is very simple to use, these are some advices once we run the code: <br /> +1. When you have to make a choice, click a button which is indicated, the code won't stop asking you to re-enter a choice until you press a right button. +2. The lambda term that is given as an input has to respect some syntactic rules, you can find the rules in the section parsing syntax. +3. When you choose an option in the menu, the images that could have been generated are stocked in a temporary directory which you are free to save or delete at the end. ## Test and Deploy diff --git a/logic.py b/logic.py index 576ecdf4858129e6d93d03770a71e9ae0511c8dd..93fe8cdda3a1790ddd152e64c707cbfa5ecf7bf0 100644 --- a/logic.py +++ b/logic.py @@ -486,7 +486,7 @@ def beta_reduction_choice_n(terme,n): def beta_reduction_interactive(terme, at): global counters if at != None: - # print(annotated_to_string(at)) + print(annotated_to_string(at)) choice = int(input("Choose a beta reduction: ")) while choice <= 0 or choice > counters: print("Invalid choice") @@ -509,7 +509,7 @@ def cleanReductions(l): def beta_reduction_interactive_totale(terme,path): if beta_reduction((terme)) != None: - # print(to_string(terme)) + #print(to_string(terme)) at = (annotate_beta_reduction((terme))) captureImage(at,path) choix=int(input("voulez-vous faire la reduction tapez sur 1 pour oui tapez sur 2 pour non ")) diff --git a/main.py b/main.py index 24c0b1c4315d872e9ee524c12e3b48465e89f066..fcf77e68f74bbc6566e81436a4f771745daf2402 100644 --- a/main.py +++ b/main.py @@ -97,15 +97,16 @@ def run_beta_reduction_totale(terme,path='beta_reduction_totale'): os.makedirs(path, exist_ok=True)# cree le rep si il existe pas, le vide si non if len(os.listdir(path)) > 0: logic.image_counter = 0 - logic.beta_reduction_totale(terme,path) - save_image_choice = input('Do you want to save the images? (y/n): ') - while save_image_choice not in ['y','n']: - save_image_choice = input('Invalid choice. Do you want to save the images? (y/n): ') - if save_image_choice == 'y': + k=logic.beta_reduction_totale(terme,path) + print(" le terme obtenu est: "+logic.to_string(k)) + save_image_choice = input('Do you want to save the images? (Y/n): ') + while save_image_choice not in ['y','n','']: + save_image_choice = input('Invalid choice. Do you want to save the images? (Y/n): ') + if save_image_choice == 'y' or save_image_choice=='': os.makedirs("./sauvegarde/"+path, exist_ok=True) moveImages(path,'./sauvegarde/'+path) os.rmdir(path) - elif save_image_choice == 'n': + elif save_image_choice=='n': delete_images(path) os.rmdir(path) @@ -118,10 +119,10 @@ def run_beta_reduction_interactive_totale(terme,path='beta_reduction_interactive if len(os.listdir(path)) > 0: logic.image_counter = 0 logic.beta_reduction_interactive_totale(terme,path) - save_image_choice = input('Do you want to save the images? (y/n): ') - while save_image_choice not in ['y','n']: - save_image_choice = input('Invalid choice. Do you want to save the images of the reduction? (y/n): ') - if save_image_choice == 'y': + save_image_choice = input('Do you want to save the images? (Y/n): ') + while save_image_choice not in ['y','n','']: + save_image_choice = input('Invalid choice. Do you want to save the images of the reduction? (Y/n): ') + if save_image_choice == 'y'or save_image_choice=='': os.makedirs("./sauvegarde/"+path, exist_ok=True) moveImages(path,'./sauvegarde/'+path) os.rmdir(path) @@ -143,10 +144,10 @@ def run_show_numbers(path): t = app_functions.dec_to_church(terme) print('Voici le terme:',logic.to_string(t)) logic.captureImage(t,path,'ENTIER'+str(terme),False) - save_image_choice = input('Do you want to save the images? (y/n): ') - while save_image_choice not in ['y','n']: - save_image_choice = input('Invalid choice. Do you want to save the images of the reduction? (y/n): ') - if save_image_choice == 'y': + save_image_choice = input('Do you want to save the images? (Y/n): ') + while save_image_choice not in ['y','n','']: + save_image_choice = input('Invalid choice. Do you want to save the images of the reduction? (Y/n): ') + if save_image_choice == 'y' or save_image_choice=='': os.makedirs("./sauvegarde/"+path, exist_ok=True) moveImages(path,'./sauvegarde/'+path) os.rmdir(path) @@ -160,10 +161,10 @@ def run_show_numbers(path): t = app_functions.dec_to_lambda_relative_integers(terme) print('Voici le terme:',logic.to_string(t)) logic.captureImage(t,path,'ENTIER-RELATIF-'+str(terme),False) - save_image_choice = input('Do you want to save the images? (y/n): ') - while save_image_choice not in ['y','n']: - save_image_choice = input('Invalid choice. Do you want to save the images of the reduction? (y/n): ') - if save_image_choice == 'y': + save_image_choice = input('Do you want to save the images? (Y/n): ') + while save_image_choice not in ['y','n','']: + save_image_choice = input('Invalid choice. Do you want to save the images of the reduction? (Y/n): ') + if save_image_choice == 'y' or save_image_choice=='': os.makedirs("./sauvegarde/"+path, exist_ok=True) moveImages(path,'./sauvegarde/'+path) os.rmdir(path) @@ -186,10 +187,10 @@ def run_boolean_expression(path): t = app_functions.NOT print('Voici le terme:',logic.to_string(t)) logic.captureImage(t,path,'NOT',False) - save_image_choice = input('Do you want to save the images? (y/n): ') - while save_image_choice not in ['y','n']: - save_image_choice = input('Invalid choice. Do you want to save the images of the reduction? (y/n): ') - if save_image_choice == 'y': + save_image_choice = input('Do you want to save the images? (Y/n): ') + while save_image_choice not in ['y','n','']: + save_image_choice = input('Invalid choice. Do you want to save the images of the reduction? (Y/n): ') + if save_image_choice == 'y' or save_image_choice=='': os.makedirs("./sauvegarde/"+path, exist_ok=True) moveImages(path,'./sauvegarde/'+path) os.rmdir(path) @@ -201,10 +202,10 @@ def run_boolean_expression(path): t = app_functions.AND print('Voici le terme:',logic.to_string(t)) logic.captureImage(t,path,'AND',False) - save_image_choice = input('Do you want to save the images? (y/n): ') - while save_image_choice not in ['y','n']: - save_image_choice = input('Invalid choice. Do you want to save the images of the reduction? (y/n): ') - if save_image_choice == 'y': + save_image_choice = input('Do you want to save the images? (Y/n): ') + while save_image_choice not in ['y','n','']: + save_image_choice = input('Invalid choice. Do you want to save the images of the reduction? (Y/n): ') + if save_image_choice == 'y' or save_image_choice=='': os.makedirs("./sauvegarde/"+path, exist_ok=True) moveImages(path,'./sauvegarde/'+path) os.rmdir(path) @@ -216,10 +217,10 @@ def run_boolean_expression(path): t = app_functions.OR print('Voici le terme:',logic.to_string(t)) logic.captureImage(t,path,'OR',False) - save_image_choice = input('Do you want to save the images? (y/n): ') - while save_image_choice not in ['y','n']: - save_image_choice = input('Invalid choice. Do you want to save the images of the reduction? (y/n): ') - if save_image_choice == 'y': + save_image_choice = input('Do you want to save the images? (Y/n): ') + while save_image_choice not in ['y','n','']: + save_image_choice = input('Invalid choice. Do you want to save the images of the reduction? (Y/n): ') + if save_image_choice == 'y' or save_image_choice=='': os.makedirs("./sauvegarde/"+path, exist_ok=True) moveImages(path,'./sauvegarde/'+path) os.rmdir(path) @@ -231,10 +232,10 @@ def run_boolean_expression(path): t = app_functions.XOR print('Voici le terme:',logic.to_string(t)) logic.captureImage(t,path,'XOR',False) - save_image_choice = input('Do you want to save the images? (y/n): ') - while save_image_choice not in ['y','n']: - save_image_choice = input('Invalid choice. Do you want to save the images of the reduction? (y/n): ') - if save_image_choice == 'y': + save_image_choice = input('Do you want to save the images? (Y/n): ') + while save_image_choice not in ['y','n','']: + save_image_choice = input('Invalid choice. Do you want to save the images of the reduction? (Y/n): ') + if save_image_choice == 'y' or save_image_choice=='': os.makedirs("./sauvegarde/"+path, exist_ok=True) moveImages(path,'./sauvegarde/'+path) os.rmdir(path) @@ -247,10 +248,10 @@ def run_boolean_expression(path): t = app_functions.IS_ZERO print('Voici le terme:',logic.to_string(t)) logic.captureImage(t,path,'IS_ZERO',False) - save_image_choice = input('Do you want to save the images? (y/n): ') - while save_image_choice not in ['y','n']: - save_image_choice = input('Invalid choice. Do you want to save the images of the reduction? (y/n): ') - if save_image_choice == 'y': + save_image_choice = input('Do you want to save the images? (Y/n): ') + while save_image_choice not in ['y','n','']: + save_image_choice = input('Invalid choice. Do you want to save the images of the reduction? (Y/n): ') + if save_image_choice == 'y' or save_image_choice=='': os.makedirs("./sauvegarde/"+path, exist_ok=True) moveImages(path,'./sauvegarde/'+path) os.rmdir(path) @@ -327,19 +328,19 @@ def run_arithmetic_operations_menu(path='arithmetic expressions'): clear() print("Voici le terme: "+ logic.to_string(app_functions.ADD)) logic.captureImage(app_functions.ADD,path,'ADD', False) - choix=(input("do you want to try an exemple? (y/n) : ")) - while choix not in ['y','n']: - choix = input('Invalid choice. Do you want to try an exemple? (y/n): ') - if choix=='y': + choix=(input("do you want to try an exemple? (Y/n) : ")) + while choix not in ['y','n','']: + choix = input('Invalid choice. Do you want to try an exemple? (Y/n): ') + if choix=='y' or choix=='': clear() print("you are going to try n+m") n=int(input("give n : ")) m=int(input("give m : ")) app_functions.add(app_functions.dec_to_church(n),app_functions.dec_to_church(m)) - save_image_choice = input('Do you want to save the images? (y/n): ') - while save_image_choice not in ['y','n']: - save_image_choice = input('Invalid choice. Do you want to save the images of the reduction? (y/n): ') - if save_image_choice == 'y': + save_image_choice = input('Do you want to save the images? (Y/n): ') + while save_image_choice not in ['y','n','']: + save_image_choice = input('Invalid choice. Do you want to save the images? (Y/n): ') + if save_image_choice == 'y' or save_image_choice=='': os.makedirs("./sauvegarde/"+path, exist_ok=True) moveImages(path,'./sauvegarde/'+path) os.rmdir(path) @@ -351,19 +352,19 @@ def run_arithmetic_operations_menu(path='arithmetic expressions'): clear() print("Voici le terme: "+ logic.to_string(app_functions.SUB)) logic.captureImage(app_functions.SUB,path,'SUB', False) - choix=(input("do you want to try an exemple? (y/n) : ")) - while choix not in ['y','n']: - choix = input('Invalid choice. Do you want to try an exemple? (y/n): ') - if choix=='y': + choix=(input("do you want to try an exemple? (Y/n) : ")) + while choix not in ['y','n','']: + choix = input('Invalid choice. Do you want to try an exemple? (Y/n): ') + if choix=='y' or choix=='': clear() print("you are going to try n-m") n=int(input("give n : ")) m=int(input("give m : ")) app_functions.sub(app_functions.dec_to_church(n),app_functions.dec_to_church(m)) - save_image_choice = input('Do you want to save the images? (y/n): ') - while save_image_choice not in ['y','n']: - save_image_choice = input('Invalid choice. Do you want to save the images of the reduction? (y/n): ') - if save_image_choice == 'y': + save_image_choice = input('Do you want to save the images? (Y/n): ') + while save_image_choice not in ['Y','n','']: + save_image_choice = input('Invalid choice. Do you want to save the images of the reduction? (Y/n): ') + if save_image_choice == 'y' or save_image_choice=='': os.makedirs("./sauvegarde/"+path, exist_ok=True) moveImages(path,'./sauvegarde/'+path) os.rmdir(path) @@ -375,19 +376,19 @@ def run_arithmetic_operations_menu(path='arithmetic expressions'): clear() print("Voici le terme: "+ logic.to_string(app_functions.MUL)) logic.captureImage(app_functions.MUL,path,'MUL',False) - choix=(input("do you want to try an exemple? (y/n) : ")) - while choix not in ['y','n']: - choix = input('Invalid choice. Do you want to try an exemple? (y/n): ') - if choix=='y': + choix=(input("do you want to try an exemple? (Y/n) : ")) + while choix not in ['y','n','']: + choix = input('Invalid choice. Do you want to try an exemple? (Y/n): ') + if choix=='y' or choix=='': clear() print("you are going to try n*m") n=int(input("give n : ")) m=int(input("give m : ")) app_functions.mul(app_functions.dec_to_church(n),app_functions.dec_to_church(m)) - save_image_choice = input('Do you want to save the images? (y/n): ') - while save_image_choice not in ['y','n']: - save_image_choice = input('Invalid choice. Do you want to save the images of the reduction? (y/n): ') - if save_image_choice == 'y': + save_image_choice = input('Do you want to save the images? (Y/n): ') + while save_image_choice not in ['y','n','']: + save_image_choice = input('Invalid choice. Do you want to save the images? (Y/n): ') + if save_image_choice == 'y' or save_image_choice=='': os.makedirs("./sauvegarde/"+path, exist_ok=True) moveImages(path,'./sauvegarde/'+path) os.rmdir(path) @@ -399,19 +400,19 @@ def run_arithmetic_operations_menu(path='arithmetic expressions'): clear() print("Voici le terme: "+ logic.to_string(app_functions.POW)) logic.captureImage(app_functions.POW,path,'POWER',False) - choix=(input("do you want to try an exemple? (y/n) : ")) - while choix not in ['y','n']: - choix = input('Invalid choice. Do you want to try an exemple? (y/n): ') - if choix=='y': + choix=(input("do you want to try an exemple? (Y/n) : ")) + while choix not in ['y','n','']: + choix = input('Invalid choice. Do you want to try an exemple? (Y/n): ') + if choix=='y' or choix=='': clear() print("you are going to try n puiss m") n=int(input("give n : ")) m=int(input("give m : ")) app_functions.power(app_functions.dec_to_church(n),app_functions.dec_to_church(m)) - save_image_choice = input('Do you want to save the images? (y/n): ') - while save_image_choice not in ['y','n']: - save_image_choice = input('Invalid choice. Do you want to save the images of the reduction? (y/n): ') - if save_image_choice == 'y': + save_image_choice = input('Do you want to save the images? (Y/n): ') + while save_image_choice not in ['y','n','']: + save_image_choice = input('Invalid choice. Do you want to save the images of the reduction? (Y/n): ') + if save_image_choice == 'y' or save_image_choice=='': os.makedirs("./sauvegarde/"+path, exist_ok=True) moveImages(path,'./sauvegarde/'+path) os.rmdir(path) @@ -423,18 +424,18 @@ def run_arithmetic_operations_menu(path='arithmetic expressions'): clear() print("Voici le terme: "+ logic.to_string(app_functions.SUCCS)) logic.captureImage(app_functions.SUCCS,path,'SUCCS',False) - choix=(input("do you want to try an exemple? (y/n) : ")) - while choix not in ['y','n']: - choix = input('Invalid choice. Do you want to try an exemple? (y/n): ') - if choix=='y': + choix=(input("do you want to try an exemple? (Y/n) : ")) + while choix not in ['y','n','']: + choix = input('Invalid choice. Do you want to try an exemple? (Y/n): ') + if choix=='y'or choix=='': clear() print("you are going to try n+1") n=int(input("give n : ")) app_functions.succ(app_functions.dec_to_church(n)) - save_image_choice = input('Do you want to save the images? (y/n): ') - while save_image_choice not in ['y','n']: - save_image_choice = input('Invalid choice. Do you want to save the images of the reduction? (y/n): ') - if save_image_choice == 'y': + save_image_choice = input('Do you want to save the images? (Y/n): ') + while save_image_choice not in ['y','n','']: + save_image_choice = input('Invalid choice. Do you want to save the images ? (Y/n): ') + if save_image_choice == 'y' or save_image_choice=='': os.makedirs("./sauvegarde/"+path, exist_ok=True) moveImages(path,'./sauvegarde/'+path) os.rmdir(path) @@ -446,18 +447,18 @@ def run_arithmetic_operations_menu(path='arithmetic expressions'): clear() print("Voici le terme: "+ logic.to_string(app_functions.PRED)) logic.captureImage(app_functions.PRED,path,'PRED',False) - choix=(input("do you want to try an exemple? (y/n) : ")) - while choix not in ['y','n']: - choix = input('Invalid choice. Do you want to try an exemple? (y/n): ') - if choix=='y': + choix=(input("do you want to try an exemple? (Y/n) : ")) + while choix not in ['y','n','']: + choix = input('Invalid choice. Do you want to try an exemple? (Y/n): ') + if choix=='y' or choix=='': clear() print("you are going to try n-1") n=int(input("give n : ")) app_functions.predec(app_functions.dec_to_church(n)) - save_image_choice = input('Do you want to save the images? (y/n): ') - while save_image_choice not in ['y','n']: - save_image_choice = input('Invalid choice. Do you want to save the images of the reduction? (y/n): ') - if save_image_choice == 'y': + save_image_choice = input('Do you want to save the images? (Y/n): ') + while save_image_choice not in ['y','n','']: + save_image_choice = input('Invalid choice. Do you want to save the images? (Y/n): ') + if save_image_choice == 'y' or save_image_choice=='': os.makedirs("./sauvegarde/"+path, exist_ok=True) moveImages(path,'./sauvegarde/'+path) os.rmdir(path) diff --git a/requirements.txt b/requirements.txt index 8f8424c9f77a67ac82fb1a3eb5982ed2cb2a7af6..eca15978218f9584df35f65b16a9586529c703a6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,4 @@ +Pillow pyfiglet -keyboard \ No newline at end of file +keyboard +shutil \ No newline at end of file