Advertisement
Guest User

Automaton Alloy

a guest
Nov 20th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. /*
  2. * Modeling the strututure and execution of deterministic finite automata.
  3. * FEUP, MFES, 22 Nov 2016
  4. */
  5. open util/ordering[ExecutionState]
  6.  
  7. sig State {}
  8.  
  9. sig Symbol{}
  10.  
  11. sig Automaton {
  12. states: set State,
  13. alphabet: set Symbol,
  14. transitions: (states -> alphabet) -> one states,
  15. start: states,
  16. accepting: set states
  17. }{
  18. -- all states are reachable from start
  19. states = start.* {s, s': states | some s.transitions.s'}
  20. }
  21.  
  22. sig ExecutionState {
  23. automaton: Automaton,
  24. current: State,
  25. lastSymbol: lone Symbol
  26. } {
  27. current in automaton.states
  28. lastSymbol in automaton.alphabet
  29. }
  30.  
  31. pred start[a: Automaton, e': ExecutionState] {
  32. e'.automaton = a
  33. e'.current = a.start
  34. no e'.lastSymbol
  35. }
  36.  
  37. pred input[e: ExecutionState, s: Symbol, e': ExecutionState] {
  38. s in e.automaton.alphabet
  39. e'.automaton = e.automaton
  40. e'.current = e.automaton.transitions[e.current][s]
  41. e'.lastSymbol = s
  42. }
  43.  
  44. fact validTraces {
  45. some a: Automaton | start[a, first]
  46. all e: ExecutionState, e': e.next | some s: Symbol | input[e, s, e']
  47. }
  48.  
  49. one sig N1, N2, N3, N0 extends State{}
  50.  
  51. one sig A, B, C extends Symbol{}
  52.  
  53. pred Automata [a: Automaton] {
  54. a.states = N1 + N2 + N3 + N0
  55. a.alphabet = A + B + C
  56. a.transitions = ((N1->A)->N2) + ((N1->B)->N2) + ((N1->C)->N0) + ((N2->A)->N1) + ((N2->B)->N2) + ((N2->C)->N3) +
  57. ((N3->A)->N0) + ((N3->B)->N0) + ((N3->C)->N2) + ((N0->A)->N0) + ((N0->B)->N0) + ((N0->C)->N0)
  58. a.start = N1
  59. a.accepting = N3
  60. }
  61.  
  62. run findTraceAccepting {
  63. Automata[first.automaton]
  64. last.current in last.automaton.accepting
  65. } for 7 but exactly 1 Automaton
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement