Which Algorithm Approach Should I Take to Generate Lambda Expressions in Java?
https://softwareengineering.stackexchange.com/questions/330823
-
27-12-2020 - |
Pergunta
Good day, I'm trying to find a way to program a lambda expression generator in java with this context-free grammar, and I would want to ask ; what would be the best way to tackle this problem and be able to manipulate them with basic lambda calculus functions such as beta reduction, alpha conversion, etc.?
I tried doing this with Strings, but was advised to discontinue because using strings will limit me to what I can do.
Here's the Context Free Grammar I got over the internet:
<expr> ::= <var>
| <func> <arg> # This is an application.
| lambda <var> . <expr> # This is an abstraction.
<func> ::= <var>
| (lambda <var> . <expr>)
| <func> <arg>
<arg> ::= <var>
| (lambda <var> . <expr>)
| (<func> <arg>)
<var> ::= a| b| .... | Z
Solução
The simplest approach would be to use a parser generate (perhaps antlr) to make a parser that produces a parse tree. You can then perform your reductions and conversions on the parse tree, rather than on a string, which should make them much simpler.