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
4bb2a1fe
Commit
4bb2a1fe
authored
3 years ago
by
Antonio MATTAR
Browse files
Options
Downloads
Patches
Plain Diff
- Fixed some specific cases where there was 2 points in the lambda term
parent
92ee95c8
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
parser.py
+34
-26
34 additions, 26 deletions
parser.py
with
34 additions
and
26 deletions
parser.py
+
34
−
26
View file @
4bb2a1fe
...
@@ -60,6 +60,12 @@ def findClosingParanthesesIndex(terme, openParentheseIndex):
...
@@ -60,6 +60,12 @@ def findClosingParanthesesIndex(terme, openParentheseIndex):
def
getTermFromParantheses
(
terme
,
i
):
def
getTermFromParantheses
(
terme
,
i
):
return
terme
[
i
+
1
:
findClosingParanthesesIndex
(
terme
,
i
)]
return
terme
[
i
+
1
:
findClosingParanthesesIndex
(
terme
,
i
)]
def
getTermsFromParantheses
(
terme
):
terms
=
[]
for
i
in
(
open_parantheses_counter
(
terme
)[
1
]):
terms
.
append
(
getTermFromParantheses
(
terme
,
i
))
return
terms
#fonction qui enleve les espaces successifs et laisse un seul espace
#fonction qui enleve les espaces successifs et laisse un seul espace
def
remove_multiple_spaces
(
terme
):
def
remove_multiple_spaces
(
terme
):
new_term
=
''
new_term
=
''
...
@@ -74,10 +80,14 @@ def remove_multiple_spaces(terme):
...
@@ -74,10 +80,14 @@ def remove_multiple_spaces(terme):
return
new_term
return
new_term
def
checkType
(
terme
):
def
checkType
(
terme
):
if
terme
[
0
]
==
'
(
'
:
if
"
#
"
==
terme
[
0
]:
return
checkType
(
getTermFromParantheses
(
terme
,
0
))
elif
"
#
"
==
terme
[
0
]:
return
ABS
return
ABS
elif
terme
[
0
]
==
'
(
'
:
l
=
getTermsFromParantheses
(
terme
)
if
len
(
l
)
==
1
:
return
checkType
(
getTermFromParantheses
(
terme
,
0
))
else
:
return
APP
elif
not
(
any
(
charac
in
(
terme
)
for
charac
in
[
'
(
'
,
'
)
'
,
'
'
,
'
#
'
,
'
.
'
])):
elif
not
(
any
(
charac
in
(
terme
)
for
charac
in
[
'
(
'
,
'
)
'
,
'
'
,
'
#
'
,
'
.
'
])):
return
VAR
return
VAR
else
:
else
:
...
@@ -104,13 +114,13 @@ def parseInputFromAbs(terme):
...
@@ -104,13 +114,13 @@ def parseInputFromAbs(terme):
return
input
return
input
# on prend l output en chaine de caractères
# on prend l output en chaine de caractères
def
parseOutputFromAbs
(
terme
):
def
parseOutputFromAbs
(
terme
):
output
=
''
index_of_point
=
terme
.
find
(
'
.
'
)
if
checkType
(
terme
)
==
ABS
:
if
checkType
(
terme
)
==
ABS
:
output
+=
(
terme
.
split
(
"
.
"
))[
1
]
return
terme
[
index_of_point
+
1
:]
return
output
def
buildVar
(
terme
):
def
buildVar
(
terme
):
assert
(
checkType
(
terme
)
==
VAR
)
assert
(
checkType
(
terme
)
==
VAR
)
# print(terme)
if
terme
[
0
]
!=
'
(
'
:
if
terme
[
0
]
!=
'
(
'
:
return
new_var
(
terme
)
return
new_var
(
terme
)
else
:
else
:
...
@@ -120,6 +130,7 @@ def buildAbs(terme):
...
@@ -120,6 +130,7 @@ def buildAbs(terme):
assert
(
checkType
(
terme
)
==
ABS
)
assert
(
checkType
(
terme
)
==
ABS
)
input
=
parseInputFromAbs
(
terme
)
input
=
parseInputFromAbs
(
terme
)
output
=
parseOutputFromAbs
(
terme
)
output
=
parseOutputFromAbs
(
terme
)
# print(terme,"INPUT:", input,'OUTPUT:', output)
if
terme
[
0
]
!=
'
(
'
:
if
terme
[
0
]
!=
'
(
'
:
return
new_abs
((
buildTerm
(
input
)),
buildTerm
(
output
))
return
new_abs
((
buildTerm
(
input
)),
buildTerm
(
output
))
else
:
else
:
...
@@ -129,10 +140,11 @@ def buildApp(terme):
...
@@ -129,10 +140,11 @@ def buildApp(terme):
assert
(
checkType
(
terme
)
==
APP
)
assert
(
checkType
(
terme
)
==
APP
)
if
terme
[
0
]
!=
'
(
'
:
if
terme
[
0
]
!=
'
(
'
:
liste_de_termes
=
terme
.
split
(
'
'
)
liste_de_termes
=
terme
.
split
(
'
'
)
print
(
liste_de_termes
)
# print(terme)
# print(liste_de_termes)
n
=
len
(
liste_de_termes
)
n
=
len
(
liste_de_termes
)
if
n
==
0
:
if
n
==
0
:
r
aise
Exception
(
'
Empty List of Terms
'
)
r
eturn
None
else
:
else
:
t
=
buildTerm
(
liste_de_termes
[
0
])
t
=
buildTerm
(
liste_de_termes
[
0
])
for
k
in
range
(
1
,
n
):
for
k
in
range
(
1
,
n
):
...
@@ -141,27 +153,23 @@ def buildApp(terme):
...
@@ -141,27 +153,23 @@ def buildApp(terme):
t
=
new_app
(
t
,
buildTerm
(
liste_de_termes
[
k
]))
t
=
new_app
(
t
,
buildTerm
(
liste_de_termes
[
k
]))
return
t
return
t
else
:
else
:
return
buildTerm
(
getTermFromParantheses
(
terme
,
0
))
liste_de_termes
=
getTermsFromParantheses
(
terme
)
t
=
buildTerm
(
liste_de_termes
[
0
])
for
k
in
range
(
1
,
len
(
liste_de_termes
)):
if
liste_de_termes
[
k
]
==
''
:
return
t
t
=
new_app
(
t
,
buildTerm
(
liste_de_termes
[
k
]))
return
t
def
buildTerm
(
terme
):
def
buildTerm
(
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
)
# print(getTermsFromParantheses("(AAAAAA)(BBBBBBBBB)(CCCCCCCCC)"))
def
parse
(
terme
):
# print(buildTerm(A))
return
(
buildTerm
(
remove_multiple_spaces
(
terme
)))
# print(remove_first_and_last_spaces('ll'))
# print(isAbstraction(A))
# print(checkType('(#x.x) (#y.y)'))
# print(isApplication("(x)(y)(z)"))
# print(parse('(#x.x) (#y.y) (#z.z)'))
# print(checkType("(#x.x)"))
# print(buildTerm('(#x.x)(#y.y)'))
print
(
parse
(
input
(
'
ENTRER UN TERME:
'
)))
# 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
(
balancedParantheses
(
'
x
'
))
print
(
buildTerm
(
"
(((((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