This is a recursive recognizer, that implements an algorithm to recognize strings generated by a grammar with recursive phrase structure.
Such algorithm was studied on PCS3556 - Computational Logics at Poli-USP.
Developed using Elixir programming language.
To test if a string is accepted you have to use Recognizer.recognize_chain
function. Passing the grammar production rules and the string that you wanna check if it's recoganized.
# The grammar production rules that defines the grammar that you wanna check
# A production rule is like "S" -> "aAS"
gram_rules = [
%{ "S" => ["a", "A", "S"] },
%{ "S" => ["a"] },
%{ "S" => ["S", "S"] },
%{ "A" => ["b", "a"] },
%{ "A" => ["S", "S"] }
]
# If wanna check if "aaaa" is recognized
chain_string = ["a", "a", "a", "a"]
# Checking if recoganizes string
recoganized = Recognizer.recognize_chain(gram_rules, chain_string)
## recoganized = true
All tests are available at test/recognizer_test.exs
mix test