Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 23a64b3

Browse files
author
sjf
committed
translation
1 parent 1403263 commit 23a64b3

3 files changed

Lines changed: 31 additions & 12 deletions

File tree

eventlogic.scm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@
215215

216216
(define (negate-alphabet a)
217217
(map (lambda (x)
218-
(string->symbol (string-append "not" (symbol->string x))))
218+
(string->symbol (string-append "~" (symbol->string x))))
219219
a))
220220

221221
(define (parse-alphabet s)
@@ -247,7 +247,7 @@
247247
(dfa-remove-never-accepting-states! dfa1)
248248
(dfa-really-minimize! dfa1)
249249
(if *complete?* (dfa-complete! dfa1))
250-
(view (graph dfa1))
250+
(view (graph dfa1 s))
251251
(display "Model > ")
252252
(let* ((model (read))
253253
(result (run-dfa dfa1 model)))

graph.scm

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,34 @@
1212
(utils "utils.scm"))
1313
(export
1414
(view graph)
15-
(graph state-machine)
15+
(graph state-machine . title)
1616
(graph-to-file state-machine file)))
1717

1818
(define *image-viewer* "eog")
1919
(define *dot* "dot")
2020

21-
(define (graph state-machine)
22-
(cond ((nfa? state-machine)
23-
(graph-nfa state-machine))
24-
((dfa? state-machine)
25-
(graph-dfa state-machine))
26-
(else
27-
(error "graph" "Can only produce a graph for nfa or dfa" state-machine))))
21+
(define (graph state-machine . title)
22+
(let ((gr (cond ((nfa? state-machine)
23+
(graph-nfa state-machine))
24+
((dfa? state-machine)
25+
(graph-dfa state-machine))
26+
(else
27+
(error "graph" "Can only produce a graph for nfa or dfa" state-machine)))))
28+
(if (null? title)
29+
gr
30+
(append-dot gr "graph[label=\"~a\"]" (car title)))))
31+
32+
(define (append-dot gr fmt s)
33+
(close-dot (string-append (open-dot gr) (format fmt s))))
34+
35+
(define (close-dot gr)
36+
(string-append gr "}"))
37+
38+
(define (open-dot gr)
39+
(let ((sc (string-contains gr "}")))
40+
(if sc
41+
(string-shrink! gr sc)
42+
gr)))
2843

2944
(define (graph-to-file state-machine filename)
3045
(call-with-output-file
@@ -46,14 +61,15 @@
4661
node[shape=circle style=solid]
4762
~a
4863
}")
64+
4965
(define dot-final-states
5066
"node[shape=doublecircle style=solid]
5167
~a;")
5268

5369
(define (string-quote x)
5470
(format "\"~a\"" x))
5571

56-
(define (graph-dfa dfa)
72+
(define (graph-dfa dfa . args)
5773
(let* ((final-states (if (null? (dfa-final-states dfa))
5874
""
5975
(format dot-final-states
@@ -75,7 +91,7 @@
7591
(string-join transitions ""))))
7692

7793

78-
(define (graph-nfa nfa)
94+
(define (graph-nfa nfa . args)
7995
(let* ((final-states (if (null? (nfa-final-states nfa))
8096
""
8197
(format dot-final-states

notes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ dot -Tps -o out.ps file.dot
99
gs -dBATCH -dNOPAUSE -dTextAlphaBits=4 -dGraphicsAlphaBits=4 \
1010
-sDEVICE=png16m -sOutputFile=out.png out.ps
1111

12+
13+
NOTES: negation includes in empty string because it is in the universal consistent language.
14+

0 commit comments

Comments
 (0)