Good day! I'm trying to create a program that accepts a Lambda expression from the user and what this program does is to check if it is a Valid Lambda expression.
example - user inputs (λa.abc)a -> then validates
my problem is that my knowledge of Regex function is very limited, I've been using preg_match to solve this but still not much of a progress. any help will be much appreciated.. Thanks :)
Well these are the rules of a valid λ-expression
- a single variable = (single letter)
- function application = (λ-expression)(λ-expression)
- function abstraction = λ(variable).(λ-expression)
This is the code I did with preg_match
if(preg_match("/\((L([a-z])*.(([a-z])*)*)\)/", $getexpression, $match)):
print "Valid!";
does not really work that well