jhkersul / recursive-recognizer

Functional recursive string recognizer. Made using Elixir programming language.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Recursive Recognizer

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.

Testing if a string is accepted

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

Running tests

All tests are available at test/recognizer_test.exs

mix test

About

Functional recursive string recognizer. Made using Elixir programming language.


Languages

Language:Elixir 100.0%