diff options
| author | Tom Harley | 2018-05-14 18:50:40 +0100 |
|---|---|---|
| committer | Tom Harley | 2018-05-14 18:50:40 +0100 |
| commit | f09627f7c5a2cd8593745211459a9fd2468bac88 (patch) | |
| tree | 1d344fe71fd57cf0dd5092f8519a9d344abaaa00 /src/tmachinespkg/mt.nim | |
| parent | Initialise nimble package (diff) | |
| download | machines-f09627f7c5a2cd8593745211459a9fd2468bac88.tar.gz machines-f09627f7c5a2cd8593745211459a9fd2468bac88.zip | |
Add docopts
Diffstat (limited to 'src/tmachinespkg/mt.nim')
| -rw-r--r-- | src/tmachinespkg/mt.nim | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/tmachinespkg/mt.nim b/src/tmachinespkg/mt.nim new file mode 100644 index 0000000..8055921 --- /dev/null +++ b/src/tmachinespkg/mt.nim @@ -0,0 +1,41 @@ +import uuid +import sets +import os +import tables +import strutils + +import lib + +proc accept( + this: var ttable, + initialState: state, + input: string, + u: string +): state {.discardable.} = + var cs = initialState + for c in input: + if not this.hasKey((cs, c)): + this[(cs, c)] = (u, '_', Inc) + cs = this[(cs, c)].newState + return cs + +proc esarp(content: string): description = + var tt = initTable[input, transition]() + var ac = initSet[state]() + var i = 0 + const initialState = "S" + for line in content.splitLines: + if line.len <= 0: continue + let split = line.split(' ') + if split[1].parseBool(): + ac.incl tt.accept(initialState, split[0], $i) + i += 1 + return (initialState, ac, tt) + +const tmname {.strdefine.}: string = "addition" +const desc = esarp(slurp(tmname & ".tmt")) + +if paramCount() >= 1: + echo makeDTM(desc, paramStr(1)).test(true) +else: + echo desc.toFile() |
