This program reads a nondeterministic pushdown automaton especified in a JSON file, and receives a word as input, then checks if the word is recognized by the automaton.
{ "pda": [ [states], [input alphabet], [stack alphabet], [transitions], [initial states], [final states] ]}
where each element in [transitions] is:
[origin state, input symbol read, symbol to remove from stack, target state, symbol to insert in stack]
Example of an automaton that recognizes palindromes
{"pda":[
["A", "B"],
["0", "1"],
["X", "Y"],
[
["A", "0", "#", "A", "X"],
["A", "1", "#", "A", "Y"],
["A", "#", "#", "B", "#"],
["A", "0", "#", "B", "#"],
["A", "1", "#", "B", "#"],
["B", "0", "X", "B", "#"],
["B", "1", "Y", "B", "#"]
],
["A"],
["B"]
]}
$ python pda.py palindrome.js 0110
Yes
$ python pda.py palindrome.js 1110
No
This program was written for an assignment of my bachelor's degree in Computer Engineering at CEFET-MG.
@thiagorss: best duo ๐ป @rimsa: professor and inspiration ๐จโ๐ซ