Skip to content
Snippets Groups Projects
Commit e40dd222 authored by Tamazouzt AIT ELDJOUDI's avatar Tamazouzt AIT ELDJOUDI
Browse files

newVar

parent 643f51b9
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -57,12 +57,14 @@ def findClosingParanthesesIndex(terme, openParentheseIndex):
return closeParantheseIndex
def checkType(terme):
if terme[0] == '(' and balancedParantheses(terme):
return APP
elif "#" == terme[0]:
if terme[0]== '(':
return checkType(getTermFromParantheses(terme,0))
if "#" == terme[0]:
return ABS
else:
elif not (' ' in terme ) and not ('(' in terme):
return VAR
else:
return APP
def isVariable(terme):
return checkType(terme) == VAR
......@@ -92,7 +94,10 @@ def parseOutputFromAbs(terme):
def buildVar(terme):
assert (checkType(terme) == VAR)
if terme[0]!='(':
return new_var(terme)
else :
return buildVar(getTermFromParantheses(terme,0))
def buildAbs(terme):
assert (checkType(terme) == ABS)
......@@ -102,7 +107,7 @@ def buildAbs(terme):
def buildApp(terme):
assert (checkType(terme) == APP)
liste_de_termes = getTermsFromParantheses(terme)
liste_de_termes = terme.split(' ')
n = len(liste_de_termes)
if n == 0:
raise Exception('Empty List of Terms')
......@@ -113,58 +118,49 @@ def buildApp(terme):
return t
A = "#x.(x)(y)"
def buildTerm(terme):
TermType = checkType(terme)
if isVariable(terme): return buildVar(terme)
elif isAbstraction(terme): return buildAbs(terme)
elif isApplication(terme): return buildApp(terme)
# renvoie les espaces laissés au debut et a la fin du terme ( ils servent a rien)
def remove_first_and_last_spaces(terme):
new_terme = list(terme)
i = 0
j = len(terme) -1
while i < j and new_terme[i] == " ":
new_terme[i] = ""
i +=1
while j > 0 and new_terme[j] == " ":
new_terme[j] = ""
j -=1
return "".join([str(letter) for letter in new_terme])
# enleve les parentheses quand y a un seul coupme
def remove_inutile_parentheses(terme):
if parantheses_couples(terme) == 1 :
return terme[1:-1] # tout sauf le premier et dernier terme
else:
return terme
# renvoie ce qu'il y a entre la parenthese ouverte a l indice i et sa parethese fermante
def getTermFromParantheses(terme,i):
return terme[i+1:findClosingParanthesesIndex(terme,i)]
# renvoie renvoie tous les termes entre parentheses dans terme
def getTermsFromParantheses(terme):
terms = []
for i in (open_parantheses_counter(terme)[1]):
terms.append(getTermFromParantheses(terme,i))
return terms
print(getTermsFromParantheses("(AAAAAA)(BBBBBBBBB)(CCCCCCCCC)"))
print(buildTerm(A))
print(remove_first_and_last_spaces('ll'))
print(isAbstraction(A))
print(isApplication("(x)(y)(z)"))
print(checkType("(#x.x)"))
print(buildTerm('(#x.x)(#y.y)'))
print(remove_inutile_parentheses('(#x.x)(#y.y)'))
#fonction qui enleve les espaces successifs et laisse un seul espace
def remove_multiple_spaces(terme):
new_term=''
i=0
while i<len(terme):
new_term+=terme[i]
if terme[i]==' ':
while terme[i]==' ':
i+=1
else:
i+=1
return new_term
# print(getTermsFromParantheses("(AAAAAA)(BBBBBBBBB)(CCCCCCCCC)"))
# print(buildTerm(A))
# print(remove_first_and_last_spaces('ll'))
# print(isAbstraction(A))
# print(isApplication("(x)(y)(z)"))
# print(checkType("(#x.x)"))
# print(buildTerm('(#x.x)(#y.y)'))
# print(remove_inutile_parentheses('(#x.x)(#y.y)'))
# print(open_parantheses_counter('((((((((((('))
# print(close_parantheses_counter('((((((((((()'))
# print(buildAbs("#x.ABC"))
# print(checkType("(#x.xx)(fds)"))
# print(findClosingParanthesesIndex('()',0))
#print(remove_multiple_spaces("x y z (#x.z g)"))
print(buildTerm("x "))
print(checkType("(((#x.x)))"))
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment