Created
January 29, 2017 10:25
-
-
Save TuxCoding/a1973df5c49bf7965f5976624ad73485 to your computer and use it in GitHub Desktop.
A push-down automaton written in Prolog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uprg(P):- uprg(P, [#]). % Creates a new push-down automaton | |
%Input | head of the stack :- Stackoutput | |
uprg([p|Tail], Stack):- uprg(Tail, [p|Stack]). | |
uprg([p|Tail], [#|Stack]):- uprg(Tail, [p, #|Stack]). | |
uprg([p|Tail], [a|Stack]):- uprg(Tail, [p, a|Stack]). | |
uprg([a|Tail], [p|Stack]):- uprg(Tail, [a|Stack]). | |
uprg([a|Tail], [a|Stack]):- uprg(Tail, [a|Stack]). | |
uprg([b|Tail], [a|Stack]):- uprg(Tail, [b|Stack]). | |
uprg([e|Tail], [b|Stack]):- uprg(Tail, Stack). | |
uprg([], [#]). %No more input and our last stack element is the default stack character -> valid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment