diff options
| author | Tom Harley | 2018-07-04 21:08:05 +0100 |
|---|---|---|
| committer | Tom Harley | 2018-07-04 21:08:05 +0100 |
| commit | 2ac50103672df10af130d3b1003980f087bc17dd (patch) | |
| tree | 5edfb47b87829964f7affdba7b41e94312e44cc0 /src/tmachines.nim | |
| parent | Remove extension auto-adding (diff) | |
| download | machines-2ac50103672df10af130d3b1003980f087bc17dd.tar.gz machines-2ac50103672df10af130d3b1003980f087bc17dd.zip | |
Add nondeterminism.
Add the ability to specify non-deterministic TMs. Listing multiple outcomes for a particular state-input combo will create a non-deterministic split instead of using only the latest one in the list.
Deterministic TMs should use a .dtm suffix, and non-deterministic TMs should use .ntm. TMs with the extension .tm will be assumed to be non-deterministic for compatability.
Diffstat (limited to 'src/tmachines.nim')
| -rw-r--r-- | src/tmachines.nim | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/src/tmachines.nim b/src/tmachines.nim index 2d1d190..aae5401 100644 --- a/src/tmachines.nim +++ b/src/tmachines.nim @@ -3,6 +3,27 @@ import os, strutils import docopt from tmachinespkg/tm import nil +from tmachinespkg/ntm import nil + +type Machine = enum + DTM, NTM + +proc tm_type_from_cli(value: string): Machine = + case value + of "dtm": + return DTM + of "ntm": + return NTM + else: + return NTM + +proc tm_type_from_filename(filename: string): Machine = + if filename.ends_with(".dtm"): + return DTM + elif filename.ends_with(".ntm"): + return NTM + elif filename.ends_with(".tm"): + return NTM const tmname {.strdefine.}: string = "" @@ -18,6 +39,16 @@ else: let args = docopt(doc) let file = $args["<machine>"] - if file.ends_with(".tm") or file.ends_with(".dtm"): - let tmd = tm.parse(readFile($args["<machine>"])) - echo tm.test(tm.makeDTM(tmd, $args["<input>"]), not args["--quiet"]) + var m_type: Machine + if $args["--type"] != "nil": + m_type = tm_type_from_cli($args["--type"]) + else: + m_type = tm_type_from_filename(file) + + case m_type: + of DTM: + let tmd = tm.parse(readFile($args["<machine>"])) + echo tm.test(tm.makeDTM(tmd, $args["<input>"]), not args["--quiet"]) + of NTM: + let tmd = ntm.parse(readFile($args["<machine>"])) + echo ntm.test(ntm.makeNTM(tmd, $args["<input>"]), not args["--quiet"]) |
