2024-03-28 12:26:18 +01:00
2024-04-11 18:40:11 +02:00
2024-04-11 18:40:11 +02:00
2024-04-11 22:00:08 +02:00

IN620

pushdown automaton

Input word = i0, I, K

  • i0 total length of input word
  • I = i1, J
    • i1, size of automaton input word
    • J automaton input, list of integers
  • K, list of transitions

transition (q, a, A, w, q')

  • q : state before
  • q' : state after
    • 0 : start state
    • 1 : accepting state
  • a : symbol in input
    • 2 : ε
  • A : symbol on stack (pop operation)
    • 2 : ε (no pop)
    • 3 : stack start symbol
  • w : word to push on stack
    • w = u, V
      u : length of V, 0 if nothing to push
      V : list of integers to push (Vn, Vn-1... V0)
      Leftmost element of the list will be at the top of the stack after the transition (Vn here).

output:

  • 0 : accept
  • 1 : reject

examples :

transition (q, a, A, w, q') = (0, 3, 4, 54, 1)

(0, 3, 4, 2, 5, 4, 1)

transition (q, a, A, w, q') = (0, ε, 1, ε, 1)

(0, 2, 1, 2, 0, 1)

0n1n

0n1n automaton:

(0, 0, 3, 2, 1, 3, 0)	// stack empty, read 0, push 1, stay in state 0
(0, 0, 1, 2, 1, 1, 0)	// stack with 1 on top, read 0, push 1, stay in state 0
(0, 1, 1, 0, 2)		// stack with 1 on top, read 1, pop 1, go to state 2
(2, 1, 1, 0, 2)		// stack with 1 on top, read 1, pop 1, stay in state 2
(2, 2, 3, 1, 3, 1)	// stack empty in state 2, go to accepting state

0n1n inputs

0n1n
input 000111 (output should be 0)

(37, 6, 0, 0, 0, 1, 1, 1, 0, 0, 3, 2, 1, 3, 0, 0, 0, 1, 2, 1, 1, 0, 0, 1, 1, 0, 2, 2, 1, 1, 0, 2, 2, 2, 3, 1, 3, 1)

0n1m n<m
input 001111 (output should be 1)

(37, 6, 0, 0, 1, 1, 1, 1, 0, 0, 3, 2, 1, 3, 0, 0, 0, 1, 2, 1, 1, 0, 0, 1, 1, 0, 2, 2, 1, 1, 0, 2, 2, 2, 3, 1, 3, 1)

0n1m n>m
input 000011 (output should be 1)

(37, 6, 0, 0, 0, 0, 1, 1, 0, 0, 3, 2, 1, 3, 0, 0, 0, 1, 2, 1, 1, 0, 0, 1, 1, 0, 2, 2, 1, 1, 0, 2, 2, 2, 3, 1, 3, 1)

!=0n1m
input 001011 (output should be 1)

(37, 6, 0, 0, 1, 0, 1, 1, 0, 0, 3, 2, 1, 3, 0, 0, 0, 1, 2, 1, 1, 0, 0, 1, 1, 0, 2, 2, 1, 1, 0, 2, 2, 2, 3, 1, 3, 1)
Description
Random Access Machine interpreter in Python
Readme 84 KiB
Languages
Python 48.6%
Assembly 25.7%
Yacc 14.6%
Makefile 8%
Lex 3.1%