From 2ac50103672df10af130d3b1003980f087bc17dd Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Wed, 4 Jul 2018 21:08:05 +0100 Subject: 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. --- src/tmachines.nim | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'src/tmachines.nim') 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[""] - if file.ends_with(".tm") or file.ends_with(".dtm"): - let tmd = tm.parse(readFile($args[""])) - echo tm.test(tm.makeDTM(tmd, $args[""]), 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[""])) + echo tm.test(tm.makeDTM(tmd, $args[""]), not args["--quiet"]) + of NTM: + let tmd = ntm.parse(readFile($args[""])) + echo ntm.test(ntm.makeNTM(tmd, $args[""]), not args["--quiet"]) -- cgit v1.2.1