Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
lambda calculus
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
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
stijn en pjotr
lambda calculus
Commits
a3de540f
Commit
a3de540f
authored
2 years ago
by
9691448
Browse files
Options
Downloads
Patches
Plain Diff
Parser voor lambda-calculus
parent
4c65fc09
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lambdaparser.py
+41
-1
41 additions, 1 deletion
lambdaparser.py
with
41 additions
and
1 deletion
lambdaparser.py
+
41
−
1
View file @
a3de540f
from
ply.lex
import
lex
from
ply.yacc
import
yacc
\ No newline at end of file
from
ply.yacc
import
yacc
from
main
import
Variable
,
Abstraction
,
Application
#BNF Grammar voor lambda calculus
#TERM ::= VARIABLE
# |LAMBDA VARIABLE PERIOD TERM
# |LPAREN TERM TERM RPAREN
#Tokens importen van de lexer
from
lambdalexer
import
tokens
def
p_paren
(
p
):
'''
TERM : LPAREN TERM RPAREN
'''
p
[
0
]
=
p
[
2
]
def
p_variable
(
p
):
'''
TERM : VARIABLE
'''
p
[
0
]
=
Variable
(
p
[
1
])
def
p_abstraction
(
p
):
'''
TERM : LAMBDA VARIABLE PERIOD TERM
'''
p
[
0
]
=
Abstraction
(
Variable
(
p
[
2
]),
p
[
4
])
def
p_application
(
p
):
'''
TERM : TERM TERM
'''
p
[
0
]
=
Application
(
p
[
1
],
p
[
2
])
def
p_error
(
p
):
print
(
"
Syntax error in input!
"
)
#Build the parser
parser
=
yacc
.
yacc
()
while
True
:
try
:
s
=
input
(
'
calc >
'
)
except
EOFError
:
break
if
not
s
:
continue
result
=
parser
.
parse
(
s
)
print
(
result
)
\ 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