► |  | Redex: Practical Semantics Engineering

1 | Amb: A Redex Tutorial
2 | Long Tutorial
3 | Extended Exercises
4 | The Redex Reference
5 | Automated Testing Benchmark
| Bibliography
| Index

▼ | 3 | Extended Exercises

3.1 | Problem: Objects
3.2 | Solution: Objects
3.3 | Problem: Types
3.4 | Solution: Types
3.5 | Problem: Missionaries and Cannibals
3.6 | Solution: Missionaries and Cannibals
3.7 | Problem: Towers of Hanoi
3.8 | Solution: Towers of Hanoi
3.9 | Problem: GC
3.10 | Solution: GC
3.11 | Problem: Finite State Machines
3.12 | Solution: Finite State Machines
3.13 | Problem: Threads
3.14 | Solution: Threads
3.15 | Problem: Contracts
3.16 | Solution: Contracts
3.17 | Problem: Binary Addition
3.18 | Solution: Binary Addition

top ← prev up next →

#### 3.12`` Solution: Finite State Machines

#lang racket
;; modeling the transitions in non-deterministic finite-state machines
(require redex)
;; -----------------------------------------------------------------------------
;; syntax
(define-language L
[FSM (rule ...)]
[rule [state -> input -> state]]
[state variable-not-otherwise-mentioned]
[input variable-not-otherwise-mentioned])
;; -----------------------------------------------------------------------------
;; the reduction system
(module+ test
(define fsm1 (term ([a -> x -> b]
[a -> y -> c]
[b -> x -> a])))
(test-->> -->fsm
(term [,fsm1
a
(x x y)])
(term [,fsm1
c
()]))
(test-->> -->fsm
(term [,fsm1
a
(x x y x)])
(term [,fsm1
c
(x)]))
(define fsm2 (term ([a -> x -> b]
[a -> y -> c]
[a -> y -> d]
[b -> x -> a]
[d -> x -> b])))
(test-->>∃ -->fsm
(term [,fsm2
a
(x x y x)])
(term [,fsm2
b
()])))
(define -->fsm
(reduction-relation
L
#:domain [FSM state (input ...)]
(--> [FSM state_1 (input_0 input_1 ...)]
[FSM state_2 (input_1 ...)]
(where (_ ... [state_1 -> input_0 -> state_2] _ ...)
FSM))))
(module+ test
(test-results))

top ← prev up next →