Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Alligators-python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Benjamin Monmege
Alligators-python
Commits
e40dd222
Commit
e40dd222
authored
3 years ago
by
Tamazouzt AIT ELDJOUDI
Browse files
Options
Downloads
Patches
Plain Diff
newVar
parent
643f51b9
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
__pycache__/main.cpython-39.pyc
+0
-0
0 additions, 0 deletions
__pycache__/main.cpython-39.pyc
parser.py
+43
-47
43 additions, 47 deletions
parser.py
with
43 additions
and
47 deletions
__pycache__/main.cpython-39.pyc
+
0
−
0
View file @
e40dd222
No preview for this file type
This diff is collapsed.
Click to expand it.
parser.py
+
43
−
47
View file @
e40dd222
...
@@ -57,12 +57,14 @@ def findClosingParanthesesIndex(terme, openParentheseIndex):
...
@@ -57,12 +57,14 @@ def findClosingParanthesesIndex(terme, openParentheseIndex):
return
closeParantheseIndex
return
closeParantheseIndex
def
checkType
(
terme
):
def
checkType
(
terme
):
if
terme
[
0
]
==
'
(
'
and
balancedParantheses
(
terme
)
:
if
terme
[
0
]
==
'
(
'
:
return
APP
return
checkType
(
getTermFromParantheses
(
terme
,
0
))
el
if
"
#
"
==
terme
[
0
]:
if
"
#
"
==
terme
[
0
]:
return
ABS
return
ABS
el
se
:
el
if
not
(
'
'
in
terme
)
and
not
(
'
(
'
in
terme
)
:
return
VAR
return
VAR
else
:
return
APP
def
isVariable
(
terme
):
def
isVariable
(
terme
):
return
checkType
(
terme
)
==
VAR
return
checkType
(
terme
)
==
VAR
...
@@ -92,7 +94,10 @@ def parseOutputFromAbs(terme):
...
@@ -92,7 +94,10 @@ def parseOutputFromAbs(terme):
def
buildVar
(
terme
):
def
buildVar
(
terme
):
assert
(
checkType
(
terme
)
==
VAR
)
assert
(
checkType
(
terme
)
==
VAR
)
if
terme
[
0
]
!=
'
(
'
:
return
new_var
(
terme
)
return
new_var
(
terme
)
else
:
return
buildVar
(
getTermFromParantheses
(
terme
,
0
))
def
buildAbs
(
terme
):
def
buildAbs
(
terme
):
assert
(
checkType
(
terme
)
==
ABS
)
assert
(
checkType
(
terme
)
==
ABS
)
...
@@ -102,7 +107,7 @@ def buildAbs(terme):
...
@@ -102,7 +107,7 @@ def buildAbs(terme):
def
buildApp
(
terme
):
def
buildApp
(
terme
):
assert
(
checkType
(
terme
)
==
APP
)
assert
(
checkType
(
terme
)
==
APP
)
liste_de_termes
=
getTermsFromParantheses
(
terme
)
liste_de_termes
=
terme
.
split
(
'
'
)
n
=
len
(
liste_de_termes
)
n
=
len
(
liste_de_termes
)
if
n
==
0
:
if
n
==
0
:
raise
Exception
(
'
Empty List of Terms
'
)
raise
Exception
(
'
Empty List of Terms
'
)
...
@@ -113,58 +118,49 @@ def buildApp(terme):
...
@@ -113,58 +118,49 @@ def buildApp(terme):
return
t
return
t
A
=
"
#x.(x)(y)
"
def
buildTerm
(
terme
):
def
buildTerm
(
terme
):
TermType
=
checkType
(
terme
)
TermType
=
checkType
(
terme
)
if
isVariable
(
terme
):
return
buildVar
(
terme
)
if
isVariable
(
terme
):
return
buildVar
(
terme
)
elif
isAbstraction
(
terme
):
return
buildAbs
(
terme
)
elif
isAbstraction
(
terme
):
return
buildAbs
(
terme
)
elif
isApplication
(
terme
):
return
buildApp
(
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
# renvoie ce qu'il y a entre la parenthese ouverte a l indice i et sa parethese fermante
def
getTermFromParantheses
(
terme
,
i
):
def
getTermFromParantheses
(
terme
,
i
):
return
terme
[
i
+
1
:
findClosingParanthesesIndex
(
terme
,
i
)]
return
terme
[
i
+
1
:
findClosingParanthesesIndex
(
terme
,
i
)]
# renvoie renvoie tous les termes entre parentheses dans terme
#fonction qui enleve les espaces successifs et laisse un seul espace
def
getTermsFromParantheses
(
terme
):
def
remove_multiple_spaces
(
terme
):
terms
=
[]
new_term
=
''
for
i
in
(
open_parantheses_counter
(
terme
)[
1
]):
i
=
0
terms
.
append
(
getTermFromParantheses
(
terme
,
i
))
while
i
<
len
(
terme
):
return
terms
new_term
+=
terme
[
i
]
if
terme
[
i
]
==
'
'
:
while
terme
[
i
]
==
'
'
:
print
(
getTermsFromParantheses
(
"
(AAAAAA)(BBBBBBBBB)(CCCCCCCCC)
"
))
i
+=
1
print
(
buildTerm
(
A
))
else
:
print
(
remove_first_and_last_spaces
(
'
ll
'
))
i
+=
1
print
(
isAbstraction
(
A
))
print
(
isApplication
(
"
(x)(y)(z)
"
))
return
new_term
print
(
checkType
(
"
(#x.x)
"
))
print
(
buildTerm
(
'
(#x.x)(#y.y)
'
))
print
(
remove_inutile_parentheses
(
'
(#x.x)(#y.y)
'
))
# 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(open_parantheses_counter('((((((((((('))
# print(close_parantheses_counter('((((((((((()'))
# print(close_parantheses_counter('((((((((((()'))
# print(buildAbs("#x.ABC"))
# print(buildAbs("#x.ABC"))
# print(checkType("(#x.xx)(fds)"))
# print(checkType("(#x.xx)(fds)"))
# print(findClosingParanthesesIndex('()',0))
# 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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment